mirror of
https://github.com/kalarina-bit/Sparkledns.git
synced 2026-11-22 07:36:09 +00:00
Cut allocations on the path of every DNS query
This commit is contained in:
@@ -24,6 +24,15 @@ class BlocklistMatchTest {
|
||||
assertFalse(isBlockedIn("ads.example.com", LongArray(0), LongArray(0)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun skipsTrailingDots() {
|
||||
val lists = set("example.com")
|
||||
|
||||
assertTrue(isBlockedIn("www.example.com..", lists, LongArray(0)))
|
||||
assertFalse(isBlockedIn("example.org.", lists, LongArray(0)))
|
||||
assertFalse(isBlockedIn("...", lists, LongArray(0)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun mergesSortedListsWithoutDuplicates() {
|
||||
val a = longArrayOf(-5, 1, 4, 9)
|
||||
|
||||
@@ -49,5 +49,6 @@ class BlocklistParserTest {
|
||||
val name = "a.b.example.com"
|
||||
assertEquals(DomainHash.of("example.com"), DomainHash.of(name, name.indexOf("example")))
|
||||
assertEquals(DomainHash.of(name), DomainHash.of(name, 0))
|
||||
assertEquals(DomainHash.of("b.example"), DomainHash.of(name, 2, name.indexOf(".com")))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package cc.skysparkle.sparkledns
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
class CompaniesTest {
|
||||
|
||||
@Test
|
||||
fun matchesDomainsAndTheirSubdomains() {
|
||||
assertEquals(Company.GOOGLE, Companies.of("youtube.com"))
|
||||
assertEquals(Company.GOOGLE, Companies.of("r3---sn-abc.googlevideo.com"))
|
||||
assertEquals(Company.META, Companies.of("scontent.cdninstagram.com"))
|
||||
assertEquals(Company.X, Companies.of("t.co"))
|
||||
assertEquals(Company.MICROSOFT, Companies.of("api.github.com"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun ignoresCaseAndTrailingDots() {
|
||||
assertEquals(Company.APPLE, Companies.of("WWW.Apple.COM"))
|
||||
assertEquals(Company.AMAZON, Companies.of("s3.amazonaws.com."))
|
||||
assertEquals(Company.AMAZON, Companies.of("s3.amazonaws.com.."))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun knowsGoogleCountrySites() {
|
||||
assertEquals(Company.GOOGLE, Companies.of("google.de"))
|
||||
assertEquals(Company.GOOGLE, Companies.of("www.google.co.uk"))
|
||||
assertEquals(Company.GOOGLE, Companies.of("google.com.br"))
|
||||
assertNull(Companies.of("google.example.org"))
|
||||
assertNull(Companies.of("google."))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun leavesOtherDomainsAlone() {
|
||||
assertNull(Companies.of("example.com"))
|
||||
assertNull(Companies.of("notyoutube.com"))
|
||||
assertNull(Companies.of("youtube.com.example"))
|
||||
assertNull(Companies.of("com"))
|
||||
assertNull(Companies.of(""))
|
||||
assertNull(Companies.of("."))
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@ class PacketTest {
|
||||
val parsed = requireNotNull(Packet.parseDnsQuery(packet, packet.size))
|
||||
|
||||
assertArrayEquals(query, parsed.payload)
|
||||
assertArrayEquals(client, parsed.srcIp)
|
||||
assertArrayEquals(server, parsed.dstIp)
|
||||
assertEquals(i32(client, 0), parsed.srcIp)
|
||||
assertEquals(i32(server, 0), parsed.dstIp)
|
||||
assertEquals(40000, parsed.srcPort)
|
||||
assertEquals(53, parsed.dstPort)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user