@@ -13,6 +13,7 @@ describe("AuthHelper for Cognito", () => {
13
13
const region = "us-west-2" ;
14
14
const cognitoIdentityPoolId = `${ region } :TEST-IDENTITY-POOL-ID` ;
15
15
const url = "https://maps.geo.us-west-2.amazonaws.com/" ;
16
+ const govCloudUrl = "https://maps.geo-fips.us-gov-west-1.amazonaws.com/" ;
16
17
const nonAWSUrl = "https://example.com/" ;
17
18
const nonLocationAWSUrl = "https://my.cool.service.us-west-2.amazonaws.com/" ;
18
19
const mockedCredentials = {
@@ -163,6 +164,35 @@ describe("AuthHelper for Cognito", () => {
163
164
expect ( credential ) . toContain ( mockedCredentials . accessKeyId ) ;
164
165
} ) ;
165
166
167
+ it ( "getMapAuthenticationOptions should contain transformRequest function to sign the AWS GovCloud Urls using our custom signer" , async ( ) => {
168
+ const authHelper = await withIdentityPoolId ( cognitoIdentityPoolId ) ;
169
+ const transformRequest = authHelper . getMapAuthenticationOptions ( ) . transformRequest ;
170
+ const originalUrl = new URL ( govCloudUrl ) ;
171
+ const signedUrl = new URL ( transformRequest ( govCloudUrl ) . url ) ;
172
+
173
+ // Host and pathname should still be the same
174
+ expect ( signedUrl . hostname ) . toStrictEqual ( originalUrl . hostname ) ;
175
+ expect ( signedUrl . pathname ) . toStrictEqual ( originalUrl . pathname ) ;
176
+
177
+ const searchParams = signedUrl . searchParams ;
178
+ expect ( searchParams . size ) . toStrictEqual ( 6 ) ;
179
+
180
+ // Verify these search params exist on the signed url
181
+ // We don't need to test the actual values since they are non-deterministic or constants
182
+ const expectedSearchParams = [ "X-Amz-Algorithm" , "X-Amz-Date" , "X-Amz-SignedHeaders" , "X-Amz-Signature" ] ;
183
+ expectedSearchParams . forEach ( ( value ) => {
184
+ expect ( searchParams . has ( value ) ) . toStrictEqual ( true ) ;
185
+ } ) ;
186
+
187
+ // We can expect the session token to match exactly as passed in
188
+ const securityToken = searchParams . get ( "X-Amz-Security-Token" ) ;
189
+ expect ( securityToken ) . toStrictEqual ( mockedCredentials . sessionToken ) ;
190
+
191
+ // The credential starts with our access key, the rest is generated
192
+ const credential = searchParams . get ( "X-Amz-Credential" ) ;
193
+ expect ( credential ) . toContain ( mockedCredentials . accessKeyId ) ;
194
+ } ) ;
195
+
166
196
it ( "getMapAuthenticationOptions transformRequest function should pass-through non AWS Urls unchanged" , async ( ) => {
167
197
const authHelper = await withIdentityPoolId ( cognitoIdentityPoolId ) ;
168
198
const transformRequest = authHelper . getMapAuthenticationOptions ( ) . transformRequest ;
0 commit comments