mirror of
https://github.com/kalarina-bit/Sparkledns.git
synced 2026-11-22 15:46:09 +00:00
Make bootstrap addresses work with HTTP/3 and bound response and list sizes
- HttpEngine resolves the server with system DNS and ignores bootstrap addresses. When it cannot resolve the name and the server has bootstrap addresses, the session switches to OkHttp, which connects to them. - AdBlock and URL rules with a path (||example.com/ads/, |http://example.com/x|) are skipped instead of blocking the whole domain. - A DoH response without Content-Length is read only up to the DNS size limit; blocklist downloads are limited to 256 MB, and lines over 4 KB are skipped without being read into memory.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package cc.skysparkle.sparkledns
|
||||
|
||||
import okio.Buffer
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
@@ -51,4 +52,22 @@ class BlocklistParserTest {
|
||||
assertEquals(DomainHash.of(name), DomainHash.of(name, 0))
|
||||
assertEquals(DomainHash.of("b.example"), DomainHash.of(name, 2, name.indexOf(".com")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rulesWithAPathAreSkippedNotTurnedIntoTheWholeDomain() {
|
||||
assertNull(BlocklistParser.parseLine("||example.com/ads/"))
|
||||
assertNull(BlocklistParser.parseLine("|http://example.com/x|"))
|
||||
assertNull(BlocklistParser.parseLine("https://example.com/banner.js"))
|
||||
assertEquals("example.com", BlocklistParser.parseLine("||example.com/^"))
|
||||
assertEquals("example.com", BlocklistParser.parseLine("https://example.com/"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun overlongLinesAreSkippedAndTheRestIsRead() {
|
||||
val long = "x".repeat(BlocklistParser.MAX_LINE_BYTES.toInt() * 3)
|
||||
val source = Buffer().writeUtf8("a.example\r\n$long\nb.example\nc.example")
|
||||
val lines = mutableListOf<String>()
|
||||
BlocklistParser.readLimitedLines(source) { lines += it.trim() }
|
||||
assertEquals(listOf("a.example", "b.example", "c.example"), lines)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user