fix(metrics): validate metrics date-range query params#70
Merged
Conversation
Add date-window validation to MetricsQuerySchema: reject unparseable from/to dates, inverted ranges (from after to), and windows larger than ~1 year. This removes the TODO in the metrics controller and makes both the summary and timeseries endpoints reject bad ranges with 400 instead of silently coercing Invalid Date into the query. Fix a pre-existing internal test that was named 'returns 400 for invalid query' but asserted 200 (it documented the missing validation). Add unit coverage for the schema. Addresses #17 (date-window validation). Broadening the timeseries beyond login success/failure remains open.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #17 (date-window validation portion)
Summary
The metrics controller had a
TODO: need to parse these for valid time ranges;from/towere passed straight intonew Date(...), so an invalid value becameInvalid Dateand silently produced an empty or bogus filter instead of an error.This adds validation to
MetricsQuerySchema(used by both the summary and timeseries endpoints):from/to.fromafterto).Notes
200— it was documenting the missing validation. It now asserts400, matching its name and the corrected behavior.Out of scope (issue stays open)
The second half of #17 — broadening the timeseries beyond
login_success/login_failedto cover OTP/WebAuthn/magic-link activity — is a larger, response-shape-affecting change and is left for a follow-up. I'll note this on the issue.Testing
Typecheck + lint clean; metrics + internal suites pass.