2018-09-28 21:45:30 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupTest } from 'ember-qunit';
|
|
|
|
import apiStub from 'vault/tests/helpers/noop-all-api-requests';
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Unit | Adapter | aws credential', function (hooks) {
|
2018-09-28 21:45:30 +00:00
|
|
|
setupTest(hooks);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
hooks.beforeEach(function () {
|
2018-09-28 21:45:30 +00:00
|
|
|
this.server = apiStub();
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
hooks.afterEach(function () {
|
2018-09-28 21:45:30 +00:00
|
|
|
this.server.shutdown();
|
|
|
|
});
|
|
|
|
|
|
|
|
const storeStub = {
|
|
|
|
pushPayload() {},
|
|
|
|
serializerFor() {
|
|
|
|
return {
|
|
|
|
serializeIntoHash() {},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
let makeSnapshot = (obj) => {
|
2018-09-28 21:45:30 +00:00
|
|
|
obj.role = {
|
|
|
|
backend: 'aws',
|
|
|
|
name: 'foo',
|
|
|
|
};
|
2021-12-17 03:44:29 +00:00
|
|
|
obj.attr = (attr) => obj[attr];
|
2018-09-28 21:45:30 +00:00
|
|
|
return obj;
|
|
|
|
};
|
|
|
|
|
|
|
|
const type = {
|
|
|
|
modelName: 'aws-credential',
|
|
|
|
};
|
|
|
|
|
|
|
|
const cases = [
|
|
|
|
['iam_user type', [storeStub, type, makeSnapshot({ credentialType: 'iam_user', ttl: '3h' })], 'GET'],
|
|
|
|
[
|
|
|
|
'federation_token type with ttl',
|
|
|
|
[storeStub, type, makeSnapshot({ credentialType: 'federation_token', ttl: '3h', roleArn: 'arn' })],
|
|
|
|
'POST',
|
|
|
|
{ ttl: '3h' },
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'federation_token type no ttl',
|
|
|
|
[storeStub, type, makeSnapshot({ credentialType: 'federation_token', roleArn: 'arn' })],
|
|
|
|
'POST',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'assumed_role type no arn, no ttl',
|
|
|
|
[storeStub, type, makeSnapshot({ credentialType: 'assumed_role' })],
|
|
|
|
'POST',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'assumed_role type no arn',
|
|
|
|
[storeStub, type, makeSnapshot({ credentialType: 'assumed_role', ttl: '3h' })],
|
|
|
|
'POST',
|
|
|
|
{ ttl: '3h' },
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'assumed_role type',
|
|
|
|
[storeStub, type, makeSnapshot({ credentialType: 'assumed_role', roleArn: 'arn', ttl: '3h' })],
|
|
|
|
'POST',
|
|
|
|
{ ttl: '3h', role_arn: 'arn' },
|
|
|
|
],
|
|
|
|
];
|
|
|
|
cases.forEach(([description, args, expectedMethod, expectedRequestBody]) => {
|
2021-12-17 03:44:29 +00:00
|
|
|
test(`aws-credential: ${description}`, function (assert) {
|
2018-09-28 21:45:30 +00:00
|
|
|
assert.expect(3);
|
|
|
|
let adapter = this.owner.lookup('adapter:aws-credential');
|
|
|
|
adapter.createRecord(...args);
|
|
|
|
let { method, url, requestBody } = this.server.handledRequests[0];
|
|
|
|
assert.equal(url, '/v1/aws/creds/foo', `calls the correct url`);
|
|
|
|
assert.equal(method, expectedMethod, `${description} uses the correct http verb: ${expectedMethod}`);
|
|
|
|
assert.equal(requestBody, JSON.stringify(expectedRequestBody));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|