Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(VpcInstanceAuthenticator): omit request body for default profile scenario #181

Merged
merged 1 commit into from
Dec 8, 2021
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
10 changes: 7 additions & 3 deletions auth/token-managers/vpc-instance-token-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,15 @@ export class VpcInstanceTokenManager extends JwtTokenManager {
const instanceIdentityToken: string = await this.getInstanceIdentityToken();

// construct request body
const body = {} as CreateIamTokenBody;
let body: CreateIamTokenBody;
if (this.iamProfileId) {
body.trusted_profile = { id: this.iamProfileId };
body = {
trusted_profile: { id: this.iamProfileId },
};
} else if (this.iamProfileCrn) {
body.trusted_profile = { crn: this.iamProfileCrn };
body = {
trusted_profile: { crn: this.iamProfileCrn },
};
}

const parameters = {
Expand Down
7 changes: 3 additions & 4 deletions test/unit/vpc-instance-token-manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('VPC Instance Token Manager', () => {
});

describe('constructor', () => {
it('should throw an error when both `iamProfileId` are `iamProfileCrn` are provided', () => {
it('should throw an error when both `iamProfileId` and `iamProfileCrn` are provided', () => {
expect(
() =>
new VpcInstanceTokenManager({
Expand Down Expand Up @@ -161,9 +161,8 @@ describe('VPC Instance Token Manager', () => {
expect(parameters.options.qs).toBeDefined();
expect(parameters.options.qs.version).toBe('2021-09-20');

expect(parameters.options.body).toBeDefined();
// if neither the profile id or crn is set, this should be undefined
expect(parameters.options.body.trusted_profile).toBeUndefined();
// if neither the profile id or crn is set, then the body should be undefined
expect(parameters.options.body).toBeUndefined();

expect(parameters.options.headers).toBeDefined();
expect(parameters.options.headers['Content-Type']).toBe('application/json');
Expand Down