Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src";
import { DynamoDB } from "@aws-sdk/client-dynamodb";
import { AwsCredentialIdentity } from "@smithy/types";
import { afterEach, beforeEach, describe, expect, test as it } from "vitest";

describe("account id endpoint", () => {
const credentialsWithAccountId: AwsCredentialIdentity = {
accessKeyId: "INTEG_TEST",
secretAccessKey: "INTEG_TEST",
accountId: "123456789012",
};
const credentials = {
accessKeyId: "INTEG_TEST",
secretAccessKey: "INTEG_TEST",
};

beforeEach(async () => {
delete process.env.AWS_ACCOUNT_ID_ENDPOINT_MODE;
});
afterEach(async () => {
delete process.env.AWS_ACCOUNT_ID_ENDPOINT_MODE;
});

describe("when credentials have account id", () => {
it("should default to resolving endpoint with account id when it is available in the client credentials", async () => {
const ddb = new DynamoDB({
region: "us-west-2",
credentials: credentialsWithAccountId,
});
requireRequestsFrom(ddb).toMatch({
hostname: /123456789012.ddb.us-west-2.amazonaws.com/,
});
await ddb.listTables();
});

describe("config values", () => {
it("disabled", async () => {
const ddb = new DynamoDB({
region: "us-west-2",
credentials: credentialsWithAccountId,
accountIdEndpointMode: "disabled",
});
requireRequestsFrom(ddb).toMatch({
hostname: /dynamodb.us-west-2.amazonaws.com/,
});
await ddb.listTables();
});
it("preferred", async () => {
const ddb = new DynamoDB({
region: "us-west-2",
credentials: credentialsWithAccountId,
accountIdEndpointMode: "preferred",
});
requireRequestsFrom(ddb).toMatch({
hostname: /123456789012.ddb.us-west-2.amazonaws.com/,
});
await ddb.listTables();
});
it("required", async () => {
const ddb = new DynamoDB({
region: "us-west-2",
credentials: credentialsWithAccountId,
accountIdEndpointMode: "required",
});
requireRequestsFrom(ddb).toMatch({
hostname: /123456789012.ddb.us-west-2.amazonaws.com/,
});
await ddb.listTables();
});
});

describe("ENV values", () => {
it("disabled", async () => {
process.env.AWS_ACCOUNT_ID_ENDPOINT_MODE = "disabled";
const ddb = new DynamoDB({
region: "us-west-2",
credentials: credentialsWithAccountId,
});
requireRequestsFrom(ddb).toMatch({
hostname: /dynamodb.us-west-2.amazonaws.com/,
});
await ddb.listTables();
});
it("preferred", async () => {
process.env.AWS_ACCOUNT_ID_ENDPOINT_MODE = "preferred";
const ddb = new DynamoDB({
region: "us-west-2",
credentials: credentialsWithAccountId,
});
requireRequestsFrom(ddb).toMatch({
hostname: /123456789012.ddb.us-west-2.amazonaws.com/,
});
await ddb.listTables();
});
it("required", async () => {
process.env.AWS_ACCOUNT_ID_ENDPOINT_MODE = "required";
const ddb = new DynamoDB({
region: "us-west-2",
credentials: credentialsWithAccountId,
});
requireRequestsFrom(ddb).toMatch({
hostname: /123456789012.ddb.us-west-2.amazonaws.com/,
});
await ddb.listTables();
});
});
});

describe("when credentials do not have account id", () => {
it("it follows that the hostname will not have it either", async () => {
const ddb = new DynamoDB({
region: "us-west-2",
credentials: credentials,
});
requireRequestsFrom(ddb).toMatch({
hostname: /dynamodb.us-west-2.amazonaws.com/,
});
await ddb.listTables();
});

it("will fail if required by ENV", async () => {
process.env.AWS_ACCOUNT_ID_ENDPOINT_MODE = "required";
const ddb = new DynamoDB({
region: "us-west-2",
credentials: credentials,
});
const error = await ddb.listTables().catch((e) => e);
expect(error.name).toEqual("EndpointError");
});

it("will fail if required by config", async () => {
const ddb = new DynamoDB({
region: "us-west-2",
credentials: credentials,
accountIdEndpointMode: "required",
});
const error = await ddb.listTables().catch((e) => e);
expect(error.name).toEqual("EndpointError");
});
});
});
92 changes: 92 additions & 0 deletions packages/core/src/submodules/client/pagination.integ.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src";
import { DynamoDB, paginateScan, ScanCommandInput } from "@aws-sdk/client-dynamodb";
import { HttpResponse } from "@smithy/protocol-http";
import { describe, expect, test as it } from "vitest";

describe("pagination", () => {
it("makes sequential requests using a pagination token", async () => {
const ddb = new DynamoDB({
credentials: {
accessKeyId: "INTEG_TEST",
secretAccessKey: "INTEG_TEST",
},
region: "us-west-2",
});

requireRequestsFrom(ddb)
.toMatch(
{
hostname: /dynamodb/,
body(b) {
expect(b).toContain("TableName");
expect(b).not.toContain("ExclusiveStartKey");
},
},
{
hostname: /dynamodb/,
body: /ExclusiveStartKey/,
}
)
.respondWith(
new HttpResponse({
statusCode: 200,
headers: {},
body: Buffer.from(
JSON.stringify({
Items: [
{
id: { S: "1" },
name: { S: "Item 1" },
},
{
id: { S: "2" },
name: { S: "Item 2" },
},
],
Count: 2,
ScannedCount: 2,
LastEvaluatedKey: {
id: { S: "2" },
},
})
),
}),
new HttpResponse({
statusCode: 200,
headers: {},
body: Buffer.from(
JSON.stringify({
Items: [
{
id: { S: "3" },
name: { S: "Item 3" },
},
{
id: { S: "4" },
name: { S: "Item 4" },
},
],
Count: 2,
ScannedCount: 2,
})
),
})
);

const requestParams: ScanCommandInput = {
TableName: "test",
};

let pages = 0;
for await (const page of paginateScan({ client: ddb }, requestParams)) {
void page;
pages += 1;
}

expect(pages).toEqual(2);
expect(requestParams.ExclusiveStartKey).toEqual({
id: { S: "2" },
});
expect.assertions(7);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src";
import { Schemas } from "@aws-sdk/client-schemas";
import { LazyJsonString } from "@smithy/core/serde";
import { describe, expect, test as it } from "vitest";

describe(LazyJsonString.name, () => {
it("should auto-serialize fields to JSON", async () => {
const client = new Schemas({
region: "us-west-2",
});

let request = 0;

requireRequestsFrom(client).toMatch({
body(b) {
if (request === 0) {
expect(b).toEqual(`{"Policy":"this is a plain string"}`);
request += 1;
} else if (request === 1) {
expect(b).toEqual(`{"Policy":"{\\"this\\":\\"is a json string\\"}"}`);
request += 1;
} else if (request === 2) {
expect(b).toEqual(`{"Policy":"{\\"message\\":\\"this is a js object\\"}"}`);
request += 1;
}
},
});

await client.putResourcePolicy({
Policy: "this is a plain string",
});
await client.putResourcePolicy({
Policy: `{"this":"is a json string"}`,
});
await client.putResourcePolicy({
Policy: {
message: "this is a js object",
},
});
expect.assertions(3);
});
});
Loading
Loading