vault/ui/tests/unit/adapters/aws-credential-test.js
hashicorp-copywrite[bot] 0b12cdcfd1
[COMPLIANCE] License changes (#22290)
* Adding explicit MPL license for sub-package.

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Adding explicit MPL license for sub-package.

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Updating the license from MPL to Business Source License.

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl.

* add missing license headers

* Update copyright file headers to BUS-1.1

* Fix test that expected exact offset on hcl file

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Sarah Thompson <sthompson@hashicorp.com>
Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
2023-08-10 18:14:03 -07:00

90 lines
2.4 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import apiStub from 'vault/tests/helpers/noop-all-api-requests';
module('Unit | Adapter | aws credential', function (hooks) {
setupTest(hooks);
hooks.beforeEach(function () {
this.server = apiStub();
});
hooks.afterEach(function () {
this.server.shutdown();
});
const storeStub = {
pushPayload() {},
serializerFor() {
return {
serializeIntoHash() {},
};
},
};
const makeSnapshot = (obj) => {
obj.role = {
backend: 'aws',
name: 'foo',
};
obj.attr = (attr) => obj[attr];
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]) => {
test(`aws-credential: ${description}`, function (assert) {
assert.expect(3);
const adapter = this.owner.lookup('adapter:aws-credential');
adapter.createRecord(...args);
const { method, url, requestBody } = this.server.handledRequests[0];
assert.strictEqual(url, '/v1/aws/creds/foo', `calls the correct url`);
assert.strictEqual(
method,
expectedMethod,
`${description} uses the correct http verb: ${expectedMethod}`
);
assert.strictEqual(requestBody, expectedRequestBody ? JSON.stringify(expectedRequestBody) : null);
});
});
});