Skip to content

Commit

Permalink
test: add scenario in credential chain integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed May 30, 2024
1 parent dced10c commit 6355890
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { STS } from "@aws-sdk/client-sts";
import * as credentialProviderHttp from "@aws-sdk/credential-provider-http";
import { HttpResponse } from "@smithy/protocol-http";
import type { SourceProfileInit } from "@smithy/shared-ini-file-loader";
import type { HttpRequest, NodeHttpHandlerOptions, ParsedIniData } from "@smithy/types";
Expand Down Expand Up @@ -490,6 +491,44 @@ describe("credential-provider-node integration test", () => {
credentialScope: "us-sso-1-us-sso-region-1",
});
});

it("should be able to combine a source_profile having credential_source with an origin profile having role_arn and source_profile", async () => {
process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI = "http://169.254.170.23";
process.env.AWS_CONTAINER_AUTHORIZATION_TOKEN = "container-authorization";
iniProfileData.default.source_profile = "credential_source_profile";
iniProfileData.default.role_arn = "ROLE_ARN";
iniProfileData.credential_source_profile = {
credential_source: "EcsContainer",
};
const spy = jest.spyOn(credentialProviderHttp, "fromHttp");
sts = new STS({
region: "us-west-2",
requestHandler: mockRequestHandler,
credentials: defaultProvider({
awsContainerCredentialsFullUri: process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI,
awsContainerAuthorizationToken: process.env.AWS_CONTAINER_AUTHORIZATION_TOKEN,
clientConfig: {
region: "us-west-2",
},
}),
});
await sts.getCallerIdentity({});
const credentials = await sts.config.credentials();
expect(credentials).toEqual({
accessKeyId: "STS_AR_ACCESS_KEY_ID",
secretAccessKey: "STS_AR_SECRET_ACCESS_KEY",
sessionToken: "STS_AR_SESSION_TOKEN",
expiration: new Date("3000-01-01T00:00:00.000Z"),
credentialScope: "us-stsar-1__us-west-2",
});
expect(spy).toHaveBeenCalledWith(
expect.objectContaining({
awsContainerCredentialsFullUri: process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI,
awsContainerAuthorizationToken: process.env.AWS_CONTAINER_AUTHORIZATION_TOKEN,
})
);
spy.mockClear();
});
});

describe("fromProcess", () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/credential-provider-node/src/defaultProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fromEnv } from "@aws-sdk/credential-provider-env";
import type { FromHttpOptions } from "@aws-sdk/credential-provider-http";
import type { FromIniInit } from "@aws-sdk/credential-provider-ini";
import type { FromProcessInit } from "@aws-sdk/credential-provider-process";
import type { FromSSOInit, SsoCredentialsParameters } from "@aws-sdk/credential-provider-sso";
Expand All @@ -14,6 +15,7 @@ import { remoteProvider } from "./remoteProvider";
* @public
*/
export type DefaultProviderInit = FromIniInit &
FromHttpOptions &
RemoteProviderInit &
FromProcessInit &
(FromSSOInit & Partial<SsoCredentialsParameters>) &
Expand Down
5 changes: 4 additions & 1 deletion packages/credential-provider-node/src/remoteProvider.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { FromHttpOptions } from "@aws-sdk/credential-provider-http";
import type { RemoteProviderInit } from "@smithy/credential-provider-imds";
import { chain, CredentialsProviderError } from "@smithy/property-provider";
import type { AwsCredentialIdentityProvider } from "@smithy/types";
Expand All @@ -10,7 +11,9 @@ export const ENV_IMDS_DISABLED = "AWS_EC2_METADATA_DISABLED";
/**
* @internal
*/
export const remoteProvider = async (init: RemoteProviderInit): Promise<AwsCredentialIdentityProvider> => {
export const remoteProvider = async (
init: RemoteProviderInit | FromHttpOptions
): Promise<AwsCredentialIdentityProvider> => {
const { ENV_CMDS_FULL_URI, ENV_CMDS_RELATIVE_URI, fromContainerMetadata, fromInstanceMetadata } = await import(
"@smithy/credential-provider-imds"
);
Expand Down

0 comments on commit 6355890

Please sign in to comment.