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

fix(report): Result field is optional. #214

Merged
merged 2 commits into from
Mar 4, 2024

Conversation

jvanz
Copy link
Member

@jvanz jvanz commented Mar 1, 2024

Description

The code which builds the PolicyReportResult does check if the Result field from the AdmissionRespose type is nil. Causing a nil pointer dereference. This field is optional and it can be nil. Specially if the policy result is "allowed" where there is not further details about the result of the evaluation.

This commit fixes this issue by checking if the Result field has something before trying to get the possible error message from the policy.

Fix #212

Test

I've added a new unit test to cover this bug.

make unit-tests

The code which builds the PolicyReportResult does check if the Result
field from the AdmissionRespose type is nil. Causing a nil pointer
dereference. This field is optional and it can be nil. Specially if the
policy result is "allowed" where there is not further details about the
result of the evaluation.

This commit fixes this issue by checking if the Result field has
something before trying to get the possible error message from the
policy.

Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
@jvanz jvanz self-assigned this Mar 1, 2024
@jvanz jvanz requested a review from a team as a code owner March 1, 2024 20:15
@@ -235,6 +235,46 @@ func TestNewPolicyReportResult(t *testing.T) {
},
},
},
{
name: "Validating policy, allowed response with no message",
Copy link
Contributor

@fabriziosestito fabriziosestito Mar 4, 2024

Choose a reason for hiding this comment

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

Instead of adding a new test we should modify the existing tests in this file and the mock policy server handler in scanner_test.go to remove the Result when the AdmissionReview is allowed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I was thinking about that too. But I've decided to keep the old tests just in case I was missing something that you know. As you are not around and leave that for the review process, like know. :)

I've just updated the tests. Please, give another look.

AdmissionResponse does not have the Result field filled when it is
allowed by the policy.

Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
@jvanz jvanz requested a review from fabriziosestito March 4, 2024 13:25
Copy link

codecov bot commented Mar 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.37%. Comparing base (3bfaf53) to head (26e6d90).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #214   +/-   ##
=======================================
  Coverage   72.37%   72.37%           
=======================================
  Files           6        6           
  Lines         637      637           
=======================================
  Hits          461      461           
  Misses        115      115           
  Partials       61       61           
Flag Coverage Δ
unit-tests 72.37% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fabriziosestito fabriziosestito merged commit 8987beb into kubewarden:main Mar 4, 2024
7 checks passed
@jvanz jvanz deleted the issue212 branch March 4, 2024 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1.11.0-rc1 Panic: runtime error: invalid memory address or nil pointer dereference
2 participants