Skip to content

Commit

Permalink
fix(VpcInstanceAuthenticator): omit request body for default profile …
Browse files Browse the repository at this point in the history
…scenario (#181)
  • Loading branch information
padamstx authored Dec 8, 2021
1 parent 4d31951 commit 1e3fb2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
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

0 comments on commit 1e3fb2d

Please sign in to comment.