@@ -25,6 +25,7 @@ describe('private functions', () => {
25
25
userPoolAppId : '123456789qwertyuiop987abcd' ,
26
26
userPoolDomain : 'my-cognito-domain.auth.us-east-1.amazoncognito.com' ,
27
27
cookieExpirationDays : 365 ,
28
+ disableCookieDomain : false ,
28
29
logLevel : 'error' ,
29
30
} ) ;
30
31
} ) ;
@@ -97,6 +98,43 @@ describe('private functions', () => {
97
98
expect ( authenticator . _getVerifiedToken ) . toHaveBeenCalled ( ) ;
98
99
} ) ;
99
100
101
+ test ( 'should not return cookie domain' , ( ) => {
102
+ const authenticatorWithNoCookieDomain = new Authenticator ( {
103
+ region : 'us-east-1' ,
104
+ userPoolId : 'us-east-1_abcdef123' ,
105
+ userPoolAppId : '123456789qwertyuiop987abcd' ,
106
+ userPoolDomain : 'my-cognito-domain.auth.us-east-1.amazoncognito.com' ,
107
+ cookieExpirationDays : 365 ,
108
+ disableCookieDomain : true ,
109
+ logLevel : 'error' ,
110
+ } ) ;
111
+
112
+ const username = 'toto' ;
113
+ const domain = 'example.com' ;
114
+ const path = '/test' ;
115
+ jest . spyOn ( authenticatorWithNoCookieDomain , '_getVerifiedToken' ) ;
116
+ authenticatorWithNoCookieDomain . _getVerifiedToken . mockReturnValueOnce ( { token_use : 'id' , 'cognito:username' : username } ) ;
117
+
118
+ const response = authenticatorWithNoCookieDomain . _getRedirectResponse ( tokenData , domain , path ) ;
119
+ expect ( response ) . toMatchObject ( {
120
+ status : '302' ,
121
+ headers : {
122
+ location : [ {
123
+ key : 'Location' ,
124
+ value : path ,
125
+ } ] ,
126
+ } ,
127
+ } ) ;
128
+ expect ( response . headers [ 'set-cookie' ] ) . toEqual ( expect . arrayContaining ( [
129
+ { key : 'Set-Cookie' , value : `CognitoIdentityServiceProvider.123456789qwertyuiop987abcd.${ username } .accessToken=${ tokenData . access_token } ; Expires=${ DATE } ; Secure` } ,
130
+ { key : 'Set-Cookie' , value : `CognitoIdentityServiceProvider.123456789qwertyuiop987abcd.${ username } .refreshToken=${ tokenData . refresh_token } ; Expires=${ DATE } ; Secure` } ,
131
+ { key : 'Set-Cookie' , value : `CognitoIdentityServiceProvider.123456789qwertyuiop987abcd.${ username } .tokenScopesString=phone email profile openid aws.cognito.signin.user.admin; Expires=${ DATE } ; Secure` } ,
132
+ { key : 'Set-Cookie' , value : `CognitoIdentityServiceProvider.123456789qwertyuiop987abcd.${ username } .idToken=${ tokenData . id_token } ; Expires=${ DATE } ; Secure` } ,
133
+ { key : 'Set-Cookie' , value : `CognitoIdentityServiceProvider.123456789qwertyuiop987abcd.LastAuthUser=${ username } ; Expires=${ DATE } ; Secure` } ,
134
+ ] ) ) ;
135
+ expect ( authenticatorWithNoCookieDomain . _getVerifiedToken ) . toHaveBeenCalled ( ) ;
136
+ } ) ;
137
+
100
138
test ( 'should getIdTokenFromCookie' , ( ) => {
101
139
const appClientName = 'toto,./;;..-_lol123' ;
102
140
expect (
@@ -124,6 +162,7 @@ describe('createAuthenticator', () => {
124
162
userPoolAppId : '123456789qwertyuiop987abcd' ,
125
163
userPoolDomain : 'my-cognito-domain.auth.us-east-1.amazoncognito.com' ,
126
164
cookieExpirationDays : 365 ,
165
+ disableCookieDomain : true
127
166
} ;
128
167
} ) ;
129
168
@@ -136,6 +175,11 @@ describe('createAuthenticator', () => {
136
175
expect ( typeof new Authenticator ( params ) ) . toBe ( 'object' ) ;
137
176
} ) ;
138
177
178
+ test ( 'should create authenticator without disableCookieDomain' , ( ) => {
179
+ delete params . disableCookieDomain ;
180
+ expect ( typeof new Authenticator ( params ) ) . toBe ( 'object' ) ;
181
+ } ) ;
182
+
139
183
test ( 'should fail when creating authenticator without params' , ( ) => {
140
184
expect ( ( ) => new Authenticator ( ) ) . toThrow ( 'Expected params' ) ;
141
185
expect ( ( ) => new Authenticator ( ) ) . toThrow ( 'Expected params' ) ;
@@ -185,6 +229,11 @@ describe('createAuthenticator', () => {
185
229
params . cookieExpirationDays = '123' ;
186
230
expect ( ( ) => new Authenticator ( params ) ) . toThrow ( 'cookieExpirationDays' ) ;
187
231
} ) ;
232
+
233
+ test ( 'should fail when creating authenticator with invalid disableCookieDomain' , ( ) => {
234
+ params . disableCookieDomain = '123' ;
235
+ expect ( ( ) => new Authenticator ( params ) ) . toThrow ( 'disableCookieDomain' ) ;
236
+ } ) ;
188
237
} ) ;
189
238
190
239
describe ( 'handle' , ( ) => {
0 commit comments