Skip to content

Fix Date::Error exception when viewing audit logs for an invalid date

What does this MR do and why?

  1. We already have the checks in place, however, we were not returning when the filter failed and therefore it raised an exception later on when we tried to parse the invalid date.
  2. Added an early return to the validate_date_params method to fix the exception raised when an invalid date is passed for either created_before or created_after parameter.
  3. Included the before_action validate_date_params to AuditLogReportsController to prevent exceptions if invalid dates are passed for while downloading the audit events csv.

Screenshots or screen recordings

These are strongly recommended to assist reviewers and reduce the time to merge your change.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Ensure that you have an ultimate license.
  2. View the instance audit logs with an invalid date. Example - https://gdk.test:3000/admin/audit_logs?created_after=2019-02-01&created_before=2022-02-32. An error "Invalid date format. Please use UTC format as YYYY-MM-DD" should be displayed.
  3. View the group audit logs with an invalid date. Example - https://gdk.test:3000/groups/flightjs/-/audit_events?created_before=2021-13-31. The same error should be displayed.
  4. View the project audit logs with an invalid date. Example - https://gdk.test:3000/flightjs/Flight/-/audit_events?created_before=w. The error should be displayed this time as well.
  5. Try downloading the audit even CSV for an invalid date. Example - https://gdk.test:3000/admin/audit_log_reports.csv?created_before=2022-02-30. HTTP status 400 should be returned.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #352747 (closed)

Merge request reports

Loading