Skip to content

Commit

Permalink
test(credential-providers): integration test for 'read config files f…
Browse files Browse the repository at this point in the history
…rom paths relative to homedir' (#6210)
  • Loading branch information
Flackus authored Jul 22, 2024
1 parent e11de23 commit 2db465a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/credential-providers/jest.config.integ.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: "ts-jest",
testMatch: ["**/*.integ.spec.ts"],
};
3 changes: 2 additions & 1 deletion packages/credential-providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"extract:docs": "api-extractor run --local",
"test": "jest"
"test": "jest",
"test:integration": "jest -c jest.config.integ.js"
},
"keywords": [
"aws",
Expand Down
53 changes: 53 additions & 0 deletions packages/credential-providers/src/fromSSO.integ.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { ListBucketsCommand, S3 } from "@aws-sdk/client-s3";
import fs from "fs";
import { homedir } from "os";
import { join } from "path";

import { fromSSO } from "./fromSSO";

const SAMPLE_CONFIG = `[profile dev]
sso_session = my-sso
sso_account_id = 111122223333
sso_role_name = SampleRole
[sso-session my-sso]
sso_region = us-east-1
sso_start_url = https://my-sso-portal.awsapps.com/start
sso_registration_scopes = sso:account:access
`;

jest.mock("fs", () => {
return {
promises: {
readFile: jest.fn(),
},
};
});

describe("fromSSO integration test", () => {
beforeEach(() => {
jest.resetAllMocks();
});

it("should expand relative homedir", async () => {
const mockReadFile = (fs.promises.readFile as jest.Mock).mockResolvedValue(SAMPLE_CONFIG);

const client = new S3({
region: "eu-west-1",
credentials: fromSSO({
profile: "dev",
filepath: "~/custom/path/to/credentials",
configFilepath: "~/custom/path/to/config",
}),
});

try {
await client.send(new ListBucketsCommand({}));
} catch (e) {
// do nothing
}

expect(mockReadFile).toHaveBeenCalledWith(join(homedir(), "custom/path/to/credentials"), "utf8");
expect(mockReadFile).toHaveBeenCalledWith(join(homedir(), "custom/path/to/config"), "utf8");
});
});

0 comments on commit 2db465a

Please sign in to comment.