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
Expand Up @@ -130,7 +130,7 @@ describe(resolveAssumeRoleCredentials.name, () => {

it("dynamically loads STS if roleAssumer is not available in options", async () => {
const inputOptions = { ...mockOptions, roleAssumer: undefined };
await resolveAssumeRoleCredentials(mockProfileName, mockProfiles, inputOptions);
await resolveAssumeRoleCredentials(mockProfileName, mockProfiles, inputOptions, {}, resolveProfileData);
expect(inputOptions.roleAssumer).toBeDefined();
});

Expand All @@ -146,9 +146,15 @@ describe(resolveAssumeRoleCredentials.name, () => {
);

try {
await resolveAssumeRoleCredentials(mockProfileCurrent, mockProfilesWithCycle, mockOptions, {
mockProfileName: true,
});
await resolveAssumeRoleCredentials(
mockProfileCurrent,
mockProfilesWithCycle,
mockOptions,
{
mockProfileName: true,
},
resolveProfileData
);
fail(`expected ${expectedError}`);
} catch (error) {
expect(error).toStrictEqual(expectedError);
Expand All @@ -168,7 +174,13 @@ describe(resolveAssumeRoleCredentials.name, () => {
},
};

const receivedCreds = await resolveAssumeRoleCredentials(mockProfileCurrent, mockProfilesWithSource, mockOptions);
const receivedCreds = await resolveAssumeRoleCredentials(
mockProfileCurrent,
mockProfilesWithSource,
mockOptions,
{},
resolveProfileData
);
expect(receivedCreds).toStrictEqual(mockCreds);
expect(resolveProfileData).toHaveBeenCalledWith(
mockProfileName,
Expand All @@ -192,7 +204,13 @@ describe(resolveAssumeRoleCredentials.name, () => {
const mockRoleAssumeParams = getMockRoleAssumeParams();
const mockProfilesWithCredSource = getMockProfilesWithCredSource(mockRoleAssumeParams);

const receivedCreds = await resolveAssumeRoleCredentials(mockProfileName, mockProfilesWithCredSource, mockOptions);
const receivedCreds = await resolveAssumeRoleCredentials(
mockProfileName,
mockProfilesWithCredSource,
mockOptions,
{},
resolveProfileData
);
expect(receivedCreds).toStrictEqual(mockCreds);
expect(resolveProfileData).not.toHaveBeenCalled();
expect(resolveCredentialSource).toHaveBeenCalledWith(mockCredentialSource, mockProfileName, undefined);
Expand All @@ -211,7 +229,13 @@ describe(resolveAssumeRoleCredentials.name, () => {
const mockRoleAssumeParams = { ...getMockRoleAssumeParams(), role_session_name: undefined };
const mockProfilesWithCredSource = getMockProfilesWithCredSource(mockRoleAssumeParams);

const receivedCreds = await resolveAssumeRoleCredentials(mockProfileName, mockProfilesWithCredSource, mockOptions);
const receivedCreds = await resolveAssumeRoleCredentials(
mockProfileName,
mockProfilesWithCredSource,
mockOptions,
{},
resolveProfileData
);
expect(receivedCreds).toStrictEqual(mockCreds);
expect(mockOptions.roleAssumer).toHaveBeenCalledWith(mockSourceCredsFromCredential, {
RoleArn: mockRoleAssumeParams.role_arn,
Expand All @@ -234,10 +258,16 @@ describe(resolveAssumeRoleCredentials.name, () => {
false
);
try {
await resolveAssumeRoleCredentials(mockProfileName, mockProfilesWithCredSource, {
...mockOptions,
mfaCodeProvider: undefined,
});
await resolveAssumeRoleCredentials(
mockProfileName,
mockProfilesWithCredSource,
{
...mockOptions,
mfaCodeProvider: undefined,
},
{},
resolveProfileData
);
fail(`expected ${expectedError}`);
} catch (error) {
expect(error).toStrictEqual(expectedError);
Expand All @@ -256,7 +286,13 @@ describe(resolveAssumeRoleCredentials.name, () => {
const mockTokenCode = "mockTokenCode";
mockOptions.mfaCodeProvider.mockResolvedValue(mockTokenCode);

const receivedCreds = await resolveAssumeRoleCredentials(mockProfileName, mockProfilesWithCredSource, mockOptions);
const receivedCreds = await resolveAssumeRoleCredentials(
mockProfileName,
mockProfilesWithCredSource,
mockOptions,
{},
resolveProfileData
);
expect(receivedCreds).toStrictEqual(mockCreds);
expect(mockOptions.roleAssumer).toHaveBeenCalledWith(mockSourceCredsFromCredential, {
RoleArn: mockRoleAssumeParams.role_arn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AwsCredentialIdentity, IniSection, Logger, ParsedIniData, Profile } fro

import { FromIniInit } from "./fromIni";
import { resolveCredentialSource } from "./resolveCredentialSource";
import { resolveProfileData } from "./resolveProfileData";
import type { ResolveProfileData } from "./resolveProfileData";

/**
* @internal
Expand Down Expand Up @@ -104,7 +104,8 @@ export const resolveAssumeRoleCredentials = async (
profileName: string,
profiles: ParsedIniData,
options: FromIniInit,
visitedProfiles: Record<string, true> = {}
visitedProfiles: Record<string, true> = {},
resolveProfileData: ResolveProfileData
) => {
options.logger?.debug("@aws-sdk/credential-provider-ini - resolveAssumeRoleCredentials (STS)");
const profileData = profiles[profileName];
Expand Down
20 changes: 16 additions & 4 deletions packages/credential-provider-ini/src/resolveProfileData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,29 @@ describe(resolveProfileData.name, () => {
vi.mocked(resolveAssumeRoleCredentials).mockImplementation(() => Promise.resolve(mockCreds));
const receivedCreds = await resolveProfileData(mockProfileName, mockProfiles, mockOptions);
expect(receivedCreds).toStrictEqual(mockCreds);
expect(resolveAssumeRoleCredentials).toHaveBeenCalledWith(mockProfileName, mockProfiles, mockOptions, {});
expect(resolveAssumeRoleCredentials).toHaveBeenCalledWith(
mockProfileName,
mockProfiles,
mockOptions,
{},
resolveProfileData
);
});

it("when it's not static creds, and profiles are visited", async () => {
(isStaticCredsProfile as unknown as any).mockReturnValue(false);
vi.mocked(resolveAssumeRoleCredentials).mockImplementation(() => Promise.resolve(mockCreds));
const receivedCreds = await resolveProfileData(mockProfileName, mockProfiles, mockOptions, { testProfile: true });
expect(receivedCreds).toStrictEqual(mockCreds);
expect(resolveAssumeRoleCredentials).toHaveBeenCalledWith(mockProfileName, mockProfiles, mockOptions, {
testProfile: true,
});
expect(resolveAssumeRoleCredentials).toHaveBeenCalledWith(
mockProfileName,
mockProfiles,
mockOptions,
{
testProfile: true,
},
resolveProfileData
);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { isSsoProfile, resolveSsoCredentials } from "./resolveSsoCredentials";
import { isStaticCredsProfile, resolveStaticCredentials } from "./resolveStaticCredentials";
import { isWebIdentityProfile, resolveWebIdentityCredentials } from "./resolveWebIdentityCredentials";

/**
* @internal
*/
export type ResolveProfileData = typeof resolveProfileData;

/**
* @internal
*/
Expand Down Expand Up @@ -37,7 +42,7 @@ export const resolveProfileData = async (
// If this is the first profile visited, role assumption keys should be
// given precedence over static credentials.
if (isAssumeRoleRecursiveCall || isAssumeRoleProfile(data, { profile: profileName, logger: options.logger })) {
return resolveAssumeRoleCredentials(profileName, profiles, options, visitedProfiles);
return resolveAssumeRoleCredentials(profileName, profiles, options, visitedProfiles, resolveProfileData);
}

// If no role assumption metadata is present, attempt to load static
Expand Down
2 changes: 1 addition & 1 deletion scripts/compilation/Inliner.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ module.exports = class Inliner {
For that reason let's avoid them.
*/
if (warning.code === "CIRCULAR_DEPENDENCY") {
// throw Error(warning.message);
throw Error(warning.message);
}
},
external: (id) => {
Expand Down
Loading