fix(das): validate the since query param instead of returning 500#227
Open
tryeverything24 wants to merge 1 commit into
Open
fix(das): validate the since query param instead of returning 500#227tryeverything24 wants to merge 1 commit into
tryeverything24 wants to merge 1 commit into
Conversation
…400, not 500 GET /api/v1/miners/:githubId/pulls?since=... and /issues?since=... pass the raw query string straight into a ::timestamptz cast. A non-timestamp value (e.g. since=banana, or since= on /issues, which binds the empty string) makes Postgres reject the cast, surfacing as a QueryFailedError 500 instead of a 400 — misclassifying a client mistake as a server failure. Consumers that treat 5xx as retryable (the usual convention) will then hammer a request that can never succeed. The POST variants of the same endpoints (parseSinceByRepo) and the dashboard controller already validate and normalize timestamps to ISO; this brings the two GET endpoints in line: absent/empty keeps the existing default behavior, anything else must parse as a date and is normalized with toISOString() before it reaches SQL. Adds controller unit tests covering rejection, normalization, the default window on /pulls, and the omitted/empty null mode on /issues.
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.
PR body — tryeverything24 — entrius/das-github-mirror
Branch:
fix-miners-since-validation(in WSL Ubuntu-22.04 clone/root/dgm, commit0e1c106, based onorigin/test@a188d3b)Base:
testTitle:
fix(miners): validatesincequery param so malformed input returns 400, not 500Bug
GET /api/v1/miners/:githubId/pulls?since=...andGET /api/v1/miners/:githubId/issues?since=...pass the rawsincequery string straight into SQL, where it hits atimestamptzcomparison (p.merged_at >= $2etc.). Any value Postgres can't parse as a timestamp makes the query itself fail, so the endpoint returns 500 Internal Server Error for what is a malformed client input:MinersService.resolveSinceonly substitutes the default window whensinceis falsy — a present-but-garbage value is forwarded untouched. On the/issuesGET path the controller forwardssince ?? null, so even an emptysince=binds""and fails the cast.This is inconsistent with the rest of the API: the POST variants of these same endpoints (
parseSinceByRepo) and the dashboard controller both validate timestamps and return 400 with a clear message. It also matters for consumers: 5xx is conventionally retryable, so a client with a badsincewill retry a request that can never succeed instead of surfacing its own bug.Fix
Add
parseSinceQuery()in the controller, applied to both GET endpoints:since→undefined, preserving existing defaults (resolveSincewindow on/pulls, open-issue-loadnullmode on/issues);toISOString()(same normalization asparseSinceByRepoand the dashboard controller), otherwise →BadRequestException("sincemust be a valid ISO timestamp").No service or SQL changes.
Tests
New
miners.controller.spec.ts(unit, mockedMinersService):sinceon/pullsand/issues→BadRequestException, service never called;sincenormalized to full ISO before reaching the service;since→ default window on/pulls,nullon/issues;since=on/issues→ treated as omitted (null) instead of binding"".Written red-first against the current
testtip: 5 of 7 cases fail before the fix, all pass after.Local checks
npm test— 32 passed (4 suites)npm run lint— cleannpm run format:check— cleannpm run build— clean