Skip to content

Conversation

@ck319
Copy link
Contributor

@ck319 ck319 commented May 25, 2022

Reason for Change:

Issue Fixed:

Requirements:

Notes:

@ck319 ck319 requested a review from a team as a code owner May 25, 2022 00:13
@ck319 ck319 requested review from matmerr and removed request for a team May 25, 2022 00:13
@ck319 ck319 added the npm Related to NPM. label May 25, 2022
ipDetails := strings.Split(ip, ",")
if util.IsIPV4(ipDetails[0]) {
return true
err := ValidateIPBlock(ipDetails[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

should we validate the whole ip like we used to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to change this because it would fail in the case of tcp since that method splits on a space and tcp has a comma. That method only validates CIDR so sending it already split seemed to make sense in this case

}
}

func TestValidateIPSetMemberIP(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.

nit: let's put this code next to the other validate ip block tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

npm/util/util.go Outdated
Comment on lines 358 to 359
ipOnly := strings.Split(ip, "/")
return net.ParseIP(ipOnly[0]).To4() != nil
Copy link
Collaborator

@rbtr rbtr May 26, 2022

Choose a reason for hiding this comment

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

consider using the netip package (here but really everywhere)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

npm/util/util.go Outdated
_, _, err = net.ParseCIDR(ip)
return (err == nil && address.Is4())
_, _, err2 := net.ParseCIDR(ip)
return (err == nil && err2 == nil && address.Is4())
Copy link
Collaborator

Choose a reason for hiding this comment

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

check err where it is assigned and you don't have to avoid reassigning it and checking so many things here.

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, updated

@ck319 ck319 merged commit 2bbbe81 into master Jun 15, 2022
@ck319 ck319 deleted the ipvalidation branch June 15, 2022 21:35
matmerr pushed a commit to matmerr/azure-container-networking that referenced this pull request Jun 29, 2022
* updated validation method and added unit tests

* moved unit test

* updated isIPV4 to use netip

* fixed bool issue

* fixed ipblock issue

* refactored code

* updated error handling

* updated error handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

npm Related to NPM.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants