-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(credential-providers): integration test for 'read config files f…
…rom paths relative to homedir' (#6210)
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testMatch: ["**/*.integ.spec.ts"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); |