Skip to content

Commit 2db465a

Browse files
authored
test(credential-providers): integration test for 'read config files from paths relative to homedir' (#6210)
1 parent e11de23 commit 2db465a

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
preset: "ts-jest",
3+
testMatch: ["**/*.integ.spec.ts"],
4+
};

packages/credential-providers/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1717
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1818
"extract:docs": "api-extractor run --local",
19-
"test": "jest"
19+
"test": "jest",
20+
"test:integration": "jest -c jest.config.integ.js"
2021
},
2122
"keywords": [
2223
"aws",
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { ListBucketsCommand, S3 } from "@aws-sdk/client-s3";
2+
import fs from "fs";
3+
import { homedir } from "os";
4+
import { join } from "path";
5+
6+
import { fromSSO } from "./fromSSO";
7+
8+
const SAMPLE_CONFIG = `[profile dev]
9+
sso_session = my-sso
10+
sso_account_id = 111122223333
11+
sso_role_name = SampleRole
12+
13+
[sso-session my-sso]
14+
sso_region = us-east-1
15+
sso_start_url = https://my-sso-portal.awsapps.com/start
16+
sso_registration_scopes = sso:account:access
17+
`;
18+
19+
jest.mock("fs", () => {
20+
return {
21+
promises: {
22+
readFile: jest.fn(),
23+
},
24+
};
25+
});
26+
27+
describe("fromSSO integration test", () => {
28+
beforeEach(() => {
29+
jest.resetAllMocks();
30+
});
31+
32+
it("should expand relative homedir", async () => {
33+
const mockReadFile = (fs.promises.readFile as jest.Mock).mockResolvedValue(SAMPLE_CONFIG);
34+
35+
const client = new S3({
36+
region: "eu-west-1",
37+
credentials: fromSSO({
38+
profile: "dev",
39+
filepath: "~/custom/path/to/credentials",
40+
configFilepath: "~/custom/path/to/config",
41+
}),
42+
});
43+
44+
try {
45+
await client.send(new ListBucketsCommand({}));
46+
} catch (e) {
47+
// do nothing
48+
}
49+
50+
expect(mockReadFile).toHaveBeenCalledWith(join(homedir(), "custom/path/to/credentials"), "utf8");
51+
expect(mockReadFile).toHaveBeenCalledWith(join(homedir(), "custom/path/to/config"), "utf8");
52+
});
53+
});

0 commit comments

Comments
 (0)