Skip to content

Commit 21e3443

Browse files
authored
test(middleware): middleware integ tests pt. 3 (#4691)
1 parent 8e4e1ea commit 21e3443

File tree

13 files changed

+315
-7
lines changed

13 files changed

+315
-7
lines changed

packages/middleware-serde/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"build:types": "tsc -p tsconfig.types.json",
1010
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1111
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
12-
"test": "jest"
12+
"test": "jest",
13+
"test:integration": "jest -c jest.config.integ.js"
1314
},
1415
"main": "./dist-cjs/index.js",
1516
"module": "./dist-es/index.js",
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { EC2 } from "@aws-sdk/client-ec2";
2+
import { S3 } from "@aws-sdk/client-s3";
3+
import { SageMaker } from "@aws-sdk/client-sagemaker";
4+
import { SageMakerRuntime } from "@aws-sdk/client-sagemaker-runtime";
5+
6+
import { requireRequestsFrom } from "../../../private/aws-util-test/src";
7+
8+
describe("middleware-serde", () => {
9+
describe(S3.name, () => {
10+
it("should serialize xml", async () => {
11+
const client = new S3({ region: "us-west-2" });
12+
requireRequestsFrom(client).toMatch({
13+
method: "PUT",
14+
hostname: "s3.us-west-2.amazonaws.com",
15+
body: '<?xml version="1.0" encoding="UTF-8"?><AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><AccessControlList><Grant><Grantee xsi:type="CanonicalUser" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><DisplayName>STRING_VALUE</DisplayName><EmailAddress>STRING_VALUE</EmailAddress><ID>STRING_VALUE</ID><URI>STRING_VALUE</URI></Grantee><Permission>READ</Permission></Grant></AccessControlList><Owner><DisplayName>STRING_VALUE</DisplayName><ID>STRING_VALUE</ID></Owner></AccessControlPolicy>',
16+
protocol: "https:",
17+
path: "/STRING_VALUE/",
18+
headers: {
19+
"content-type": "application/xml",
20+
"x-amz-acl": "private",
21+
"content-length": "509",
22+
Expect: "100-continue",
23+
"content-md5": "qpwmS0vhCISEXes008aoXA==",
24+
host: "s3.us-west-2.amazonaws.com",
25+
"x-amz-content-sha256": "c0a89780e1aac5dfa17604e9e25616e7babba0b655db189be49b4c352543bb22",
26+
},
27+
query: { acl: "" },
28+
});
29+
await client.putBucketAcl({
30+
ACL: "private",
31+
AccessControlPolicy: {
32+
Grants: [
33+
{
34+
Grantee: {
35+
DisplayName: "STRING_VALUE",
36+
EmailAddress: "STRING_VALUE",
37+
ID: "STRING_VALUE",
38+
URI: "STRING_VALUE",
39+
Type: "CanonicalUser", // required
40+
},
41+
Permission: "READ",
42+
},
43+
],
44+
Owner: {
45+
DisplayName: "STRING_VALUE",
46+
ID: "STRING_VALUE",
47+
},
48+
},
49+
Bucket: "STRING_VALUE", // required
50+
});
51+
});
52+
});
53+
54+
describe(EC2.name, () => {
55+
it("should serialize query", async () => {
56+
const client = new EC2({ region: "us-west-2" });
57+
requireRequestsFrom(client).toMatch({
58+
method: "POST",
59+
hostname: "ec2.us-west-2.amazonaws.com",
60+
query: {},
61+
headers: {
62+
"content-type": "application/x-www-form-urlencoded",
63+
host: "ec2.us-west-2.amazonaws.com",
64+
},
65+
body: /ClientCidrBlock=ClientCidrBlock&ServerCertificateArn=ServerCertificateArn(.*?)&Action=CreateClientVpnEndpoint&Version=2016-11-15/,
66+
protocol: "https:",
67+
path: "/",
68+
});
69+
await client.createClientVpnEndpoint({
70+
ClientCidrBlock: "ClientCidrBlock",
71+
ServerCertificateArn: "ServerCertificateArn",
72+
AuthenticationOptions: [],
73+
ConnectionLogOptions: {},
74+
});
75+
});
76+
});
77+
78+
describe(SageMaker.name, () => {
79+
it("should serialize json", async () => {
80+
const client = new SageMaker({ region: "us-west-2" });
81+
requireRequestsFrom(client).toMatch({
82+
method: "POST",
83+
hostname: "api.sagemaker.us-west-2.amazonaws.com",
84+
query: {},
85+
headers: {
86+
"content-type": "application/x-amz-json-1.1",
87+
"x-amz-target": "SageMaker.PutModelPackageGroupPolicy",
88+
host: "api.sagemaker.us-west-2.amazonaws.com",
89+
},
90+
body: '{"ModelPackageGroupName":"ModelPackageGroupName","ResourcePolicy":"ResourcePolicy"}',
91+
protocol: "https:",
92+
path: "/",
93+
});
94+
await client.putModelPackageGroupPolicy({
95+
ModelPackageGroupName: "ModelPackageGroupName",
96+
ResourcePolicy: "ResourcePolicy",
97+
});
98+
});
99+
});
100+
101+
describe(SageMakerRuntime.name, () => {
102+
it("should serialize json", async () => {
103+
const client = new SageMakerRuntime({ region: "us-west-2" });
104+
requireRequestsFrom(client).toMatch({
105+
method: "POST",
106+
hostname: "runtime.sagemaker.us-west-2.amazonaws.com",
107+
query: {},
108+
headers: {
109+
"x-amzn-sagemaker-inputlocation": "InputLocation",
110+
host: "runtime.sagemaker.us-west-2.amazonaws.com",
111+
"x-amz-content-sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
112+
},
113+
body: /undefined/,
114+
protocol: "https:",
115+
path: "/endpoints/EndpointName/async-invocations",
116+
});
117+
await client.invokeEndpointAsync({
118+
EndpointName: "EndpointName",
119+
InputLocation: "InputLocation",
120+
});
121+
});
122+
});
123+
});

packages/middleware-signing/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"build:types": "tsc -p tsconfig.types.json",
1010
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1111
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
12-
"test": "jest --passWithNoTests"
12+
"test": "jest --passWithNoTests",
13+
"test:integration": "jest -c jest.config.integ.js"
1314
},
1415
"main": "./dist-cjs/index.js",
1516
"module": "./dist-es/index.js",
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { EC2 } from "@aws-sdk/client-ec2";
2+
import { SageMaker } from "@aws-sdk/client-sagemaker";
3+
4+
import { requireRequestsFrom } from "../../../private/aws-util-test/src";
5+
6+
describe("middleware-signing", () => {
7+
describe(EC2.name, () => {
8+
it("sign requests in the header", async () => {
9+
const client = new EC2({ region: "us-west-2" });
10+
requireRequestsFrom(client).toMatch({
11+
headers: {
12+
"x-amz-date": /\d{8}T\d+Z/,
13+
"x-amz-content-sha256": /\w{30}\w+/,
14+
authorization:
15+
/AWS4-HMAC-SHA256 Credential=(.+)\/(.+)\/(.+)\/(.+)\/aws4_request, SignedHeaders=(.+), Signature=(.+)/,
16+
},
17+
});
18+
await client.createClientVpnEndpoint({
19+
ClientCidrBlock: "ClientCidrBlock",
20+
ServerCertificateArn: "ServerCertificateArn",
21+
AuthenticationOptions: [],
22+
ConnectionLogOptions: {},
23+
});
24+
});
25+
});
26+
27+
describe(SageMaker.name, () => {
28+
it("sign requests in the header", async () => {
29+
const client = new SageMaker({ region: "us-west-2" });
30+
requireRequestsFrom(client).toMatch({
31+
headers: {
32+
"x-amz-date": /\d{8}T\d+Z/,
33+
"x-amz-content-sha256": /\w{30}\w+/,
34+
authorization:
35+
/AWS4-HMAC-SHA256 Credential=(.+)\/(.+)\/(.+)\/(.+)\/aws4_request, SignedHeaders=(.+), Signature=(.+)/,
36+
},
37+
});
38+
await client.putModelPackageGroupPolicy({
39+
ModelPackageGroupName: "ModelPackageGroupName",
40+
ResourcePolicy: "ResourcePolicy",
41+
});
42+
});
43+
});
44+
});

packages/middleware-ssec/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"build:types": "tsc -p tsconfig.types.json",
1010
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1111
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
12-
"test": "jest"
12+
"test": "jest",
13+
"test:integration": "jest -c jest.config.integ.js"
1314
},
1415
"main": "./dist-cjs/index.js",
1516
"module": "./dist-es/index.js",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { S3 } from "@aws-sdk/client-s3";
2+
3+
import { requireRequestsFrom } from "../../../private/aws-util-test/src";
4+
5+
// "server-side-encryption"
6+
describe("middleware-ssec", () => {
7+
describe(S3.name, () => {
8+
it("adds hash for SSECustomerKey and CopySourceSSECustomerKey", async () => {
9+
const client = new S3({ region: "us-west-2" });
10+
requireRequestsFrom(client).toMatch({
11+
method: "PUT",
12+
hostname: "s3.us-west-2.amazonaws.com",
13+
query: { "x-id": "CopyObject" },
14+
headers: {
15+
"x-amz-copy-source": "s",
16+
"x-amz-server-side-encryption-customer-key": "c3NlLWN1c3RvbWVyLWtleQ==",
17+
"x-amz-server-side-encryption-customer-key-md5": "E+/nTVpQe9+cNzOKBFXSlA==",
18+
"x-amz-copy-source-server-side-encryption-customer-key": "Y29weS1zb3VyY2Utc3NlLWN1c3RvbWVyLWtleQ==",
19+
"x-amz-copy-source-server-side-encryption-customer-key-md5": "4CgOx9iMMPvAQi7bWXEJEw==",
20+
},
21+
protocol: "https:",
22+
path: "/b/k",
23+
});
24+
await client.copyObject({
25+
SSECustomerKey: "sse-customer-key",
26+
CopySourceSSECustomerKey: "copy-source-sse-customer-key",
27+
Bucket: "b",
28+
CopySource: "s",
29+
Key: "k",
30+
});
31+
});
32+
});
33+
});

packages/middleware-stack/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"build:types": "tsc -p tsconfig.types.json",
1111
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1212
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
13-
"test": "jest"
13+
"test": "jest",
14+
"test:integration": "jest -c jest.config.integ.js --passWithNoTests"
1415
},
1516
"author": {
1617
"name": "AWS SDK for JavaScript Team",

packages/middleware-token/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"build:types": "tsc -p tsconfig.types.json",
1414
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1515
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
16-
"test": "jest"
16+
"test": "jest",
17+
"test:integration": "jest -c jest.config.integ.js"
1718
},
1819
"keywords": [
1920
"aws",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { CodeCatalyst } from "@aws-sdk/client-codecatalyst";
2+
3+
import { requireRequestsFrom } from "../../../private/aws-util-test/src";
4+
5+
describe("middleware-token", () => {
6+
describe(CodeCatalyst.name, () => {
7+
it("sets bearer token authorization header", async () => {
8+
const client = new CodeCatalyst({
9+
region: "us-west-2",
10+
token: {
11+
token: "my-token",
12+
},
13+
});
14+
requireRequestsFrom(client).toMatch({
15+
headers: {
16+
authorization: /Bearer my-token/,
17+
},
18+
});
19+
await client.getUserDetails({
20+
id: "my-id",
21+
userName: "my-username",
22+
});
23+
});
24+
});
25+
});

packages/middleware-user-agent/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"build:types": "tsc -p tsconfig.types.json",
1010
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1111
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
12-
"test": "jest --passWithNoTests"
12+
"test": "jest --passWithNoTests",
13+
"test:integration": "jest -c jest.config.integ.js"
1314
},
1415
"main": "./dist-cjs/index.js",
1516
"module": "./dist-es/index.js",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { CodeCatalyst } from "@aws-sdk/client-codecatalyst";
2+
3+
import { requireRequestsFrom } from "../../../private/aws-util-test/src";
4+
5+
describe("middleware-user-agent", () => {
6+
describe(CodeCatalyst.name, () => {
7+
it("sets the SDK user agent", async () => {
8+
const client = new CodeCatalyst({
9+
region: "us-west-2",
10+
token: {
11+
token: "my-token",
12+
},
13+
});
14+
requireRequestsFrom(client).toMatch({
15+
headers: {
16+
"x-amz-user-agent": /aws-sdk-js\/[\d\.]+/,
17+
"user-agent": /aws-sdk-js\/[\d\.]+ (.*?)lang\/js md\/nodejs\/[\d\.]+ (.*?)api\/(.+)\/[\d\.]+/,
18+
},
19+
});
20+
await client.getUserDetails({
21+
id: "my-id",
22+
userName: "my-username",
23+
});
24+
});
25+
});
26+
});

packages/middleware-websocket/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"build:types": "tsc -p tsconfig.types.json",
1313
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1414
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
15-
"test": "jest"
15+
"test": "jest",
16+
"test:integration": "jest -c jest.config.integ.js"
1617
},
1718
"author": {
1819
"name": "AWS SDK for JavaScript Team",
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { RekognitionStreaming } from "@aws-sdk/client-rekognitionstreaming";
2+
3+
import { requireRequestsFrom } from "../../../private/aws-util-test/src";
4+
5+
describe("middleware-websocket", () => {
6+
describe(RekognitionStreaming.name, () => {
7+
it("sets protocol, headers, moves params to query, and signs in the query", async () => {
8+
const client = new RekognitionStreaming({
9+
region: "us-west-2",
10+
});
11+
requireRequestsFrom(client).toMatch({
12+
protocol: "wss:",
13+
path: "/start-face-liveness-session-websocket",
14+
headers: {
15+
host: "streaming-rekognition.us-west-2.amazonaws.com",
16+
"Content-Type": /^undefined$/,
17+
"x-amz-content-sha256": /^undefined$/,
18+
"user-agent": /^aws-sdk-js/,
19+
},
20+
query: {
21+
"session-id": "abcd-1234",
22+
"video-width": "1024",
23+
"video-height": "1024",
24+
"challenge-versions": "a,b,c",
25+
"x-amz-user-agent": /^aws-sdk-js/,
26+
"X-Amz-Algorithm": "AWS4-HMAC-SHA256",
27+
"X-Amz-Credential": /(.*?)\/(.*?)\/us-west-2\/rekognition\/aws4_request/,
28+
"X-Amz-Date": /./,
29+
"X-Amz-Expires": "60",
30+
"X-Amz-SignedHeaders": "host",
31+
"X-Amz-Signature": /./,
32+
},
33+
});
34+
client.config.requestHandler.metadata = {
35+
handlerProtocol: "websocket",
36+
};
37+
await client.startFaceLivenessSession({
38+
SessionId: "abcd-1234",
39+
VideoWidth: "1024",
40+
VideoHeight: "1024",
41+
ChallengeVersions: "a,b,c",
42+
LivenessRequestStream: {
43+
[Symbol.asyncIterator]() {
44+
return this;
45+
},
46+
},
47+
});
48+
});
49+
});
50+
});

0 commit comments

Comments
 (0)