mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-15 01:09:20 +02:00
Add test to ParaseIPList
This commit is contained in:
parent
44317bd657
commit
5d5beb2028
|
@ -25,6 +25,27 @@ func init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParaseIPList(t *testing.T) {
|
||||||
|
t.Log(os.Getenv("xray.location.asset"))
|
||||||
|
|
||||||
|
common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoiptestrouter.dat"), platform.GetAssetLocation("geoip.dat")))
|
||||||
|
|
||||||
|
ips := []string{
|
||||||
|
"geoip:us",
|
||||||
|
"geoip:cn",
|
||||||
|
"geoip:!cn",
|
||||||
|
"ext:geoiptestrouter.dat:!cn",
|
||||||
|
"ext:geoiptestrouter.dat:ca",
|
||||||
|
"ext-ip:geoiptestrouter.dat:!cn",
|
||||||
|
"ext-ip:geoiptestrouter.dat:!ca",
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := ParaseIPList(ips)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to parse geoip list, got %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGeoIPMatcherContainer(t *testing.T) {
|
func TestGeoIPMatcherContainer(t *testing.T) {
|
||||||
container := &GeoIPMatcherContainer{}
|
container := &GeoIPMatcherContainer{}
|
||||||
|
|
||||||
|
@ -123,18 +144,6 @@ func TestGeoIPMatcher(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGeoIPMatcher4CN(t *testing.T) {
|
|
||||||
ips, err := loadGeoIP("CN")
|
|
||||||
common.Must(err)
|
|
||||||
|
|
||||||
matcher := &GeoIPMatcher{}
|
|
||||||
common.Must(matcher.Init(ips))
|
|
||||||
|
|
||||||
if matcher.Match([]byte{8, 8, 8, 8}) {
|
|
||||||
t.Error("expect CN geoip doesn't contain 8.8.8.8, but actually does")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGeoIPReverseMatcher(t *testing.T) {
|
func TestGeoIPReverseMatcher(t *testing.T) {
|
||||||
cidrList := CIDRList{
|
cidrList := CIDRList{
|
||||||
{Ip: []byte{8, 8, 8, 8}, Prefix: 32},
|
{Ip: []byte{8, 8, 8, 8}, Prefix: 32},
|
||||||
|
@ -171,6 +180,18 @@ func TestGeoIPReverseMatcher(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGeoIPMatcher4CN(t *testing.T) {
|
||||||
|
ips, err := loadGeoIP("CN")
|
||||||
|
common.Must(err)
|
||||||
|
|
||||||
|
matcher := &GeoIPMatcher{}
|
||||||
|
common.Must(matcher.Init(ips))
|
||||||
|
|
||||||
|
if matcher.Match([]byte{8, 8, 8, 8}) {
|
||||||
|
t.Error("expect CN geoip doesn't contain 8.8.8.8, but actually does")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGeoIPMatcher6US(t *testing.T) {
|
func TestGeoIPMatcher6US(t *testing.T) {
|
||||||
ips, err := loadGeoIP("US")
|
ips, err := loadGeoIP("US")
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
|
|
Loading…
Reference in New Issue