(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestValidateIPAM(t *testing.T) { |
| 13 | tests := []struct { |
| 14 | name string |
| 15 | ipam []network.IPAMConfig |
| 16 | ipv6 bool |
| 17 | expectedErrors []string |
| 18 | }{ |
| 19 | { |
| 20 | name: "IP version mismatch", |
| 21 | ipam: []network.IPAMConfig{{ |
| 22 | Subnet: netip.MustParsePrefix("10.10.10.0/24"), |
| 23 | IPRange: netip.MustParsePrefix("2001:db8::/32"), |
| 24 | Gateway: netip.MustParseAddr("2001:db8::1"), |
| 25 | AuxAddress: map[string]netip.Addr{"DefaultGatewayIPv4": netip.MustParseAddr("2001:db8::1")}, |
| 26 | }}, |
| 27 | expectedErrors: []string{ |
| 28 | "invalid ip-range 2001:db8::/32: parent subnet is an IPv4 block", |
| 29 | "invalid gateway 2001:db8::1: parent subnet is an IPv4 block", |
| 30 | "invalid auxiliary address DefaultGatewayIPv4: parent subnet is an IPv4 block", |
| 31 | }, |
| 32 | }, |
| 33 | { |
| 34 | // Regression test for https://github.com/moby/moby/issues/47202 |
| 35 | name: "IPv6 subnet is discarded with no error when IPv6 is disabled", |
| 36 | ipam: []network.IPAMConfig{{Subnet: netip.MustParsePrefix("2001:db8::/32")}}, |
| 37 | ipv6: false, |
| 38 | }, |
| 39 | { |
| 40 | name: "IPRange bigger than its subnet", |
| 41 | ipam: []network.IPAMConfig{ |
| 42 | {Subnet: netip.MustParsePrefix("10.10.10.0/24"), IPRange: netip.MustParsePrefix("10.0.0.0/8")}, |
| 43 | }, |
| 44 | expectedErrors: []string{ |
| 45 | "invalid ip-range 10.0.0.0/8: CIDR block is bigger than its parent subnet 10.10.10.0/24", |
| 46 | }, |
| 47 | }, |
| 48 | { |
| 49 | name: "Out of range prefix & addresses", |
| 50 | ipam: []network.IPAMConfig{{ |
| 51 | Subnet: netip.MustParsePrefix("10.0.0.0/8"), |
| 52 | IPRange: netip.MustParsePrefix("192.168.0.1/24"), |
| 53 | Gateway: netip.MustParseAddr("192.168.0.1"), |
| 54 | AuxAddress: map[string]netip.Addr{"DefaultGatewayIPv4": netip.MustParseAddr("192.168.0.1")}, |
| 55 | }}, |
| 56 | expectedErrors: []string{ |
| 57 | "invalid ip-range 192.168.0.1/24: it should be 192.168.0.0/24", |
| 58 | "invalid ip-range 192.168.0.1/24: parent subnet 10.0.0.0/8 doesn't contain ip-range", |
| 59 | "invalid gateway 192.168.0.1: parent subnet 10.0.0.0/8 doesn't contain this address", |
| 60 | "invalid auxiliary address DefaultGatewayIPv4: parent subnet 10.0.0.0/8 doesn't contain this address", |
| 61 | }, |
| 62 | }, |
| 63 | { |
| 64 | name: "Subnet with host fragment set", |
| 65 | ipam: []network.IPAMConfig{{ |
| 66 | Subnet: netip.MustParsePrefix("10.10.10.0/8"), |
| 67 | }}, |
| 68 | expectedErrors: []string{"invalid subnet 10.10.10.0/8: it should be 10.0.0.0/8"}, |
| 69 | }, |
nothing calls this directly
no test coverage detected
searching dependent graphs…