1
1
import { generateKeyPair } from 'node:crypto' ;
2
2
import { WebTokenAuthenticator } from '../../src/auth/webtoken-authenticator.js' ;
3
- import { withOauthContainer } from './oauth-authenticator. test.js' ;
3
+ import { withOauthContainer } from './oauth-authenticator- test.js' ;
4
4
5
5
describe ( 'WebTokenAuthenticatorTest' , ( ) => {
6
- withOauthContainer ( ( oauthHost : string ) => {
7
- const getPrivateKey = ( ) : Promise < string > => {
8
- return new Promise ( ( resolve , reject ) => {
9
- generateKeyPair (
10
- 'rsa' ,
11
- {
12
- modulusLength : 2048 ,
13
- publicKeyEncoding : { type : 'spki' , format : 'pem' } ,
14
- privateKeyEncoding : { type : 'pkcs8' , format : 'pem' } ,
15
- } ,
16
- ( err , publicKey , privKey ) => {
17
- if ( err ) {
18
- return reject ( err ) ;
19
- }
20
- resolve ( privKey ) ;
21
- } ,
22
- ) ;
23
- } ) ;
24
- } ;
6
+ const getPrivateKey = ( ) : Promise < string > => {
7
+ return new Promise ( ( resolve , reject ) => {
8
+ generateKeyPair (
9
+ 'rsa' ,
10
+ {
11
+ modulusLength : 2048 ,
12
+ publicKeyEncoding : { type : 'spki' , format : 'pem' } ,
13
+ privateKeyEncoding : { type : 'pkcs8' , format : 'pem' } ,
14
+ } ,
15
+ ( err , publicKey , privKey ) => {
16
+ if ( err ) {
17
+ return reject ( err ) ;
18
+ }
19
+ resolve ( privKey ) ;
20
+ } ,
21
+ ) ;
22
+ } ) ;
23
+ } ;
25
24
25
+ withOauthContainer ( ( getOauthHost ) => {
26
26
test ( 'testRefreshToken' , async ( ) => {
27
+ const oauthHost = getOauthHost ( ) ;
27
28
const authenticator = await WebTokenAuthenticator . builder (
28
29
oauthHost ,
29
30
'1' ,
@@ -35,7 +36,6 @@ describe('WebTokenAuthenticatorTest', () => {
35
36
expect ( await authenticator . getAuthToken ( ) ) . not . toBeFalsy ( ) ;
36
37
const token = await authenticator . refreshToken ( ) ;
37
38
expect ( token . access_token ) . not . toBeFalsy ( ) ;
38
- const expiresIn = token . expires_in ?? 0 ;
39
39
expect ( token . expires_in && token . expires_in > 0 ) . toBe ( true ) ;
40
40
expect ( token . access_token ) . toBe ( await authenticator . getAuthToken ( ) ) ;
41
41
expect ( authenticator . getHost ( ) . toString ( ) ) . toBe ( oauthHost + '/' ) ;
@@ -45,6 +45,7 @@ describe('WebTokenAuthenticatorTest', () => {
45
45
} , 30000 ) ;
46
46
47
47
test ( 'testRefreshTokenWithRS256' , async ( ) => {
48
+ const oauthHost = getOauthHost ( ) ;
48
49
const authenticator = await WebTokenAuthenticator . builder (
49
50
oauthHost ,
50
51
'1' ,
@@ -65,6 +66,7 @@ describe('WebTokenAuthenticatorTest', () => {
65
66
} , 30000 ) ;
66
67
67
68
test ( 'testRefreshTokenWithExtendedLifetime' , async ( ) => {
69
+ const oauthHost = getOauthHost ( ) ;
68
70
const authenticator = await WebTokenAuthenticator . builder (
69
71
oauthHost ,
70
72
'1' ,
0 commit comments