Skip to content

refactor(user-tokens): migrate from server - #2279

Draft
shikanime wants to merge 5 commits into
mainfrom
shikanime/push-uotmotuknkvy
Draft

refactor(user-tokens): migrate from server#2279
shikanime wants to merge 5 commits into
mainfrom
shikanime/push-uotmotuknkvy

Conversation

@shikanime

Copy link
Copy Markdown
Member

Issues liées

Issues numéro: #1889


Quel est le comportement actuel ?

Quel est le nouveau comportement ?

Cette PR introduit-elle un breaking change ?

Autres informations

Comment thread apps/server-nestjs/src/modules/admin-token/admin-token.service.ts Fixed
Comment thread apps/server-nestjs/src/modules/user-tokens/user-tokens.service.ts Fixed
@shikanime
shikanime force-pushed the shikanime/push-uotmotuknkvy branch from a9a75b7 to 64a5234 Compare June 30, 2026 10:02
Comment thread apps/server-nestjs/src/modules/admin-token/admin-token.service.ts Fixed
Comment thread apps/server-nestjs/src/modules/user-tokens/user-tokens.service.ts Fixed
Comment thread apps/server-nestjs/test/admin-token.e2e-spec.ts Fixed
Comment thread apps/server-nestjs/test/user-tokens.e2e-spec.ts Dismissed
@shikanime
shikanime force-pushed the shikanime/push-uotmotuknkvy branch 10 times, most recently from b37e308 to 0331d48 Compare July 1, 2026 09:54
@shikanime
shikanime force-pushed the shikanime/push-uotmotuknkvy branch from 0331d48 to c53cb23 Compare July 1, 2026 10:19
Comment thread apps/server-nestjs/src/modules/gitlab/gitlab-client.service.ts Fixed
Comment thread apps/server-nestjs/src/modules/gitlab/gitlab.service.ts Fixed
@shikanime
shikanime force-pushed the shikanime/push-uotmotuknkvy branch 2 times, most recently from 09f3402 to b667443 Compare July 1, 2026 11:29
@shikanime
shikanime force-pushed the shikanime/push-uotmotuknkvy branch 2 times, most recently from 1b31261 to f16a730 Compare July 1, 2026 12:00
@shikanime shikanime changed the title refactor(server-nestjs): migrate project hook refactor(user-tokens): migrate from server Jul 1, 2026
@shikanime
shikanime force-pushed the shikanime/push-uotmotuknkvy branch 4 times, most recently from cecad1b to 10b4770 Compare July 1, 2026 13:35
@github-actions github-actions Bot added the built label Jul 1, 2026
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

@shikanime
shikanime force-pushed the shikanime/push-uotmotuknkvy branch 2 times, most recently from 0eb3e93 to 43d21dc Compare July 1, 2026 13:56
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

@shikanime
shikanime force-pushed the shikanime/push-uotmotuknkvy branch from 792f711 to 1740e91 Compare July 16, 2026 08:38
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

StephaneTrebel
StephaneTrebel previously approved these changes Jul 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

@StephaneTrebel

Copy link
Copy Markdown
Collaborator

Je tente un truc

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

2 similar comments
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

4 similar comments
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

@shikanime

Copy link
Copy Markdown
Member Author

Review: REQUEST CHANGES (posted as comment — GitHub does not allow the author to submit a formal review on their own PR).

Contract regressions in the token migration:

BLOCKER B1user-tokens.controller.ts:37 and admin-token.controller.ts:31: @Delete(':tokenId') uses bare @Param('tokenId') with no ParseUUIDPipe/zod pipe. Legacy contract enforced z.string().uuid() (400 on bad UUID); now a non-UUID id reaches Prisma → P2023 → unhandled 500. Fix: @Param('tokenId', ParseUUIDPipe) tokenId: string.

BLOCKER B2 — date parsing path (user-tokens.service.ts / admin-token.service.ts): z.coerce.date().parse() throws a raw ZodError (500) on bad input; legacy returned 400. Map ZodError → BadRequestException or route through ZodValidationPipe.

WARNINGS

  • Use the existing @RequireUserType('human') decorator instead of the hand-rolled userType !== 'human' checks (3×).
  • withRevoked === 'true' silently coerces invalid query values to false (legacy rejected them).

NITS

  • unused verifyTokenHash export; needless async on generateTokenPair; commit scope says user-tokens but half the diff is admin-token; confirm the strangler routing.conf is flipped to the NestJS route (or the new code is dead).

Good: token hash never selected/exposed, authz parity preserved, tests are meaningful (25/25).

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

@shikanime shikanime left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: #2279 — refactor(user-tokens): migrate from server

Verdict: REQUEST CHANGES (dead crypto export; strong authz parity + tests)

Findings

[blocker] apps/server-nestjs/src/utils/crypto.ts:46 verifyTokenHash is exported but never imported anywhere (verified: zero usages outside its own def + spec). Dead code in a security-sensitive file. Either wire it into the token-login validation path or drop it from this PR.

[warning] admin-token/admin-token.service.ts:58 BigInt(data.permissions)permissionLevelSchema is z.coerce.string(), so permissions is a string. BigInt("chocapics") throws a raw SyntaxError → 500, not a BadRequestException. Validate with z.coerce.bigint() or wrap in a typed parse. (Latent in the Fastify version too; you're rewriting, so fix it.)

[warning] admin-token.service.ts:39 / user-tokens.service.tsz.coerce.date().parse("toto") returns Invalid Date (not a ZodError), and isAtLeastTomorrow then yields a confusing "trop courte" message. Add explicit Number.isNaN(date.getTime())BadRequestException('Date d\'expiration invalide'). (Aligns with StephaneTrebel's still-open "la date peut aussi être invalide".)

[resolved/non-issue] Items from StephaneTrebel's review:

  • RequireUserType('human') — the repo has no HUMAN_KIND constant; literal 'human' matches the Prisma enum and existing usage. No change needed.
  • withRevoked="chocapics"ZodValidationPipe + CoerceBooleanSchema rejects non-boolean with 400. Already mitigated.

Compliance checklist

  • Conventional title
  • Authz preserved: admin routes use RequireAdminPermission; user routes UserGuard + RequireUserType('human') — mirrors Fastify AdminAuthorized / ProjectAuthorized
  • No secret leakage: hash omitted from all selects/responses
  • Tests present (service specs + crypto specs + gated e2e)
  • Remove dead verifyTokenHash export before merge

Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: Ib1b5cbbfcd8274912ed9ffb20d60cbed6a6a6964
- Export CoerceBooleanSchema from @cpn-console/shared schemas index so
  server-nestjs can import it (TS2305 broke the Docker build).
- Add apps/server-nestjs to sonar.javascript.lcov.reportPaths; the PR's
  new code was uncovered and failed the new-code coverage quality gate.

Co-Authored-By: Shikanime Deva <william.phetsinorath@shikanime.studio>
Move './_utils.js' before './config.js' to satisfy
perfectionist/sort-exports in the shared lint gate.

Co-Authored-By: Shikanime Deva <william.phetsinorath@shikanime.studio>
Cover the newly migrated admin-token and user-tokens data-access
functions (list/create/revoke, bot-user creation) with mockDeep-based
unit tests. Lifts new-code coverage for the SonarQube quality gate
alongside the build/runtime fixes already on this branch.
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

2 similar comments
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

The vitest coverage reporter was set to text/json/html but no lcov, so
`vitest --coverage` never wrote coverage/lcov.info. Sonar's reportPath for
server-nestjs then resolved to nothing and the PR's new code reported 0%
coverage, failing the quality gate. Match the sibling apps' ['text','lcov'].

Signed-off-by: William Phetsinorath <william.phetsinorath@shikanime.studio>
Co-Authored-By: Shikanime Deva <william.phetsinorath@shikanime.studio>
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

The security scan report for the current pull request is available here.

@cloud-pi-native-sonarqube

Copy link
Copy Markdown

Failed Quality Gate failed

  • 11 New Issues (is greater than 10)

Project ID: cloud-pi-native_console_AYsa46O31ebDtzs-pYyZ

View in SonarQube

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants