Skip to content

Commit 31fbb75

Browse files
authored
chore: add fake credentials and regions to unit tests (#1513)
Some functional tests, unit tests and protocol tests constructs new clients in test suites. If these tests run in environment without any AWS configs, they will fail with region is missing or cannot resolve credentials. This change add fake regions and credentials to this test so SDK won't try to resolve them in the test. It enables the test:all script to be runnable on for example, a fresh EC2 instance
1 parent 797ba7d commit 31fbb75

File tree

9 files changed

+345
-8
lines changed

9 files changed

+345
-8
lines changed

clients/client-lex-runtime-service/LexRuntimeService.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ describe("@aws-sdk/client-lex-runtime-service", () => {
1313
expect(request.headers).to.have.property("x-amz-content-sha256", "UNSIGNED-PAYLOAD");
1414
return Promise.resolve({ output: {} as any, response: {} as any });
1515
};
16-
const client = new LexRuntimeService({});
16+
const client = new LexRuntimeService({
17+
region: "us-west-2",
18+
});
1719
client.middlewareStack.add(validator, {
1820
step: "serialize",
1921
name: "endpointValidator",

clients/client-mediastore-data/MidiaStoreData.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ describe("@aws-sdk/client-mediastore-data", () => {
1313
expect(request.headers).to.have.property("x-amz-content-sha256", "UNSIGNED-PAYLOAD");
1414
return Promise.resolve({ output: {} as any, response: {} as any });
1515
};
16-
const client = new MediaStoreData({});
16+
const client = new MediaStoreData({
17+
region: "us-west-2",
18+
});
1719
client.middlewareStack.add(validator, {
1820
step: "serialize",
1921
name: "endpointValidator",

clients/client-s3/S3.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ describe("Accesspoint ARN", async () => {
4747
};
4848

4949
it("should succeed with access point ARN", async () => {
50-
const client = new S3({});
51-
client.middlewareStack.add(endpointValidator, { step: "finalizeRequest", priority: "low" });
50+
const client = new S3({ region: "us-west-2" });
51+
client.middlewareStack.add(endpointValidator, { step: "build", priority: "low" });
5252
const result: any = await client.putObject({
5353
Bucket: "arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint",
5454
Key: "key",
@@ -58,7 +58,11 @@ describe("Accesspoint ARN", async () => {
5858
});
5959

6060
it("should sign request with region from ARN is useArnRegion is set", async () => {
61-
const client = new S3({ region: "us-east-1", useArnRegion: true });
61+
const client = new S3({
62+
region: "us-east-1",
63+
useArnRegion: true,
64+
credentials: { accessKeyId: "key", secretAccessKey: "secret" },
65+
});
6266
client.middlewareStack.add(endpointValidator, { step: "finalizeRequest", priority: "low" });
6367
const result: any = await client.putObject({
6468
Bucket: "arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint",

packages/s3-request-presigner/src/getSignedUrl.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ import { RequestPresigningArguments } from "@aws-sdk/types/src";
2626
import { getSignedUrl } from "./getSignedUrl";
2727

2828
describe("getSignedUrl", () => {
29+
const clientParams = { region: "us-foo-1" };
30+
2931
beforeEach(() => {
3032
mockPresign.mockReset();
3133
});
3234

3335
it("should call S3Presigner.sign", async () => {
3436
const mockPresigned = "a presigned url";
3537
mockPresign.mockReturnValue(mockPresigned);
36-
const client = new S3Client({});
38+
const client = new S3Client(clientParams);
3739
const command = new GetObjectCommand({
3840
Bucket: "Bucket",
3941
Key: "Key",
@@ -53,7 +55,7 @@ describe("getSignedUrl", () => {
5355
mockPresign.mockReturnValue(mockPresigned);
5456
const signingRegion = "aws-foo-1";
5557
const signingService = "bar";
56-
const client = new S3Client({});
58+
const client = new S3Client(clientParams);
5759
client.middlewareStack.addRelativeTo(
5860
(next: any, context: any) => (args: any) => {
5961
context["signing_region"] = signingRegion;
@@ -88,7 +90,7 @@ describe("getSignedUrl", () => {
8890
signableHeaders: new Set(["head-1", "head-2"]),
8991
unsignableHeaders: new Set(["head-3", "head-4"]),
9092
};
91-
const client = new S3Client({});
93+
const client = new S3Client(clientParams);
9294
const command = new GetObjectCommand({
9395
Bucket: "Bucket",
9496
Key: "Key",

protocol_tests/aws-ec2/tests/functional/ec2query.spec.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,17 @@ const equivalentContents = (expected: any, generated: any): boolean => {
140140
return true;
141141
};
142142

143+
const clientParams = {
144+
region: "us-west-2",
145+
credentials: { accessKeyId: "key", secretAccessKey: "secret" },
146+
};
147+
143148
/**
144149
* Empty input serializes no extra query params
145150
*/
146151
it("Ec2QueryEmptyInputAndEmptyOutput:Request", async () => {
147152
const client = new EC2ProtocolClient({
153+
...clientParams,
148154
requestHandler: new RequestSerializationTestHandler(),
149155
});
150156

@@ -178,6 +184,7 @@ it("Ec2QueryEmptyInputAndEmptyOutput:Request", async () => {
178184
*/
179185
it("Ec2QueryEmptyInputAndEmptyOutput:Response", async () => {
180186
const client = new EC2ProtocolClient({
187+
...clientParams,
181188
requestHandler: new ResponseDeserializationTestHandler(
182189
true,
183190
200,
@@ -209,6 +216,7 @@ it("Ec2QueryEmptyInputAndEmptyOutput:Response", async () => {
209216
*/
210217
it("Ec2GreetingWithErrors:Response", async () => {
211218
const client = new EC2ProtocolClient({
219+
...clientParams,
212220
requestHandler: new ResponseDeserializationTestHandler(
213221
true,
214222
200,
@@ -250,6 +258,7 @@ it("Ec2GreetingWithErrors:Response", async () => {
250258
*/
251259
it("Ec2InvalidGreetingError:Error:GreetingWithErrors", async () => {
252260
const client = new EC2ProtocolClient({
261+
...clientParams,
253262
requestHandler: new ResponseDeserializationTestHandler(
254263
false,
255264
400,
@@ -298,6 +307,7 @@ it("Ec2InvalidGreetingError:Error:GreetingWithErrors", async () => {
298307

299308
it("Ec2ComplexError:Error:GreetingWithErrors", async () => {
300309
const client = new EC2ProtocolClient({
310+
...clientParams,
301311
requestHandler: new ResponseDeserializationTestHandler(
302312
false,
303313
400,
@@ -357,6 +367,7 @@ it("Ec2ComplexError:Error:GreetingWithErrors", async () => {
357367
*/
358368
it("Ec2IgnoresWrappingXmlName:Response", async () => {
359369
const client = new EC2ProtocolClient({
370+
...clientParams,
360371
requestHandler: new ResponseDeserializationTestHandler(
361372
true,
362373
200,
@@ -398,6 +409,7 @@ it("Ec2IgnoresWrappingXmlName:Response", async () => {
398409
*/
399410
it("Ec2NestedStructures:Request", async () => {
400411
const client = new EC2ProtocolClient({
412+
...clientParams,
401413
requestHandler: new RequestSerializationTestHandler(),
402414
});
403415

@@ -444,6 +456,7 @@ it("Ec2NestedStructures:Request", async () => {
444456
*/
445457
it("Ec2QueryNoInputAndOutput:Request", async () => {
446458
const client = new EC2ProtocolClient({
459+
...clientParams,
447460
requestHandler: new RequestSerializationTestHandler(),
448461
});
449462

@@ -477,6 +490,7 @@ it("Ec2QueryNoInputAndOutput:Request", async () => {
477490
*/
478491
it("Ec2QueryNoInputAndOutput:Response", async () => {
479492
const client = new EC2ProtocolClient({
493+
...clientParams,
480494
requestHandler: new ResponseDeserializationTestHandler(
481495
true,
482496
200,
@@ -508,6 +522,7 @@ it("Ec2QueryNoInputAndOutput:Response", async () => {
508522
*/
509523
it("Ec2ProtocolIdempotencyTokenAutoFill:Request", async () => {
510524
const client = new EC2ProtocolClient({
525+
...clientParams,
511526
requestHandler: new RequestSerializationTestHandler(),
512527
});
513528

@@ -544,6 +559,7 @@ it("Ec2ProtocolIdempotencyTokenAutoFill:Request", async () => {
544559
*/
545560
it("Ec2ProtocolIdempotencyTokenAutoFillIsSet:Request", async () => {
546561
const client = new EC2ProtocolClient({
562+
...clientParams,
547563
requestHandler: new RequestSerializationTestHandler(),
548564
});
549565

@@ -580,6 +596,7 @@ it("Ec2ProtocolIdempotencyTokenAutoFillIsSet:Request", async () => {
580596
*/
581597
it("Ec2Lists:Request", async () => {
582598
const client = new EC2ProtocolClient({
599+
...clientParams,
583600
requestHandler: new RequestSerializationTestHandler(),
584601
});
585602

@@ -630,6 +647,7 @@ it("Ec2Lists:Request", async () => {
630647
*/
631648
it("Ec2EmptyQueryLists:Request", async () => {
632649
const client = new EC2ProtocolClient({
650+
...clientParams,
633651
requestHandler: new RequestSerializationTestHandler(),
634652
});
635653

@@ -665,6 +683,7 @@ it("Ec2EmptyQueryLists:Request", async () => {
665683
*/
666684
it("Ec2ListArgWithXmlNameMember:Request", async () => {
667685
const client = new EC2ProtocolClient({
686+
...clientParams,
668687
requestHandler: new RequestSerializationTestHandler(),
669688
});
670689

@@ -702,6 +721,7 @@ it("Ec2ListArgWithXmlNameMember:Request", async () => {
702721
*/
703722
it("Ec2ListMemberWithXmlName:Request", async () => {
704723
const client = new EC2ProtocolClient({
724+
...clientParams,
705725
requestHandler: new RequestSerializationTestHandler(),
706726
});
707727

@@ -739,6 +759,7 @@ it("Ec2ListMemberWithXmlName:Request", async () => {
739759
*/
740760
it("Ec2TimestampsInput:Request", async () => {
741761
const client = new EC2ProtocolClient({
762+
...clientParams,
742763
requestHandler: new RequestSerializationTestHandler(),
743764
});
744765

@@ -781,6 +802,7 @@ it("Ec2TimestampsInput:Request", async () => {
781802
*/
782803
it("Ec2RecursiveShapes:Response", async () => {
783804
const client = new EC2ProtocolClient({
805+
...clientParams,
784806
requestHandler: new ResponseDeserializationTestHandler(
785807
true,
786808
200,
@@ -847,6 +869,7 @@ it("Ec2RecursiveShapes:Response", async () => {
847869
*/
848870
it("Ec2SimpleInputParamsStrings:Request", async () => {
849871
const client = new EC2ProtocolClient({
872+
...clientParams,
850873
requestHandler: new RequestSerializationTestHandler(),
851874
});
852875

@@ -886,6 +909,7 @@ it("Ec2SimpleInputParamsStrings:Request", async () => {
886909
*/
887910
it("Ec2SimpleInputParamsStringAndBooleanTrue:Request", async () => {
888911
const client = new EC2ProtocolClient({
912+
...clientParams,
889913
requestHandler: new RequestSerializationTestHandler(),
890914
});
891915

@@ -925,6 +949,7 @@ it("Ec2SimpleInputParamsStringAndBooleanTrue:Request", async () => {
925949
*/
926950
it("Ec2SimpleInputParamsStringsAndBooleanFalse:Request", async () => {
927951
const client = new EC2ProtocolClient({
952+
...clientParams,
928953
requestHandler: new RequestSerializationTestHandler(),
929954
});
930955

@@ -961,6 +986,7 @@ it("Ec2SimpleInputParamsStringsAndBooleanFalse:Request", async () => {
961986
*/
962987
it("Ec2SimpleInputParamsInteger:Request", async () => {
963988
const client = new EC2ProtocolClient({
989+
...clientParams,
964990
requestHandler: new RequestSerializationTestHandler(),
965991
});
966992

@@ -997,6 +1023,7 @@ it("Ec2SimpleInputParamsInteger:Request", async () => {
9971023
*/
9981024
it("Ec2SimpleInputParamsFloat:Request", async () => {
9991025
const client = new EC2ProtocolClient({
1026+
...clientParams,
10001027
requestHandler: new RequestSerializationTestHandler(),
10011028
});
10021029

@@ -1033,6 +1060,7 @@ it("Ec2SimpleInputParamsFloat:Request", async () => {
10331060
*/
10341061
it("Ec2SimpleInputParamsBlob:Request", async () => {
10351062
const client = new EC2ProtocolClient({
1063+
...clientParams,
10361064
requestHandler: new RequestSerializationTestHandler(),
10371065
});
10381066

@@ -1069,6 +1097,7 @@ it("Ec2SimpleInputParamsBlob:Request", async () => {
10691097
*/
10701098
it("Ec2Enums:Request", async () => {
10711099
const client = new EC2ProtocolClient({
1100+
...clientParams,
10721101
requestHandler: new RequestSerializationTestHandler(),
10731102
});
10741103

@@ -1105,6 +1134,7 @@ it("Ec2Enums:Request", async () => {
11051134
*/
11061135
it("Ec2Query:Request", async () => {
11071136
const client = new EC2ProtocolClient({
1137+
...clientParams,
11081138
requestHandler: new RequestSerializationTestHandler(),
11091139
});
11101140

@@ -1141,6 +1171,7 @@ it("Ec2Query:Request", async () => {
11411171
*/
11421172
it("Ec2QueryIsPreferred:Request", async () => {
11431173
const client = new EC2ProtocolClient({
1174+
...clientParams,
11441175
requestHandler: new RequestSerializationTestHandler(),
11451176
});
11461177

@@ -1177,6 +1208,7 @@ it("Ec2QueryIsPreferred:Request", async () => {
11771208
*/
11781209
it("Ec2XmlNameIsUppercased:Request", async () => {
11791210
const client = new EC2ProtocolClient({
1211+
...clientParams,
11801212
requestHandler: new RequestSerializationTestHandler(),
11811213
});
11821214

@@ -1213,6 +1245,7 @@ it("Ec2XmlNameIsUppercased:Request", async () => {
12131245
*/
12141246
it("Ec2SimpleScalarProperties:Response", async () => {
12151247
const client = new EC2ProtocolClient({
1248+
...clientParams,
12161249
requestHandler: new ResponseDeserializationTestHandler(
12171250
true,
12181251
200,
@@ -1281,6 +1314,7 @@ it("Ec2SimpleScalarProperties:Response", async () => {
12811314
*/
12821315
it("Ec2XmlBlobs:Response", async () => {
12831316
const client = new EC2ProtocolClient({
1317+
...clientParams,
12841318
requestHandler: new ResponseDeserializationTestHandler(
12851319
true,
12861320
200,
@@ -1322,6 +1356,7 @@ it("Ec2XmlBlobs:Response", async () => {
13221356
*/
13231357
it("Ec2XmlEnums:Response", async () => {
13241358
const client = new EC2ProtocolClient({
1359+
...clientParams,
13251360
requestHandler: new ResponseDeserializationTestHandler(
13261361
true,
13271362
200,
@@ -1397,6 +1432,7 @@ it("Ec2XmlEnums:Response", async () => {
13971432
*/
13981433
it("Ec2XmlLists:Response", async () => {
13991434
const client = new EC2ProtocolClient({
1435+
...clientParams,
14001436
requestHandler: new ResponseDeserializationTestHandler(
14011437
true,
14021438
200,
@@ -1525,6 +1561,7 @@ it("Ec2XmlLists:Response", async () => {
15251561
*/
15261562
it("Ec2XmlNamespaces:Response", async () => {
15271563
const client = new EC2ProtocolClient({
1564+
...clientParams,
15281565
requestHandler: new ResponseDeserializationTestHandler(
15291566
true,
15301567
200,
@@ -1576,6 +1613,7 @@ it("Ec2XmlNamespaces:Response", async () => {
15761613
*/
15771614
it("Ec2XmlTimestamps:Response", async () => {
15781615
const client = new EC2ProtocolClient({
1616+
...clientParams,
15791617
requestHandler: new ResponseDeserializationTestHandler(
15801618
true,
15811619
200,
@@ -1617,6 +1655,7 @@ it("Ec2XmlTimestamps:Response", async () => {
16171655
*/
16181656
it("Ec2XmlTimestampsWithDateTimeFormat:Response", async () => {
16191657
const client = new EC2ProtocolClient({
1658+
...clientParams,
16201659
requestHandler: new ResponseDeserializationTestHandler(
16211660
true,
16221661
200,
@@ -1658,6 +1697,7 @@ it("Ec2XmlTimestampsWithDateTimeFormat:Response", async () => {
16581697
*/
16591698
it("Ec2XmlTimestampsWithEpochSecondsFormat:Response", async () => {
16601699
const client = new EC2ProtocolClient({
1700+
...clientParams,
16611701
requestHandler: new ResponseDeserializationTestHandler(
16621702
true,
16631703
200,
@@ -1699,6 +1739,7 @@ it("Ec2XmlTimestampsWithEpochSecondsFormat:Response", async () => {
16991739
*/
17001740
it("Ec2XmlTimestampsWithHttpDateFormat:Response", async () => {
17011741
const client = new EC2ProtocolClient({
1742+
...clientParams,
17021743
requestHandler: new ResponseDeserializationTestHandler(
17031744
true,
17041745
200,

0 commit comments

Comments
 (0)