@@ -11,42 +11,28 @@ test.afterEach.always('reset instances and prototypes', () => {
11
11
12
12
test ( 'server method – authentication supports mode: "optional" - will succeed without auth' , async ( t ) => {
13
13
const server = await helpers . getServer ( cfg )
14
-
15
14
const res = await server . inject ( {
16
15
method : 'GET' ,
17
- url : '/mode-optional' ,
16
+ url : '/mode-optional'
18
17
} )
19
18
20
19
t . truthy ( res )
21
20
t . is ( res . statusCode , 200 )
22
21
} )
23
22
24
23
test ( 'server method – authentication supports mode: "optional" - will fail with invalid auth' , async ( t ) => {
24
+ const mockReq = helpers . mockRequest ( fixtures . common . token , '/mode-optional' )
25
25
const server = await helpers . getServer ( cfg )
26
-
27
- const res = await server . inject ( {
28
- method : 'GET' ,
29
- url : '/mode-optional' ,
30
- headers : {
31
- authorization : `bearer invalid-token`
32
- }
33
- } )
26
+ const res = await server . inject ( mockReq )
34
27
35
28
t . truthy ( res )
36
29
t . is ( res . statusCode , 401 )
37
- t . is ( err . output . headers [ 'WWW-Authenticate' ] , 'Bearer strategy="keycloak-jwt", error="Invalid credentials"' )
38
30
} )
39
31
40
32
test ( 'server method – authentication supports mode: "try" - will succeed with invalid auth' , async ( t ) => {
33
+ const mockReq = helpers . mockRequest ( fixtures . common . token , '/mode-try' )
41
34
const server = await helpers . getServer ( cfg )
42
-
43
- const res = await server . inject ( {
44
- method : 'GET' ,
45
- url : '/mode-try' ,
46
- headers : {
47
- authorization : `bearer ${ fixtures . composeJwt ( 'expired' ) } `
48
- }
49
- } )
35
+ const res = await server . inject ( mockReq )
50
36
51
37
t . truthy ( res )
52
38
t . is ( res . statusCode , 200 )
0 commit comments