@@ -234,35 +234,28 @@ describe("bucketHostname", () => {
234
234
} ) ;
235
235
} ) ;
236
236
237
- describe ( "allows different client region with same signing scope" , ( ) => {
238
- [ "s3-external-1" , "s3" ] . forEach ( ( clientRegion ) => {
239
- const baseHostname = `${ clientRegion } .amazonaws.com` ;
240
- it ( `should use client region from base hostname ${ baseHostname } ` , ( ) => {
241
- const { bucketEndpoint, hostname } = bucketHostname ( {
242
- bucketName : parseArn ( "arn:aws:s3:us-east-1:123456789012:accesspoint:myendpoint" ) ,
243
- baseHostname,
244
- isCustomEndpoint : false ,
245
- clientRegion : region ,
246
- clientSigningRegion : "us-east-1" ,
247
- } ) ;
248
- expect ( bucketEndpoint ) . toBe ( true ) ;
249
- expect ( hostname ) . toBe ( `myendpoint-123456789012.s3-accesspoint.${ clientRegion } .amazonaws.com` ) ;
250
- } ) ;
251
- } ) ;
252
-
253
- [ "s3-external-1" , "s3" ] . forEach ( ( clientRegion ) => {
254
- const baseHostname = `${ clientRegion } .amazonaws.com` ;
255
- it ( `should use ARN region with base hostname ${ baseHostname } ` , ( ) => {
256
- const { bucketEndpoint, hostname } = bucketHostname ( {
257
- bucketName : parseArn ( "arn:aws:s3:us-east-1:123456789012:accesspoint:myendpoint" ) ,
258
- baseHostname,
259
- isCustomEndpoint : false ,
260
- clientRegion : region ,
261
- clientSigningRegion : "us-east-1" ,
262
- useArnRegion : true ,
263
- } ) ;
264
- expect ( bucketEndpoint ) . toBe ( true ) ;
265
- expect ( hostname ) . toBe ( "myendpoint-123456789012.s3-accesspoint.us-east-1.amazonaws.com" ) ;
237
+ describe ( "validate client region" , ( ) => {
238
+ [
239
+ { baseHostname : "s3.amazonaws.com" , region : "aws-global" , signingRegion : "us-east-1" } ,
240
+ {
241
+ baseHostname : "s3-external-1.amazonaws.com" ,
242
+ region : "s3-external-1" ,
243
+ signingRegion : "us-east-1" ,
244
+ } ,
245
+ ] . forEach ( ( { baseHostname, region, signingRegion } ) => {
246
+ it ( `should throw if supplied with global region ${ region } ` , ( ) => {
247
+ try {
248
+ bucketHostname ( {
249
+ bucketName : parseArn ( "arn:aws:s3:us-east-1:123456789012:accesspoint:myendpoint" ) ,
250
+ baseHostname,
251
+ isCustomEndpoint : false ,
252
+ clientRegion : region ,
253
+ clientSigningRegion : signingRegion ,
254
+ } ) ;
255
+ fail ( "function should have thrown" ) ;
256
+ } catch ( e ) {
257
+ expect ( e ) . toBeDefined ( ) ;
258
+ }
266
259
} ) ;
267
260
} ) ;
268
261
} ) ;
@@ -333,43 +326,75 @@ describe("bucketHostname", () => {
333
326
334
327
describe ( "allows fips client region" , ( ) => {
335
328
const bucketArn = parseArn ( "arn:aws-us-gov:s3:us-gov-east-1:123456789012:accesspoint:myendpoint" ) ;
329
+ const clientRegion = "fips-us-gov-east-1" ;
330
+ const clientPartition = "aws-us-gov" ;
336
331
it ( "should use client region" , ( ) => {
337
332
const { bucketEndpoint, hostname } = bucketHostname ( {
338
333
bucketName : bucketArn ,
339
- baseHostname : " s3.fips-us-gov-east-1 .amazonaws.com" ,
334
+ baseHostname : ` s3.${ clientRegion } .amazonaws.com` ,
340
335
isCustomEndpoint : false ,
341
- clientRegion : "us-gov-east-1" ,
342
- clientPartition : "aws-us-gov" ,
336
+ clientRegion,
337
+ clientPartition,
343
338
} ) ;
344
339
expect ( bucketEndpoint ) . toBe ( true ) ;
345
- expect ( hostname ) . toBe ( "myendpoint-123456789012.s3-accesspoint.fips- us-gov-east-1.amazonaws.com" ) ;
340
+ expect ( hostname ) . toBe ( "myendpoint-123456789012.s3-accesspoint-fips. us-gov-east-1.amazonaws.com" ) ;
346
341
} ) ;
347
342
348
343
it ( "should use ARN region" , ( ) => {
349
344
const { bucketEndpoint, hostname } = bucketHostname ( {
350
345
bucketName : bucketArn ,
351
- baseHostname : " s3.fips-us-gov-east-1 .amazonaws.com" ,
346
+ baseHostname : ` s3.${ clientRegion } .amazonaws.com` ,
352
347
isCustomEndpoint : false ,
353
- clientRegion : "us-gov-east-1" ,
354
- clientPartition : "aws-us-gov" ,
348
+ clientRegion,
349
+ clientPartition,
355
350
useArnRegion : true ,
356
351
} ) ;
357
352
expect ( bucketEndpoint ) . toBe ( true ) ;
358
- expect ( hostname ) . toBe ( "myendpoint-123456789012.s3-accesspoint.us-gov-east-1.amazonaws.com" ) ;
353
+ expect ( hostname ) . toBe ( "myendpoint-123456789012.s3-accesspoint-fips .us-gov-east-1.amazonaws.com" ) ;
359
354
} ) ;
360
355
361
356
it ( "should allow dualstack" , ( ) => {
362
357
const { bucketEndpoint, hostname } = bucketHostname ( {
363
358
bucketName : bucketArn ,
364
- baseHostname : " s3.fips-us-gov-east-1 .amazonaws.com" ,
359
+ baseHostname : ` s3.${ clientRegion } .amazonaws.com` ,
365
360
isCustomEndpoint : false ,
366
- clientRegion : "us-gov-east-1" ,
367
- clientPartition : "aws-us-gov" ,
361
+ clientRegion,
362
+ clientPartition,
368
363
useArnRegion : true ,
369
364
dualstackEndpoint : true ,
370
365
} ) ;
371
366
expect ( bucketEndpoint ) . toBe ( true ) ;
372
- expect ( hostname ) . toBe ( "myendpoint-123456789012.s3-accesspoint.dualstack.us-gov-east-1.amazonaws.com" ) ;
367
+ expect ( hostname ) . toBe ( "myendpoint-123456789012.s3-accesspoint-fips.dualstack.us-gov-east-1.amazonaws.com" ) ;
368
+ } ) ;
369
+ } ) ;
370
+
371
+ describe ( "validates FIPS client region matching ARN region" , ( ) => {
372
+ const bucketArn = parseArn ( "arn:aws-us-gov:s3:us-gov-west-1:123456789012:accesspoint:myendpoint" ) ;
373
+ const clientRegion = "fips-us-gov-east-1" ;
374
+ const clientPartition = "aws-us-gov" ;
375
+ it ( "should throw client region doesn't match arn region" , ( ) => {
376
+ expect ( ( ) =>
377
+ bucketHostname ( {
378
+ bucketName : bucketArn ,
379
+ baseHostname : `s3.${ clientRegion } .amazonaws.com` ,
380
+ isCustomEndpoint : false ,
381
+ clientRegion,
382
+ clientPartition,
383
+ } )
384
+ ) . toThrowError ( ) ;
385
+ } ) ;
386
+
387
+ it ( "should throw client region doesn't match arn region and uses ARN region" , ( ) => {
388
+ expect ( ( ) =>
389
+ bucketHostname ( {
390
+ bucketName : bucketArn ,
391
+ baseHostname : `s3.${ clientRegion } .amazonaws.com` ,
392
+ isCustomEndpoint : false ,
393
+ clientRegion,
394
+ clientPartition,
395
+ useArnRegion : true ,
396
+ } )
397
+ ) . toThrowError ( ) ;
373
398
} ) ;
374
399
} ) ;
375
400
@@ -554,33 +579,35 @@ describe("bucketHostname", () => {
554
579
} ) . toThrow ( `Partition in ARN is incompatible, got "aws-cn" but expected "aws"` ) ;
555
580
} ) ;
556
581
557
- describe ( "not supports fips region" , ( ) => {
558
- it ( "should throw if client region is fips" , ( ) => {
582
+ describe ( "fips region" , ( ) => {
583
+ it ( "should throw if client is using fips region" , ( ) => {
584
+ const clientRegion = "fips-us-gov-east-1" ;
585
+ const clientPartition = "aws-us-gov" ;
559
586
expect . assertions ( 2 ) ;
560
587
expect ( ( ) => {
561
588
bucketHostname ( {
562
589
bucketName : parseArn (
563
590
"arn:aws-us-gov:s3-outposts:us-gov-east-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint"
564
591
) ,
565
- baseHostname : " s3.fips-us-gov-east-1 .amazonaws.com" ,
592
+ baseHostname : ` s3.${ clientRegion } .amazonaws.com` ,
566
593
isCustomEndpoint : false ,
567
- clientRegion : "us-gov-east-1" ,
568
- clientPartition : "aws-us-gov" ,
594
+ clientRegion,
595
+ clientPartition,
569
596
} ) ;
570
- } ) . toThrow ( "FIPS region is not supported with Outpost, got fips-us-gov-east-1 " ) ;
597
+ } ) . toThrow ( "FIPS region is not supported" ) ;
571
598
572
599
expect ( ( ) => {
573
600
bucketHostname ( {
574
601
bucketName : parseArn (
575
602
"arn:aws-us-gov:s3-outposts:fips-us-gov-east-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint"
576
603
) ,
577
- baseHostname : " s3.fips-us-gov-east-1 .amazonaws.com" ,
604
+ baseHostname : ` s3.${ clientRegion } .amazonaws.com` ,
578
605
isCustomEndpoint : false ,
579
- clientRegion : "us-gov-east-1" ,
580
- clientPartition : "aws-us-gov" ,
606
+ clientRegion,
607
+ clientPartition,
581
608
useArnRegion : true ,
582
609
} ) ;
583
- } ) . toThrow ( "Endpoint does not support FIPS region " ) ;
610
+ } ) . toThrow ( "FIPS region is not supported " ) ;
584
611
} ) ;
585
612
586
613
it ( "should allow if region is not fips" , ( ) => {
@@ -778,7 +805,13 @@ describe("bucketHostname", () => {
778
805
779
806
describe ( "object lambda general test cases" , ( ) => {
780
807
it ( "should match expectations in valid configurations" , ( ) => {
781
- const validLambdaExpectations : [ string , string , boolean , string ] [ ] = [
808
+ const validLambdaExpectations : [
809
+ arn : string ,
810
+ clientRegion : string ,
811
+ useArnRegion : boolean ,
812
+ expectedEndpoint : string ,
813
+ clientPartition ?: string
814
+ ] [ ] = [
782
815
[
783
816
"arn:aws:s3-object-lambda:us-west-2:1123456789012:accesspoint/mybanner" ,
784
817
"us-west-2" ,
@@ -798,37 +831,42 @@ describe("bucketHostname", () => {
798
831
"mybanner-3123456789012.s3-object-lambda.us-east-1.amazonaws.com" ,
799
832
] ,
800
833
[
801
- "arn:aws:s3-object-lambda:us-east-1:4123456789012:accesspoint/mybanner" ,
802
- "s3-external-1" ,
803
- true ,
804
- "mybanner-4123456789012.s3-object-lambda.us-east-1.amazonaws.com" ,
834
+ "arn:aws-us-gov:s3-object-lambda:us-gov-east-1:123456789012:accesspoint/mybanner" ,
835
+ "fips-us-gov-east-1" ,
836
+ false ,
837
+ "mybanner-123456789012.s3-object-lambda-fips.us-gov-east-1.amazonaws.com" ,
838
+ "aws-us-gov" ,
805
839
] ,
806
840
[
807
- "arn:aws:s3-object-lambda:us-east-1:5123456789012 :accesspoint/mybanner" ,
808
- "aws-global " ,
841
+ "arn:aws-us-gov :s3-object-lambda:us-gov- east-1:123456789012 :accesspoint/mybanner" ,
842
+ "fips-us-gov-east-1 " ,
809
843
true ,
810
- "mybanner-5123456789012.s3-object-lambda.us-east-1.amazonaws.com" ,
844
+ "mybanner-123456789012.s3-object-lambda-fips.us-gov-east-1.amazonaws.com" ,
845
+ "aws-us-gov" ,
811
846
] ,
812
847
] ;
813
- validLambdaExpectations . forEach ( ( lambdaArn ) => {
814
- const arn = lambdaArn [ 0 ] ;
815
- const region = lambdaArn [ 1 ] ;
816
- const useArnRegion = lambdaArn [ 2 ] ;
817
- const exoectedEndpoint = lambdaArn [ 3 ] ;
848
+ validLambdaExpectations . forEach ( ( [ arn , clientRegion , useArnRegion , expectedEndpoint , clientPartition ] ) => {
818
849
const { bucketEndpoint, hostname } = bucketHostname ( {
819
850
bucketName : parseArn ( arn ) ,
820
851
baseHostname : `s3.${ region } .amazonaws.com` ,
821
852
isCustomEndpoint : false ,
822
- clientRegion : region ,
823
- useArnRegion : useArnRegion ,
853
+ clientRegion,
854
+ useArnRegion,
855
+ clientPartition,
824
856
} ) ;
825
857
expect ( bucketEndpoint ) . toBe ( true ) ;
826
- expect ( hostname ) . toBe ( exoectedEndpoint ) ;
858
+ expect ( hostname ) . toBe ( expectedEndpoint ) ;
827
859
} ) ;
828
860
} ) ;
829
861
830
862
it ( "should match not work with invalid configurations" , ( ) => {
831
- const invalidLambdaConfigurations : [ string , string , boolean , string ] [ ] = [
863
+ const invalidLambdaConfigurations : [
864
+ arn : string ,
865
+ clientRegion : string ,
866
+ useArnRegion : boolean ,
867
+ expectedError : string ,
868
+ clientPartition ?: string
869
+ ] [ ] = [
832
870
[
833
871
"arn:aws:s3-object-lambda:us-east-1:123456789012:accesspoint/mybanner" ,
834
872
"us-west-2" ,
@@ -895,22 +933,46 @@ describe("bucketHostname", () => {
895
933
false ,
896
934
"Invalid ARN, Access Point ARN contains sub resources" ,
897
935
] ,
936
+ [
937
+ "arn:aws:s3-object-lambda:us-east-1:4123456789012:accesspoint/mybanner" ,
938
+ "s3-external-1" ,
939
+ false ,
940
+ "Client region s3-external-1 is not regional" ,
941
+ ] ,
942
+ [
943
+ "arn:aws:s3-object-lambda:us-east-1:5123456789012:accesspoint/mybanner" ,
944
+ "aws-global" ,
945
+ false ,
946
+ "Client region aws-global is not regional" ,
947
+ ] ,
948
+ [
949
+ "arn:aws-us-gov:s3-object-lambda:us-gov-west-1:123456789012:accesspoint/mybanner" ,
950
+ "fips-us-gov-east-1" ,
951
+ false ,
952
+ "Client FIPS region fips-us-gov-east-1 doesn't match region us-gov-west-1 in ARN" ,
953
+ "aws-us-gov" ,
954
+ ] ,
955
+ [
956
+ "arn:aws-us-gov:s3-object-lambda:us-gov-west-1:123456789012:accesspoint/mybanner" ,
957
+ "fips-us-gov-east-1" ,
958
+ true ,
959
+ "Client FIPS region fips-us-gov-east-1 doesn't match region us-gov-west-1 in ARN" ,
960
+ "aws-us-gov" ,
961
+ ] ,
898
962
] ;
899
963
900
- invalidLambdaConfigurations . forEach ( ( lambdaArn ) => {
901
- const arn = lambdaArn [ 0 ] ;
902
- const region = lambdaArn [ 1 ] ;
903
- const useArnRegion = lambdaArn [ 2 ] ;
964
+ invalidLambdaConfigurations . forEach ( ( [ arn , clientRegion , useArnRegion , expectedError , clientPartition ] ) => {
904
965
try {
905
966
bucketHostname ( {
906
967
bucketName : parseArn ( arn ) ,
907
- baseHostname : " s3.us-west-2 .amazonaws.com" ,
968
+ baseHostname : ` s3.${ region } .amazonaws.com` ,
908
969
isCustomEndpoint : false ,
909
- clientRegion : region ,
910
- useArnRegion : useArnRegion ,
970
+ useArnRegion,
971
+ clientRegion,
972
+ clientPartition,
911
973
} ) ;
912
974
// should never get here
913
- expect . assertions ( 1 ) ;
975
+ fail ( ) ;
914
976
} catch ( e ) {
915
977
// should throw since these are error cases
916
978
expect ( 1 ) . toEqual ( 1 ) ;
0 commit comments