Skip to content

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

Description

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

Stacktrace

Sentry - https://sentry.gitlab.net/gitlab/gitlabcom/issues/3184876/events/?environment=gprd

Date::Error: invalid date
  from ee/app/controllers/concerns/audit_events/date_range.rb:14:in `parse'
  from ee/app/controllers/concerns/audit_events/date_range.rb:14:in `set_date_range'
  from activesupport (6.1.4.4) lib/active_support/callbacks.rb:427:in `block in make_lambda'
  from activesupport (6.1.4.4) lib/active_support/callbacks.rb:179:in `block (2 levels) in halting_and_conditional'
  from actionpack (6.1.4.4) lib/abstract_controller/callbacks.rb:34:in `block (2 levels) in <module:Callbacks>'
  from activesupport (6.1.4.4) lib/active_support/callbacks.rb:180:in `block in halting_and_conditional'
  from activesupport (6.1.4.4) lib/active_support/callbacks.rb:512:in `block in invoke_before'
  from activesupport (6.1.4.4) lib/active_support/callbacks.rb:512:in `each'
  from activesupport (6.1.4.4) lib/active_support/callbacks.rb:512:in `invoke_before'
  from activesupport (6.1.4.4) lib/active_support/callbacks.rb:115:in `block in run_callbacks'
  from ee/lib/gitlab/ip_address_state.rb:10:in `with'
  from ee/app/controllers/ee/application_controller.rb:46:in `set_current_ip_address'

Steps to reproduce

  1. Visit any of the audit logs page (instance/group/project) and supply an invalid date for either created_before or created_after parameter.
  2. For example: https://gdk.test:3000/admin/audit_logs?created_before=2021-13-31. Notice that the month is invalid here.
  3. Another example: https://gdk.test:3000/admin/audit_logs?created_before=invalid-string.

Expected behaviour

validate_date_params before_action defined inside EnforcesValidDateParams should show the invalid date alert as shown in the image below. image