Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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,45 @@
import { afterAll, beforeEach, describe, expect, test as it } from "vitest";
import { S3 } from "@aws-sdk/client-s3";
import path from "node:path";
import type { Provider } from "@smithy/types";

describe("defaults mode", () => {
const snapshot = {
...process.env,
};

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

afterAll(async () => {
process.env = snapshot;
});

it("should load various client configuration options from file with default profile", async () => {
process.env.AWS_CONFIG_FILE = path.join(__dirname, "mock-aws-config");

const client = new S3({});

expect(await client.config.region()).toEqual("us-west-2");
});

it("should load various client configuration options from specific profile", async () => {
process.env.AWS_CONFIG_FILE = path.join(__dirname, "mock-aws-config");

const client = new S3({
profile: "abc",
});

expect(await client.config.region()).toEqual("ap-northeast-1");
expect(await (client.config.retryMode as Provider<string>)()).toEqual("adaptive");
expect(await (client.config.disableS3ExpressSessionAuth as Provider<boolean>)()).toEqual(true);
expect(await client.config.maxAttempts()).toEqual(33);
expect(await client.config.requestChecksumCalculation()).toEqual("WHEN_REQUIRED");
expect(await client.config.sigv4aSigningRegionSet()).toEqual(["*", "*", "us-west-2"]);
expect(await client.config.useFipsEndpoint()).toEqual(true);
expect(await (client.config.useArnRegion as Provider<boolean>)()).toEqual(true);
expect(await client.config.useDualstackEndpoint()).toEqual(true);
expect(await client.config.userAgentAppId()).toEqual("blargh");
});
});
17 changes: 17 additions & 0 deletions packages/core/integ/configuration-file/mock-aws-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[profile empty]

[default]
region = us-west-2
output = json

[profile abc]
region = ap-northeast-1
retry_mode = adaptive
s3_disable_express_session_auth = true
max_attempts = 33
request_checksum_calculation = when_required
sigv4a_signing_region_set = *,*,us-west-2
use_fips_endpoint = true
s3_use_arn_region = true
use_dualstack_endpoint = true
sdk-ua-app-id = blargh
94 changes: 94 additions & 0 deletions packages/core/integ/defaults-mode.integ.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { describe, test as it, expect, beforeEach, afterAll } from "vitest";

import { CloudWatch } from "@aws-sdk/client-cloudwatch";
import type { DefaultsMode } from "@smithy/smithy-client";
import type { NodeHttpHandlerOptions, Provider } from "@smithy/types";
import type { Agent as hAgent } from "http";
import type { Agent as hsAgent } from "https";

describe("defaults mode", () => {
const snapshot = {
AWS_EXECUTION_ENV: process.env.AWS_EXECUTION_ENV,
AWS_REGION: process.env.AWS_REGION,
AWS_DEFAULT_REGION: process.env.AWS_DEFAULT_REGION,
AWS_DEFAULTS_MODE: process.env.AWS_DEFAULTS_MODE,
};

beforeEach(async () => {
delete process.env.AWS_EXECUTION_ENV;
delete process.env.AWS_REGION;
delete process.env.AWS_DEFAULT_REGION;
delete process.env.AWS_DEFAULTS_MODE;
});

afterAll(async () => {
Object.assign(process.env, snapshot);
});

const sharedConfig = {
credentials: {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
},
region: "ap-northeast-1",
};

async function assertCrossRegion(client: CloudWatch) {
expect(await (client.config.defaultsMode as Provider<DefaultsMode>)()).toEqual("cross-region");
const handler = client.config.requestHandler;

type ResolvedNodeHttpHandlerConfig = Omit<NodeHttpHandlerOptions, "httpAgent" | "httpsAgent"> & {
httpAgent: hAgent;
httpsAgent: hsAgent;
};

const config = await (
handler as unknown as {
configProvider: Promise<ResolvedNodeHttpHandlerConfig>;
}
).configProvider;

expect(config).toMatchObject({
connectionTimeout: 3100,
});
}

it("should set a higher timeout due to cross-region defaults mode when auto-detected (ENV)", async () => {
process.env.AWS_DEFAULTS_MODE = "auto";
process.env.AWS_EXECUTION_ENV = "INTEGRATION_TEST";
process.env.AWS_DEFAULT_REGION = "us-east-1";

const client = new CloudWatch(sharedConfig);

await assertCrossRegion(client);
});

it("should set a higher timeout due to cross-region defaults mode when auto-detected (client-config)", async () => {
process.env.AWS_EXECUTION_ENV = "INTEGRATION_TEST";
process.env.AWS_DEFAULT_REGION = "us-east-1";

const client = new CloudWatch({
...sharedConfig,
defaultsMode: "auto",
});

await assertCrossRegion(client);
});

it("should set a higher timeout when cross region defaults-mode is set (ENV)", async () => {
process.env.AWS_DEFAULTS_MODE = "cross-region";

const client = new CloudWatch(sharedConfig);

await assertCrossRegion(client);
});

it("should set a higher timeout when cross region defaults-mode is set (client-config)", async () => {
const client = new CloudWatch({
...sharedConfig,
defaultsMode: "cross-region",
});

await assertCrossRegion(client);
});
});
Loading