-
Notifications
You must be signed in to change notification settings - Fork 10
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
VX-97 Add check IP Address format #31
Conversation
b1059df
to
c6b3c8c
Compare
c6b3c8c
to
6e94e08
Compare
Codecov Report
@@ Coverage Diff @@
## master #31 +/- ##
==========================================
+ Coverage 86.44% 86.81% +0.37%
==========================================
Files 7 7
Lines 177 182 +5
==========================================
+ Hits 153 158 +5
Misses 15 15
Partials 9 9
Continue to review full report at Codecov.
|
utils/utils.go
Outdated
@@ -18,3 +19,12 @@ func GenerateVethName(podUUID, containerVethName string) string { | |||
str := sha256String(podUUID + containerVethName) | |||
return fmt.Sprintf("veth%s", str[0:8]) | |||
} | |||
|
|||
func VerifyIP(str string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to propose using IsValidIP
as function name
func IsValidIP(ip string) bool
utils/utils.go
Outdated
return net.ParseIP(str) != nil | ||
} | ||
|
||
func VerifyCIDR(str string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to propose using IsValidCIDR
as function name
func IsValidCIDR(cidr string) bool
client/main.go
Outdated
@@ -45,6 +46,16 @@ func main() { | |||
os.Exit(1) | |||
} | |||
|
|||
// Verify IP address | |||
if utils.VerifyIP(options.Interface.IP) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should parse input string for IP address validity not options.Interface.IP
The options.Interface.IP
isn't only has IP address. it contains mask.
if utils.VerifyIP(options.Interface.Gateway)
client/main.go
Outdated
} | ||
|
||
// Verify gateway address | ||
if utils.VerifyCIDR(options.Interface.Gateway) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should parse input string for CIDR address validity not options.Interface.Gateway
The options.Interface.Gateway
only has a IP address.
if utils.VerifyCIDR(options.Interface.IP)
utils/utils_test.go
Outdated
@@ -10,3 +10,13 @@ func TestGenerateVethName(t *testing.T) { | |||
o := GenerateVethName("12345678", "12345678") | |||
assert.Equal(t, "veth33cdbc38", o) | |||
} | |||
|
|||
func TestVerifyIP(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestIsValidIP
utils/utils_test.go
Outdated
assert.Equal(t, true, o) | ||
} | ||
|
||
func TestVerifyCIDR(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestIsValidCIDR
2761229
to
d0e605d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also test invalid IP and CIDR
d931633
to
2deb06b
Compare
No description provided.