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

VX-97 Add check IP Address format #31

Merged
merged 4 commits into from
Jun 12, 2018
Merged

VX-97 Add check IP Address format #31

merged 4 commits into from
Jun 12, 2018

Conversation

chenyunchen
Copy link
Contributor

No description provided.

@chenyunchen chenyunchen force-pushed the alex/CheckIPFormat branch 2 times, most recently from b1059df to c6b3c8c Compare June 11, 2018 10:25
@codecov
Copy link

codecov bot commented Jun 11, 2018

Codecov Report

Merging #31 into master will increase coverage by 0.37%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
utils/utils.go 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ff044c9...6e79547. Read the comment docs.

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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) {
Copy link
Contributor

@John-Lin John-Lin Jun 11, 2018

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) {
Copy link
Contributor

@John-Lin John-Lin Jun 11, 2018

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) 

@@ -10,3 +10,13 @@ func TestGenerateVethName(t *testing.T) {
o := GenerateVethName("12345678", "12345678")
assert.Equal(t, "veth33cdbc38", o)
}

func TestVerifyIP(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

TestIsValidIP

assert.Equal(t, true, o)
}

func TestVerifyCIDR(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

TestIsValidCIDR

@John-Lin John-Lin requested a review from hwchiu June 11, 2018 16:30
Copy link
Contributor

@hwchiu hwchiu left a 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

@chenyunchen chenyunchen changed the title Add check IP Address format VX-97 Add check IP Address format Jun 12, 2018
@hwchiu hwchiu merged commit 9771cdb into master Jun 12, 2018
@hwchiu hwchiu deleted the alex/CheckIPFormat branch June 12, 2018 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants