-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Cwe 190 #1057
Cwe 190 #1057
Conversation
@DaanHoogland, pretty good job, you created the test cases and removed the return null cases. |
@rafaelweingartner the cast was the reason for starting this. Coverity complained about a 32 bit shift on an integer (31 bit + sign) |
Got it @DaanHoogland. |
@rafaelweingartner sure, they're not needed but I'll add them for clarity. |
That is it. |
I was just re-checking the code, what about creating a test case for "netMaskFromCidr" method? |
@rafaelweingartner yes of course. you caught me pants down ;) |
static long netMaskFromCidr(final long cidrSize) { | ||
return ((long)0xffffffff) >> MAX_CIDR - cidrSize << MAX_CIDR - cidrSize; | ||
} | ||
|
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.
Why are tho static methods using "package" modifier? Are classes in the same package going to access it? If the answer is no, they can be made "private".
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.
for testing purpose (so yes)
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 think that it is fine letting the method with default modifier.
The point of a test case is that we can/should write tests for a single method. Therefore, if we want to test the method “getCidrSizeFromString”, we should write a test case for that specific method, and not for another one that uses it.
After we make sure that a method works fine, when we test another method (let’s say “cidrToLong”) that uses the first one already tested, we can use EasyMock/Mockito or another test suite to mock the method that we know works, this way we facilitate the writing of test cases.
b0a8d87
to
02058b9
Compare
FYI: @DaanHoogland My tests show 29 test failures. I will retest to be sure, but please hold until this is done. Stuff like this:
|
@remibergsma running them myself as well, now |
to many unexplained failures for such a small refactor. |
Hi @DaanHoogland, I have created a PR for your branch, so you can get those changes and reopen your PR. |
@rafaelweingartner thanks for picking this up. it is not a matter of giving up but of priorities and I didn't want to keep it open knowing there was work to do that I wouldn't look into. I'll have a look at your PR and run the integration suite against them. |
Changed the behavior of methods that use NetUtils.cidrToLong(String)
I understand why you closed the PR, but after a quick review, I thought that I could help you, so let’s see if now everything is ok |
@DaanHoogland @rafaelweingartner Much better now, just one failed test to resolve: Failed test:
Details:
|
thanks @remibergsma |
@DaanHoogland It could be a result of another failure. On master this test passes, so maybe you can run just this test yourself and look at the details? |
I was busy starting ;) |
:-) |
@remibergsma for me test_01_create_redundant_VPC_2tiers_4VMs_4IPs_4PF_ACL fails. That is not the one you meant is it? I also saw the failure you had. |
@remibergsma, could you send me the stack trace of the test that failed? |
1057.network.results.txt |
LGTM based on these tests:
Result:
And:
Result:
I didn't test the actual feature. This just shows it didn't break anything else. |
Cwe 190coverity warnings of this type adressed. Some where dismissed and maybe with reason but it seemed possible to remove them and hence obligatory ;p * pr/1057: move back to original contract of isNetworksOverlap() Changed the behavior of methods that use NetUtils.cidrToLong(String) CWE-190 unit test for extremes of long netMaskFromCidr(long) CWE-190 netmask as long form cidr-size as method CID-1116482 cidrToLong cleanup of bitshift problem CID-1116483 cidr to netmask bitshifts guarded with casts CID-1116484 cast to long and use long as cidrsize type and simpel test CID-1116485: cast cidr during bit shifting and simple test included CID-1175714 casts before bit shift Signed-off-by: Daan Hoogland <daan@onecht.net>
coverity warnings of this type adressed. Some where dismissed and maybe with reason but it seemed possible to remove them and hence obligatory ;p