Skip to content

Commit

Permalink
fix(backend/auth): robustesse aux utilisateurs non présents dans la t…
Browse files Browse the repository at this point in the history
…able utilisateurSupportTable
  • Loading branch information
dthib committed Jan 8, 2025
1 parent 47a3d11 commit 389d414
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend/src/auth/authorizations/roles/role.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class RoleService {
.select()
.from(utilisateurSupportTable)
.where(eq(utilisateurSupportTable.userId, userId));
return result[0].support || false;
return (result.length && result[0]?.support) || false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,14 @@ describe('Calcul de trajectoire SNBC', () => {
});
}, 10000);

it(`Calcul sans droit suffisant (uniquement lecture)`, () => {
it(`Calcul sans droit suffisant - visite`, () => {
return request(app.getHttpServer())
.get('/trajectoires/snbc?collectiviteId=3895')
.get('/trajectoires/snbc?collectiviteId=3896')
.set('Authorization', `Bearer ${yoloDodoToken}`)
.expect(401)
.expect({
message:
"Droits insuffisants, l'utilisateur 17440546-f389-4d4f-bfdb-b0c94a1bd0f9 n'a pas l'autorisation indicateurs.trajectoires.edition sur la ressource Collectivité 3895",
"Droits insuffisants, l'utilisateur 17440546-f389-4d4f-bfdb-b0c94a1bd0f9 n'a pas l'autorisation indicateurs.trajectoires.lecture sur la ressource Collectivité 3896",
error: 'Unauthorized',
statusCode: 401,
});
Expand Down

0 comments on commit 389d414

Please sign in to comment.