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
Validate audit log parts #779
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## v3/dev #779 +/- ##
==========================================
- Coverage 81.86% 81.79% -0.07%
==========================================
Files 153 153
Lines 8192 8207 +15
==========================================
+ Hits 6706 6713 +7
- Misses 1267 1274 +7
- Partials 219 220 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
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.
Good one! Please do add some tests.
internal/actions/ctl.go
Outdated
@@ -112,7 +112,16 @@ func (a *ctlFn) Evaluate(_ plugintypes.RuleMetadata, txS plugintypes.Transaction | |||
tx.AuditEngine = ae | |||
case ctlAuditLogParts: | |||
// TODO lets switch it to a string |
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.
// TODO lets switch it to a string |
types/waf.go
Outdated
@@ -106,6 +106,30 @@ type AuditLogPart byte | |||
// Z: Final boundary, signifies the end of the entry (mandatory). | |||
type AuditLogParts []AuditLogPart | |||
|
|||
var validOpts = map[AuditLogPart]bool{ |
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.
In order to save some bytes we could turn this into map[AuditLogPart]struct{}
as struct{}
allocates zero bytes.
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.
thanks, I don't know this way before
} | ||
func TestInvalidAuditLog(t *testing.T) { | ||
AuditLogParts, err := types.ParseAuditLogParts("ABCDEFGHIJKLMN") | ||
if err == nil || !reflect.DeepEqual(AuditLogParts, types.AuditLogParts("")) { |
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'd avoid using reflection and cast AuditLogParts to string instead.
@@ -429,6 +430,28 @@ func TestAuditLog(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestParseAuditLog(t *testing.T) { | |||
tx := makeTransaction(t) |
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 wonder why we need to create a transaction to test the log parts.
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.
sorry,I just cody the TestAuditLog()
Thanks for this! I left some comments. |
Great work @Hayak3 |
fix #678