Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78b58a9188 |
@@ -133,9 +133,10 @@ func TestGetIPInfoFindsMostSpecificLiveRoute(t *testing.T) {
|
|||||||
lookup("2001:db8:1:2::3", "2001:db8:1::/48")
|
lookup("2001:db8:1:2::3", "2001:db8:1::/48")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestGetIPInfoIgnoresShortRoutes checks that a default route or a route
|
// TestGetIPInfoIgnoresShortRoutes checks that the IP lookup does not report a
|
||||||
// shorter than the lookup's minimum mask length is not reported as the route
|
// default route, or a route shorter than /8 for IPv4 or /16 for IPv6, as the
|
||||||
// for an address, and that a longer route covering the address still is.
|
// route for an address, and that a route of exactly /8 or /16, or longer, still
|
||||||
|
// is. The prefixes are written out so that a wrong limit fails the test.
|
||||||
func TestGetIPInfoIgnoresShortRoutes(t *testing.T) {
|
func TestGetIPInfoIgnoresShortRoutes(t *testing.T) {
|
||||||
cfg := &config.Config{StateDir: t.TempDir()}
|
cfg := &config.Config{StateDir: t.TempDir()}
|
||||||
|
|
||||||
@@ -165,8 +166,26 @@ func TestGetIPInfoIgnoresShortRoutes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lookup checks that ip resolves to the live prefix netblock from asn.
|
||||||
|
lookup := func(ip, netblock string, asn int) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
info, err := db.GetIPInfo(ip)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("GetIPInfo(%s): %v", ip, err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if info.Netblock != netblock || info.ASN != asn {
|
||||||
|
t.Errorf("GetIPInfo(%s) = %s AS%d, want %s AS%d", ip, info.Netblock, info.ASN, netblock, asn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default and very short routes, and routes one bit shorter than each limit.
|
||||||
announce("2000::/3", 64500)
|
announce("2000::/3", 64500)
|
||||||
announce("0.0.0.0/0", 64500)
|
announce("0.0.0.0/0", 64500)
|
||||||
|
announce("2000::/15", 64500)
|
||||||
|
announce("192.0.0.0/7", 64500)
|
||||||
|
|
||||||
for _, ip := range []string{"2001:db8::1", "192.0.2.1"} {
|
for _, ip := range []string{"2001:db8::1", "192.0.2.1"} {
|
||||||
if info, err := db.GetIPInfo(ip); !errors.Is(err, ErrNoRoute) {
|
if info, err := db.GetIPInfo(ip); !errors.Is(err, ErrNoRoute) {
|
||||||
@@ -174,15 +193,16 @@ func TestGetIPInfoIgnoresShortRoutes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
announce("2001:db8::/32", 64501)
|
// Routes of exactly the minimum length are used.
|
||||||
|
announce("2001::/16", 64501)
|
||||||
|
announce("192.0.0.0/8", 64501)
|
||||||
|
|
||||||
info, err := db.GetIPInfo("2001:db8::1")
|
lookup("2001:db8::1", "2001::/16", 64501)
|
||||||
if err != nil {
|
lookup("192.0.2.1", "192.0.0.0/8", 64501)
|
||||||
t.Fatalf("GetIPInfo(2001:db8::1) after a /32 is added: %v", err)
|
|
||||||
}
|
announce("2001:db8::/32", 64502)
|
||||||
if info.Netblock != "2001:db8::/32" || info.ASN != 64501 {
|
|
||||||
t.Errorf("GetIPInfo(2001:db8::1) = %s AS%d, want 2001:db8::/32 AS64501", info.Netblock, info.ASN)
|
lookup("2001:db8::1", "2001:db8::/32", 64502)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestConnectionPoolPragmas holds several pooled connections open at once and
|
// TestConnectionPoolPragmas holds several pooled connections open at once and
|
||||||
|
|||||||
Reference in new issue
Block a user