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

Wrp validation update #318

Merged
merged 13 commits into from
Nov 14, 2023
Merged

Wrp validation update #318

merged 13 commits into from
Nov 14, 2023

Conversation

primaryHandler.go Outdated Show resolved Hide resolved
err = multierr.Append(err, wrp.SourceValidator(*msg))
err = multierr.Append(err, wrp.DestinationValidator(*msg))
if err != nil {
logger.Warn("errors returned during WRP message validation", zap.Error(err))
Copy link
Contributor

@denopink denopink Nov 13, 2023

Choose a reason for hiding this comment

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

Suggested change
logger.Warn("errors returned during WRP message validation", zap.Error(err))
logger.Warn("Found WRP message validation failures", zap.Error(err))

Comment on lines 573 to 575
for _, v := range validators {
err = multierr.Append(err, v.Validate(*msg))
}
Copy link
Contributor

@denopink denopink Nov 13, 2023

Choose a reason for hiding this comment

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

i say keep the for loop pattern you had and add assert.ErrorIs errors.Is
it'll help manage and make clear which error we'll like to return 400s for

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is there a different assert package? i thought assert was just for testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nevermind i think i found the function i can use.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh sorry, I meant to say errors.Is and not assert.ErrorIs

Copy link
Contributor

@denopink denopink left a comment

Choose a reason for hiding this comment

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

great progress 😄 let a couple of suggestions

Copy link

codecov bot commented Nov 14, 2023

Codecov Report

Attention: 19 lines in your changes are missing coverage. Please review.

Comparison is base (64a85b5) 20.95% compared to head (49637ec) 20.64%.
Report is 1 commits behind head on main.

Files Patch % Lines
primaryHandler.go 0.00% 19 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #318      +/-   ##
==========================================
- Coverage   20.95%   20.64%   -0.32%     
==========================================
  Files           7        7              
  Lines         730      741      +11     
==========================================
  Hits          153      153              
- Misses        575      586      +11     
  Partials        2        2              
Flag Coverage Δ
unittests 20.64% <0.00%> (-0.32%) ⬇️

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.

Copy link

guardrails bot commented Nov 14, 2023

All previously detected findings have been fixed. Good job! 👍🎉

We will keep this comment up-to-date as you go along and notify you of any security issues that we identify.


👉 Go to the dashboard for detailed results.

📥 Happy? Share your feedback with us.

go.mod Outdated Show resolved Hide resolved
for _, v := range validators {
err = multierr.Append(err, v.Validate(*msg))
}

if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need this nil check since errors.Is should handle this

Suggested change
if err != nil {
if err != nil {

if err != nil {

if warningErrors != nil {
logger.Warn("WRP message validation failures found", zap.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.Warn("WRP message validation failures found", zap.Error(err))
logger.Warn("WRP message validation warnings found", zap.Error(warningErrors))

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(
w,
`{"code": %d, "message": "%s"}`,
http.StatusBadRequest,
fmt.Sprintf("failed to validate WRP message: %s", err),
)
fmt.Sprintf("failed to validate WRP message: %s", err))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fmt.Sprintf("failed to validate WRP message: %s", err))
fmt.Sprintf("failed to validate WRP message: %s", failureError))

Copy link
Contributor

@denopink denopink left a comment

Choose a reason for hiding this comment

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

lgtm!

@maurafortino maurafortino merged commit f674634 into main Nov 14, 2023
12 of 14 checks passed
@maurafortino maurafortino deleted the wrp-validation-update branch November 14, 2023 20:59
@maurafortino maurafortino restored the wrp-validation-update branch November 14, 2023 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants