Skip to content

Commit 5f345dd

Browse files
committed
chore(config-resolver): add NodeUseFipsEndpointConfigOptions
1 parent 1b3c9b7 commit 5f345dd

File tree

4 files changed

+71
-6
lines changed

4 files changed

+71
-6
lines changed

packages/config-resolver/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
"url": "https://aws.amazon.com/javascript/"
1818
},
1919
"license": "Apache-2.0",
20-
"devDependencies": {
21-
"@aws-sdk/node-config-provider": "3.38.0",
22-
"@types/jest": "^26.0.4",
23-
"jest": "^26.1.0",
24-
"typescript": "~4.3.5"
25-
},
2620
"dependencies": {
21+
"@aws-sdk/node-config-provider": "3.38.0",
2722
"@aws-sdk/signature-v4": "3.38.0",
2823
"@aws-sdk/types": "3.38.0",
2924
"tslib": "^2.3.0"
3025
},
26+
"devDependencies": {
27+
"@types/jest": "^26.0.4",
28+
"jest": "^26.1.0",
29+
"typescript": "~4.3.5"
30+
},
3131
"engines": {
3232
"node": ">= 10.0.0"
3333
},
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { booleanSelector, SelectorType } from "@aws-sdk/node-config-provider";
2+
3+
import {
4+
CONFIG_USE_FIPS_ENDPOINT,
5+
DEFAULT_USE_FIPS_ENDPOINT,
6+
ENV_USE_FIPS_ENDPOINT,
7+
NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS,
8+
} from "./NodeUseFipsEndpointConfigOptions";
9+
10+
jest.mock("@aws-sdk/node-config-provider");
11+
12+
describe("NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS", () => {
13+
afterEach(() => {
14+
jest.clearAllMocks();
15+
});
16+
17+
const test = (func: Function, obj: { [key: string]: string }, key: string, type: SelectorType) => {
18+
it.each([true, false, undefined])("returns %s", (output) => {
19+
(booleanSelector as jest.Mock).mockReturnValueOnce(output);
20+
expect(func(obj)).toEqual(output);
21+
expect(booleanSelector).toBeCalledWith(obj, key, type);
22+
});
23+
24+
it("throws error", () => {
25+
const mockError = new Error("error");
26+
(booleanSelector as jest.Mock).mockImplementationOnce(() => {
27+
throw mockError;
28+
});
29+
expect(() => {
30+
func(obj);
31+
}).toThrow(mockError);
32+
});
33+
};
34+
35+
describe("calls booleanSelector for environmentVariableSelector", () => {
36+
const env: { [ENV_USE_FIPS_ENDPOINT]: any } = {} as any;
37+
const { environmentVariableSelector } = NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS;
38+
test(environmentVariableSelector, env, ENV_USE_FIPS_ENDPOINT, SelectorType.ENV);
39+
});
40+
41+
describe("calls booleanSelector for configFileSelector", () => {
42+
const profileContent: { [CONFIG_USE_FIPS_ENDPOINT]: any } = {} as any;
43+
const { configFileSelector } = NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS;
44+
test(configFileSelector, profileContent, CONFIG_USE_FIPS_ENDPOINT, SelectorType.CONFIG);
45+
});
46+
47+
it("returns false for default", () => {
48+
const { default: defaultValue } = NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS;
49+
expect(defaultValue).toEqual(DEFAULT_USE_FIPS_ENDPOINT);
50+
});
51+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { LoadedConfigSelectors } from "@aws-sdk/node-config-provider";
2+
import { booleanSelector, SelectorType } from "@aws-sdk/node-config-provider";
3+
4+
export const ENV_USE_FIPS_ENDPOINT = "AWS_USE_FIPS_ENDPOINT";
5+
export const CONFIG_USE_FIPS_ENDPOINT = "use_fips_endpoint";
6+
export const DEFAULT_USE_FIPS_ENDPOINT = false;
7+
8+
export const NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS: LoadedConfigSelectors<boolean> = {
9+
environmentVariableSelector: (env: NodeJS.ProcessEnv) =>
10+
booleanSelector(env, ENV_USE_FIPS_ENDPOINT, SelectorType.ENV),
11+
configFileSelector: (profile) => booleanSelector(profile, CONFIG_USE_FIPS_ENDPOINT, SelectorType.CONFIG),
12+
default: false,
13+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from "./NodeUseFipsEndpointConfigOptions";
12
export * from "./config";
23
export * from "./resolveRegionConfig";

0 commit comments

Comments
 (0)