@@ -13,6 +13,7 @@ import {
1313} from "./secret.testdata.js" ;
1414import jwt from "jsonwebtoken" ;
1515import { allAppRoles , AppRoles } from "../../src/common/roles.js" ;
16+ import { beforeEach , describe } from "node:test" ;
1617
1718const ddbMock = mockClient ( SecretsManagerClient ) ;
1819
@@ -50,40 +51,46 @@ vi.stubEnv("JwtSigningKey", jwt_secret);
5051const testJwt = createJwt ( ) ;
5152const testJwtNoGroups = createJwtNoGroups ( ) ;
5253
53- test ( "Test happy path" , async ( ) => {
54- ddbMock . on ( GetSecretValueCommand ) . resolves ( {
55- SecretString : secretJson ,
54+ describe ( "Test authentication" , ( ) => {
55+ test ( "Test happy path" , async ( ) => {
56+ ddbMock . on ( GetSecretValueCommand ) . resolves ( {
57+ SecretString : secretJson ,
58+ } ) ;
59+ const response = await app . inject ( {
60+ method : "GET" ,
61+ url : "/api/v1/protected" ,
62+ headers : {
63+ authorization : `Bearer ${ testJwt } ` ,
64+ } ,
65+ } ) ;
66+ expect ( response . statusCode ) . toBe ( 200 ) ;
67+ const jsonBody = await response . json ( ) ;
68+ expect ( jsonBody ) . toEqual ( {
69+ 70+ roles : allAppRoles ,
71+ } ) ;
5672 } ) ;
57- const response = await app . inject ( {
58- method : "GET" ,
59- url : "/api/v1/protected" ,
60- headers : {
61- authorization : `Bearer ${ testJwt } ` ,
62- } ,
63- } ) ;
64- expect ( response . statusCode ) . toBe ( 200 ) ;
65- const jsonBody = await response . json ( ) ;
66- expect ( jsonBody ) . toEqual ( {
67- 68- roles : allAppRoles ,
69- } ) ;
70- } ) ;
7173
72- test ( "Test user-specific role grants" , async ( ) => {
73- ddbMock . on ( GetSecretValueCommand ) . resolves ( {
74- SecretString : secretJson ,
74+ test ( "Test user-specific role grants" , async ( ) => {
75+ ddbMock . on ( GetSecretValueCommand ) . resolves ( {
76+ SecretString : secretJson ,
77+ } ) ;
78+ const response = await app . inject ( {
79+ method : "GET" ,
80+ url : "/api/v1/protected" ,
81+ headers : {
82+ authorization : `Bearer ${ testJwtNoGroups } ` ,
83+ } ,
84+ } ) ;
85+ expect ( response . statusCode ) . toBe ( 200 ) ;
86+ const jsonBody = await response . json ( ) ;
87+ expect ( jsonBody ) . toEqual ( {
88+ 89+ roles : [ AppRoles . TICKETS_SCANNER ] ,
90+ } ) ;
7591 } ) ;
76- const response = await app . inject ( {
77- method : "GET" ,
78- url : "/api/v1/protected" ,
79- headers : {
80- authorization : `Bearer ${ testJwtNoGroups } ` ,
81- } ,
82- } ) ;
83- expect ( response . statusCode ) . toBe ( 200 ) ;
84- const jsonBody = await response . json ( ) ;
85- expect ( jsonBody ) . toEqual ( {
86- 87- roles : [ AppRoles . TICKETS_SCANNER ] ,
92+
93+ beforeEach ( ( ) => {
94+ ( app as any ) . nodeCache . flushAll ( ) ;
8895 } ) ;
8996} ) ;
0 commit comments