Commit 7183a162 authored by Mygod's avatar Mygod

Add more AclMatcherTest

parent 668740fc
......@@ -41,9 +41,9 @@ class AclMatcherTest {
fun emptyFile() {
runBlocking {
AclMatcher().apply {
init("".reader())
Assert.assertFalse(shouldBypassIpv4(ByteArray(4)))
Assert.assertFalse(shouldBypassIpv6(ByteArray(16)))
init(AclTest.BYPASS_BASE.reader())
Assert.assertTrue(shouldBypassIpv4(ByteArray(4)))
Assert.assertTrue(shouldBypassIpv6(ByteArray(16)))
Assert.assertNull(shouldBypass("www.google.com"))
}
}
......@@ -54,14 +54,30 @@ class AclMatcherTest {
runBlocking {
AclMatcher().apply {
init(AclTest.INPUT1.reader())
Assert.assertTrue(shouldBypassIpv4("0.1.2.3".parseNumericAddress()!!.address))
Assert.assertFalse(shouldBypassIpv4("1.0.1.2".parseNumericAddress()!!.address))
Assert.assertTrue(shouldBypassIpv4("1.0.3.2".parseNumericAddress()!!.address))
Assert.assertTrue(shouldBypassIpv6("::".parseNumericAddress()!!.address))
Assert.assertFalse(shouldBypassIpv6("2020::2020".parseNumericAddress()!!.address))
Assert.assertTrue(shouldBypassIpv6("fe80::2020".parseNumericAddress()!!.address))
Assert.assertTrue(shouldBypass("4tern.com") == false)
Assert.assertTrue(shouldBypass("www.4tern.com") == false)
Assert.assertNull(shouldBypass("www.google.com"))
}
}
}
@Test
fun bypassList() {
runBlocking {
AclMatcher().apply {
init(AclTest.INPUT2.reader())
Assert.assertFalse(shouldBypassIpv4("0.1.2.3".parseNumericAddress()!!.address))
Assert.assertTrue(shouldBypassIpv4("1.0.1.2".parseNumericAddress()!!.address))
Assert.assertFalse(shouldBypassIpv4("1.0.3.2".parseNumericAddress()!!.address))
Assert.assertFalse(shouldBypassIpv6("::".parseNumericAddress()!!.address))
Assert.assertTrue(shouldBypassIpv6("2020::2020".parseNumericAddress()!!.address))
Assert.assertFalse(shouldBypassIpv6("fe80::2020".parseNumericAddress()!!.address))
Assert.assertTrue(shouldBypass("4tern.com") == true)
Assert.assertTrue(shouldBypass("www.4tern.com") == true)
Assert.assertTrue(shouldBypassIpv4("10.0.1.2".parseNumericAddress()!!.address))
Assert.assertTrue(shouldBypassIpv4("10.10.1.2".parseNumericAddress()!!.address))
Assert.assertFalse(shouldBypassIpv4("11.0.1.2".parseNumericAddress()!!.address))
Assert.assertTrue(shouldBypass("chrome.com") == true)
Assert.assertTrue(shouldBypass("about.google") == false)
Assert.assertNull(shouldBypass("www.google.com"))
}
}
......
......@@ -25,11 +25,23 @@ import org.junit.Test
class AclTest {
companion object {
const val INPUT1 = """[proxy_all]
[bypass_list]
const val BYPASS_BASE = """[bypass_all]
[proxy_list]"""
const val INPUT1 = """$BYPASS_BASE
1.0.1.0/24
2000::/8
(?:^|\.)4tern\.com${'$'}
"""
const val INPUT2 = """[proxy_all]
[bypass_list]
10.3.0.0/16
10.0.0.0/8
(?:^|\.)chrome\.com${'$'}
[proxy_list]
# ignored
0.0.0.0/0
(?:^|\.)about\.google${'$'}
"""
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment