refactor(user-tokens): migrate from server - #2279
Conversation
a9a75b7 to
64a5234
Compare
b37e308 to
0331d48
Compare
0331d48 to
c53cb23
Compare
09f3402 to
b667443
Compare
1b31261 to
f16a730
Compare
cecad1b to
10b4770
Compare
|
🤖 Hey ! The security scan report for the current pull request is available here. |
0eb3e93 to
43d21dc
Compare
|
🤖 Hey ! The security scan report for the current pull request is available here. |
792f711 to
1740e91
Compare
|
🤖 Hey ! The security scan report for the current pull request is available here. |
|
🤖 Hey ! The security scan report for the current pull request is available here. |
|
Je tente un truc |
|
🤖 Hey ! The security scan report for the current pull request is available here. |
2 similar comments
|
🤖 Hey ! The security scan report for the current pull request is available here. |
|
🤖 Hey ! The security scan report for the current pull request is available here. |
|
🤖 Hey ! The security scan report for the current pull request is available here. |
4 similar comments
|
🤖 Hey ! The security scan report for the current pull request is available here. |
|
🤖 Hey ! The security scan report for the current pull request is available here. |
|
🤖 Hey ! The security scan report for the current pull request is available here. |
|
🤖 Hey ! The security scan report for the current pull request is available here. |
|
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 B1 — BLOCKER B2 — date parsing path ( WARNINGS
NITS
Good: token hash never selected/exposed, authz parity preserved, tests are meaningful (25/25). |
|
🤖 Hey ! The security scan report for the current pull request is available here. |
shikanime
left a comment
There was a problem hiding this comment.
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.ts — z.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 noHUMAN_KINDconstant; literal'human'matches the Prisma enum and existing usage. No change needed.withRevoked="chocapics"—ZodValidationPipe+CoerceBooleanSchemarejects non-boolean with 400. Already mitigated.
Compliance checklist
- Conventional title
- Authz preserved: admin routes use
RequireAdminPermission; user routesUserGuard+RequireUserType('human')— mirrors FastifyAdminAuthorized/ProjectAuthorized - No secret leakage:
hashomitted from all selects/responses - Tests present (service specs + crypto specs + gated e2e)
- Remove dead
verifyTokenHashexport 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.
|
🤖 Hey ! The security scan report for the current pull request is available here. |
2 similar comments
|
🤖 Hey ! The security scan report for the current pull request is available here. |
|
🤖 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>
|
🤖 Hey ! The security scan report for the current pull request is available here. |

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