Skip to content

Commit 08d0a63

Browse files
committed
test(packages): integration tests for signers
1 parent cf2f0c1 commit 08d0a63

File tree

13 files changed

+189
-33
lines changed

13 files changed

+189
-33
lines changed

clients/client-s3/test/e2e/s3-object-lambda.e2e.spec.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { describe, test as it } from "vitest";
2+
3+
import { S3 } from "@aws-sdk/client-s3";
4+
import { AwsCredentialIdentity } from "@smithy/types";
5+
import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src";
6+
7+
describe("S3 Object Lambda", () => {
8+
const region = "us-west-2";
9+
const credentials: AwsCredentialIdentity = {
10+
accessKeyId: "",
11+
secretAccessKey: "",
12+
};
13+
14+
it("can make a GET request to an S3 Object Lambda ARN", async () => {
15+
const s3 = new S3({
16+
region,
17+
credentials,
18+
});
19+
20+
requireRequestsFrom(s3).toMatch({
21+
hostname: "my-access-point-123456789012.s3-object-lambda.us-west-2.amazonaws.com",
22+
query: {
23+
"x-id": "GetObject",
24+
},
25+
headers: {
26+
authorization: /=\/\d+\/us-west-2\/s3-object-lambda\/aws4_request/,
27+
},
28+
path: "/a",
29+
});
30+
31+
// slash delimiter
32+
await s3.getObject({
33+
Bucket: "arn:aws:s3-object-lambda:us-west-2:123456789012:accesspoint/my-access-point",
34+
Key: "a",
35+
});
36+
37+
// colon delimiter
38+
await s3.getObject({
39+
Bucket: "arn:aws:s3-object-lambda:us-west-2:123456789012:accesspoint:my-access-point",
40+
Key: "a",
41+
});
42+
});
43+
});

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1414
"extract:docs": "api-extractor run --local",
1515
"test": "yarn g:vitest run",
16-
"test:integration": "yarn g:vitest run -c vitest.config.integ.ts",
1716
"test:watch": "yarn g:vitest watch",
17+
"test:integration": "yarn g:vitest run -c vitest.config.integ.ts",
1818
"test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.ts"
1919
},
2020
"main": "./dist-cjs/index.js",

packages/dsql-signer/README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,36 @@ const { DsqlSigner } = require("@aws-sdk/dsql-signer");
3232
### Generate Authentication Token for Dsql IAM Authentication
3333

3434
```js
35+
import { Hash } from "@smithy/hash-node";
36+
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
37+
3538
const signer = new DsqlSigner({
3639
/**
3740
* Required: The hostname of the database to connect to.
3841
*/
39-
hostname: "foo0bar1baz2quux3quux4.dsql.us-east-1.on.aws";
42+
hostname: "foo0bar1baz2quux3quux4.dsql.us-east-1.on.aws",
4043

4144
/**
4245
* Optional: The region the database is located in. Uses the region inferred from the runtime if omitted.
4346
*/
44-
region?: "us-east-1";
47+
region: "us-east-1",
4548

4649
/**
4750
* Optional: The SHA256 hasher constructor to sign the request.
4851
*/
49-
sha256?: HashCtor;
52+
sha256: Hash.bind(null, "sha256"),
5053

5154
/**
5255
* Optional: The amount of time in seconds the generated token is valid
5356
*/
54-
expiresIn?: 3600;
57+
expiresIn: 3600,
5558

5659
/**
5760
* Optional: The AWS credentials to sign requests with. Uses the default credential provider chain if not specified.
61+
* You can use any credential provider from https://www.npmjs.com/package/@aws-sdk/credential-providers,
62+
* or provide a credentials object.
5863
*/
59-
credentials?: fromNodeCredentialProvider();
64+
credentials: fromNodeProviderChain(),
6065
});
6166

6267
// Creates auth token.

packages/dsql-signer/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1515
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1616
"extract:docs": "api-extractor run --local",
17-
"test": "yarn g:vitest run"
17+
"test": "yarn g:vitest run",
18+
"test:watch": "yarn g:vitest watch",
19+
"test:integration": "yarn g:vitest run -c vitest.config.integ.ts",
20+
"test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.ts"
1821
},
1922
"engines": {
2023
"node": ">=18.0.0"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Sha256 } from "@aws-crypto/sha256-js";
2+
import { describe, expect, test as it } from "vitest";
3+
4+
import { DsqlSigner, DsqlSignerConfig } from "./Signer";
5+
6+
describe("dsql-signer integration", () => {
7+
it("creates a token", async () => {
8+
const allParamsConfig: DsqlSignerConfig = {
9+
hostname: "localhost",
10+
region: "us-east-2",
11+
credentials: {
12+
accessKeyId: "allParamsAccessKey",
13+
secretAccessKey: "allParamsSecretAccessKey",
14+
sessionToken: "allParamsSessionToken",
15+
},
16+
expiresIn: 1000,
17+
sha256: Sha256,
18+
};
19+
const signer = new DsqlSigner(allParamsConfig);
20+
const token = await signer.getDbConnectAdminAuthToken();
21+
22+
expect(token.split("&").sort()).toMatchObject([
23+
/localhost\/\?Action=DbConnectAdmin/,
24+
/X-Amz-Algorithm=AWS4-HMAC-SHA256/,
25+
/X-Amz-Credential=allParamsAccessKey%2F(\d+)%2Fus-east-2%2Fdsql%2Faws4_request/,
26+
/X-Amz-Date=(\d+T\d+Z)/,
27+
/X-Amz-Expires=1000/,
28+
/X-Amz-Security-Token=allParamsSessionToken/,
29+
/X-Amz-Signature=(.*?)/,
30+
/X-Amz-SignedHeaders=host/,
31+
]);
32+
});
33+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
include: ["**/*.integ.spec.ts"],
6+
environment: "node",
7+
},
8+
});

packages/polly-request-presigner/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1212
"extract:docs": "api-extractor run --local",
1313
"test": "yarn g:vitest run",
14-
"test:watch": "yarn g:vitest watch"
14+
"test:watch": "yarn g:vitest watch",
15+
"test:integration": "yarn g:vitest run -c vitest.config.integ.ts",
16+
"test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.ts"
1517
},
1618
"main": "./dist-cjs/index.js",
1719
"module": "./dist-es/index.js",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { PollyClient } from "@aws-sdk/client-polly";
2+
import { describe, expect, test as it } from "vitest";
3+
4+
import { getSynthesizeSpeechUrl } from "./index";
5+
6+
describe("polly-request-presigner", () => {
7+
it("should sign URLs", async () => {
8+
const url = await getSynthesizeSpeechUrl({
9+
client: new PollyClient({
10+
credentials: {
11+
accessKeyId: "INTEG",
12+
secretAccessKey: "INTEG",
13+
},
14+
region: "us-east-1",
15+
}),
16+
params: {
17+
Text: "Hello world, the polly presigner is really cool!",
18+
OutputFormat: "mp3",
19+
VoiceId: "Kimberly",
20+
},
21+
});
22+
23+
const urlSegments = url.split("&");
24+
expect(urlSegments.sort()).toMatchObject([
25+
"Text=Hello%20world%2C%20the%20polly%20presigner%20is%20really%20cool%21",
26+
"VoiceId=Kimberly",
27+
"X-Amz-Algorithm=AWS4-HMAC-SHA256",
28+
/X-Amz-Credential=(.*?)%2F(\d{8})%2Fus-east-1%2Fpolly%2Faws4_request/,
29+
/X-Amz-Date=\d{8}T\d+Z/,
30+
"X-Amz-Expires=3600",
31+
/X-Amz-Signature=(.*?)/,
32+
"X-Amz-SignedHeaders=host",
33+
"https://polly.us-east-1.amazonaws.com/v1/speech?OutputFormat=mp3",
34+
/x-amz-user-agent=aws-sdk-js%2F\d\.\d+\.\d+/,
35+
]);
36+
});
37+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
include: ["**/*.integ.spec.ts"],
6+
environment: "node",
7+
},
8+
});

0 commit comments

Comments
 (0)