Skip to content

Commit

Permalink
Updated objects with message to throw errors
Browse files Browse the repository at this point in the history
Example test failure on updating jest:
Expected value to match object:
  {"message": "Profile default could not be found or parsed in shared credentials file."}
Received:
  [Error: Profile default could not be found or parsed in shared credentials file.]
  • Loading branch information
trivikr committed Dec 10, 2018
1 parent cb81ff6 commit 0066bf4
Showing 1 changed file with 45 additions and 35 deletions.
80 changes: 45 additions & 35 deletions packages/credential-provider-ini/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ afterAll(() => {

describe('fromIni', () => {
it('should flag a lack of credentials as a non-terminal error', () => {
return expect(fromIni()()).rejects.toMatchObject({
message: 'Profile default could not be found or parsed in shared credentials file.',
tryNextLink: true,
});
return expect(fromIni()()).rejects.toMatchObject(
new Error(
'Profile default could not be found or parsed in shared credentials file.'
)
);
});

describe('shared credentials file', () => {
Expand Down Expand Up @@ -540,10 +541,11 @@ role_arn = arn:aws:iam::123456789:role/foo
source_profile = bar`.trim()
);

return expect(fromIni({profile: 'foo'})()).rejects.toMatchObject({
message: 'Profile foo requires a role to be assumed, but no role assumption callback was provided.',
tryNextLink: false,
});
return expect(fromIni({profile: 'foo'})()).rejects.toMatchObject(
new Error(
'Profile foo requires a role to be assumed, but no role assumption callback was provided.'
)
);
}
);

Expand All @@ -566,10 +568,11 @@ source_profile = bar`.trim()
roleAssumer: jest.fn()
});

return expect(provider()).rejects.toMatchObject({
message: 'Profile bar could not be found or parsed in shared credentials file.',
tryNextLink: true,
});
return expect(provider()).rejects.toMatchObject(
new Error(
'Profile bar could not be found or parsed in shared credentials file.'
)
);
}
);

Expand Down Expand Up @@ -768,10 +771,11 @@ source_profile = default`.trim()
roleAssumer: () => Promise.resolve(FOO_CREDS),
});

return expect(provider()).rejects.toMatchObject({
message: 'Profile foo requires multi-factor authentication, but no MFA code callback was provided.',
tryNextLink: false,
});
return expect(provider()).rejects.toMatchObject(
new Error(
'Profile foo requires multi-factor authentication, but no MFA code callback was provided.'
)
);
}
);
});
Expand Down Expand Up @@ -801,10 +805,11 @@ aws_session_token = ${FOO_CREDS.sessionToken}`.trim());
aws_secret_access_key = ${DEFAULT_CREDS.secretAccessKey}
`.trim());

return expect(fromIni()()).rejects.toMatchObject({
message: 'Profile default could not be found or parsed in shared credentials file.',
tryNextLink: true,
});
return expect(fromIni()()).rejects.toMatchObject(
new Error(
'Profile default could not be found or parsed in shared credentials file.'
)
);
});

it('should reject credentials with no secret key', () => {
Expand All @@ -813,10 +818,11 @@ aws_secret_access_key = ${DEFAULT_CREDS.secretAccessKey}
aws_access_key_id = ${DEFAULT_CREDS.accessKeyId}
`.trim());

return expect(fromIni()()).rejects.toMatchObject({
message: 'Profile default could not be found or parsed in shared credentials file.',
tryNextLink: true,
});
return expect(fromIni()()).rejects.toMatchObject(
new Error(
'Profile default could not be found or parsed in shared credentials file.'
)
);
});

it('should not merge profile values together', () => {
Expand All @@ -830,10 +836,11 @@ aws_access_key_id = ${DEFAULT_CREDS.accessKeyId}
aws_secret_access_key = ${FOO_CREDS.secretAccessKey}
`.trim());

return expect(fromIni()()).rejects.toMatchObject({
message: 'Profile default could not be found or parsed in shared credentials file.',
tryNextLink: true,
});
return expect(fromIni()()).rejects.toMatchObject(
new Error(
'Profile default could not be found or parsed in shared credentials file.'
)
);
});

it(
Expand Down Expand Up @@ -960,19 +967,22 @@ source_profile = fizz
`.trim());
const provider = fromIni({roleAssumer: jest.fn()});

return expect(provider()).rejects.toMatchObject({
message: 'Detected a cycle attempting to resolve credentials for profile default. Profiles visited: foo, bar, baz, fizz',
tryNextLink: false,
});
return expect(provider()).rejects.toMatchObject(
new Error(
'Detected a cycle attempting to resolve credentials for profile default. Profiles visited: foo, bar, baz, fizz'
)
);
}
);

it(
'should not attempt to load from disk if loaded credentials are provided',
async () => {
await expect(fromIni()()).rejects.toMatchObject({
message: 'Profile default could not be found or parsed in shared credentials file.'
});
await expect(fromIni()()).rejects.toMatchObject(
new Error(
'Profile default could not be found or parsed in shared credentials file.'
)
);

const params = {
loadedConfig: Promise.resolve({
Expand Down

0 comments on commit 0066bf4

Please sign in to comment.