Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add service cluster IP range unit test #95630

Merged
merged 1 commit into from
Oct 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions cmd/kube-apiserver/app/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,32 @@ func TestGetServiceIPAndRanges(t *testing.T) {
{"", "10.0.0.1", "10.0.0.0/24", "<nil>", false},
{"192.0.2.1/24", "192.0.2.1", "192.0.2.0/24", "<nil>", false},
{"192.0.2.1/24,192.168.128.0/17", "192.0.2.1", "192.0.2.0/24", "192.168.128.0/17", false},
// Dual stack IPv4/IPv6
{"192.0.2.1/24,2001:db2:1:3:4::1/112", "192.0.2.1", "192.0.2.0/24", "2001:db2:1:3:4::/112", false},
// Dual stack IPv6/IPv4
{"2001:db2:1:3:4::1/112,192.0.2.1/24", "2001:db2:1:3:4::1", "2001:db2:1:3:4::/112", "192.0.2.0/24", false},

{"192.0.2.1/30,192.168.128.0/17", "<nil>", "<nil>", "<nil>", true},
// Invalid ip range[0] IPv4 mask
{"192.0.2.1/33,192.168.128.0/17", "<nil>", "<nil>", "<nil>", true},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is meant to be used for dual stack IIIRC,
Can you please add test cases for IPv4, IPv6 and IPv6, IPv4 addresses?
just replace one of the subnets by 2001:db2:1:3:4::/112 per example

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add also invalid ip addresses to test it fails, ie,
"bad.ip.range,192.168.0.2/24"
"192.168.0.1" notice is missing the mask , i.e /24

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I fixed to include these.

  • Dual stack IPv4/IPv6
  • missing IPv4, IPv6 mask
  • invalid IP address format

And this.

  • Invalid IPv6 mask

// Invalid ip range[1] IPv4 mask
{"192.0.2.1/24,192.168.128.0/33", "<nil>", "<nil>", "<nil>", true},
// Invalid ip range[0] IPv6 mask
{"2001:db2:1:3:4::1/129,192.0.2.1/24", "<nil>", "<nil>", "<nil>", true},
// Invalid ip range[1] IPv6 mask
{"192.0.2.1/24,2001:db2:1:3:4::1/129", "<nil>", "<nil>", "<nil>", true},
// Invalid ip range[0] missing IPv4 mask
{"192.0.2.1,192.168.128.0/17", "<nil>", "<nil>", "<nil>", true},
// Invalid ip range[1] missing IPv4 mask
{"192.0.2.1/24,192.168.128.1", "<nil>", "<nil>", "<nil>", true},
// Invalid ip range[0] missing IPv6 mask
{"2001:db2:1:3:4::1,192.0.2.1/24", "<nil>", "<nil>", "<nil>", true},
// Invalid ip range[1] missing IPv6 mask
{"192.0.2.1/24,2001:db2:1:3:4::1", "<nil>", "<nil>", "<nil>", true},
// Invalid ip range[0] IP address format
{"bad.ip.range,192.168.0.2/24", "<nil>", "<nil>", "<nil>", true},
// Invalid ip range[1] IP address format
{"192.168.0.2/24,bad.ip.range", "<nil>", "<nil>", "<nil>", true},
}

for _, test := range tests {
Expand Down