AWS test prep for WIF work (#28069)

* add test coverage and clean up selectors

* remove

* small clean up

* select things
This commit is contained in:
Angel Garbarino
2024-08-13 16:22:09 -06:00
committed by GitHub
parent 1b1f22192a
commit 8eb7595304
6 changed files with 139 additions and 39 deletions

View File

@@ -16,7 +16,7 @@
"saveRootCreds"
(hash access_key=@accessKey iam_endpoint=@iamEndpoint sts_endpoint=@stsEndpoint secret_key=@secretKey region=@region)
}}
data-test-aws-root-creds-form="true"
data-test-root-form
aria-label="save root creds form"
>
<div class="box is-fullwidth is-shadowless is-marginless">
@@ -61,7 +61,11 @@
</div>
</div>
<ToggleButton @isOpen={{this.showOptions}} @onClick={{fn (mut this.showOptions)}} data-test-popup-menu-trigger />
<ToggleButton
@isOpen={{this.showOptions}}
@onClick={{fn (mut this.showOptions)}}
data-test-toggle-group="Root config options"
/>
{{#if this.showOptions}}
<div class="box is-marginless">
<div class="field">
@@ -104,7 +108,7 @@
{{/if}}
<div class="box is-bottomless is-fullwidth">
<Hds::Button @text="Save" data-test-save="root" type="submit" />
<Hds::Button @text="Save" data-test-save-root-config type="submit" />
</div>
</form>
</T.Panel>
@@ -112,7 +116,7 @@
<form
onsubmit={{action "saveLease" (hash lease=@model.lease lease_max=@model.leaseMax)}}
aria-label="save lease form"
data-test-aws-leases-form="true"
data-test-lease-form
>
<div class="box is-fullwidth is-shadowless is-marginless">
<NamespaceReminder @mode="saved" @noun="configuration" />
@@ -134,7 +138,7 @@
@onChange={{fn this.handleTtlChange "leaseMax"}}
/>
<div class="box is-bottomless is-fullwidth">
<Hds::Button @text="Save" data-test-save="lease" type="submit" />
<Hds::Button @text="Save" data-test-save-lease-config type="submit" />
</div>
</form>
</T.Panel>

View File

@@ -21,6 +21,7 @@ import {
expectedConfigKeys,
expectedValueOfConfigKeys,
configUrl,
fillInAwsConfig,
} from 'vault/tests/helpers/secret-engine/secret-engine-helpers';
module('Acceptance | aws | configuration', function (hooks) {
@@ -51,7 +52,7 @@ module('Acceptance | aws | configuration', function (hooks) {
await runCmd(`delete sys/mounts/${path}`);
});
test('it should transition to configure page on Configure click from toolbar', async function (assert) {
test('it should transition to configure page on click "Configure" from toolbar', async function (assert) {
const path = `aws-${this.uid}`;
await enablePage.enable('aws', path);
await click(SES.configTab);
@@ -77,15 +78,12 @@ module('Acceptance | aws | configuration', function (hooks) {
});
test('it should save root AWS configuration', async function (assert) {
assert.expect(3);
const path = `aws-${this.uid}`;
await enablePage.enable('aws', path);
await click(SES.configTab);
await click(SES.configure);
await fillIn(GENERAL.inputByAttr('accessKey'), 'foo');
await fillIn(GENERAL.inputByAttr('secretKey'), 'bar');
await click(GENERAL.saveButtonId('root'));
await fillInAwsConfig();
await click(SES.aws.saveRootConfig);
assert.true(
this.flashSuccessSpy.calledWith('The backend configuration saved successfully!'),
'Success flash message is rendered'
@@ -101,26 +99,21 @@ module('Acceptance | aws | configuration', function (hooks) {
});
test('it should save lease AWS configuration', async function (assert) {
assert.expect(3);
const path = `aws-${this.uid}`;
await enablePage.enable('aws', path);
await click(SES.configTab);
await click(SES.configure);
await click(GENERAL.hdsTab('lease'));
await click(GENERAL.toggleInput('Lease'));
await fillIn(GENERAL.ttl.input('Lease'), '55');
await click(GENERAL.toggleInput('Maximum Lease'));
await fillIn(GENERAL.ttl.input('Maximum Lease'), '65');
await click(GENERAL.saveButtonId('lease'));
await fillInAwsConfig(false, false, true); // only fills in lease config with defaults
await click(SES.aws.saveLeaseConfig);
assert.true(
this.flashSuccessSpy.calledWith('The backend configuration saved successfully!'),
'Success flash message is rendered'
);
await visit(`/vault/secrets/${path}/configuration`);
assert.dom(GENERAL.infoRowValue('Default Lease TTL')).hasText('55s', `Default TTL has been set.`);
assert.dom(GENERAL.infoRowValue('Max Lease TTL')).hasText('1m5s', `Default TTL has been set.`);
assert.dom(GENERAL.infoRowValue('Default Lease TTL')).hasText('33s', `Default TTL has been set.`);
assert.dom(GENERAL.infoRowValue('Max Lease TTL')).hasText('44s', `Max lease TTL has been set.`);
// cleanup
await runCmd(`delete sys/mounts/${path}`);
});
@@ -154,7 +147,6 @@ module('Acceptance | aws | configuration', function (hooks) {
});
test('it should update AWS configuration details after editing', async function (assert) {
assert.expect(6);
const path = `aws-${this.uid}`;
const type = 'aws';
await enablePage.enable(type, path);
@@ -162,7 +154,7 @@ module('Acceptance | aws | configuration', function (hooks) {
await click(SES.configTab);
await click(SES.configure);
await fillIn(GENERAL.inputByAttr('accessKey'), 'foo');
await click(GENERAL.saveButtonId('root'));
await click(SES.aws.saveRootConfig);
await click(SES.viewBackend);
await click(SES.configTab);
assert.dom(GENERAL.infoRowValue('Access key')).hasText('foo', 'Access key is foo');
@@ -172,23 +164,18 @@ module('Acceptance | aws | configuration', function (hooks) {
// edit root config details and lease config details and confirm the configuration.index page is updated.
await click(SES.configure);
await fillIn(GENERAL.inputByAttr('accessKey'), 'hello');
await click(GENERAL.menuTrigger);
await fillIn(GENERAL.selectByAttr('region'), 'ca-central-1');
await click(GENERAL.saveButtonId('root'));
await click(GENERAL.toggleGroup('Root config options'));
await fillIn(GENERAL.selectByAttr('region'), 'ap-southeast-2');
await click(SES.aws.saveRootConfig);
// add lease config details
await click(GENERAL.hdsTab('lease'));
await click(GENERAL.toggleInput('Lease'));
await fillIn(GENERAL.ttl.input('Lease'), '33');
await click(GENERAL.toggleInput('Maximum Lease'));
await fillIn(GENERAL.ttl.input('Maximum Lease'), '43');
await click(GENERAL.saveButtonId('lease'));
await fillInAwsConfig(false, false, true); // only fills in lease config with defaults
await click(SES.aws.saveLeaseConfig);
await click(SES.viewBackend);
await click(SES.configTab);
assert.dom(GENERAL.infoRowValue('Access key')).hasText('hello', 'Access key has been updated to hello');
assert.dom(GENERAL.infoRowValue('Region')).hasText('ca-central-1', 'Region has been added');
assert.dom(GENERAL.infoRowValue('Region')).hasText('ap-southeast-2', 'Region has been added');
assert.dom(GENERAL.infoRowValue('Default Lease TTL')).hasText('33s', 'Default Lease TTL has been added');
assert.dom(GENERAL.infoRowValue('Max Lease TTL')).hasText('43s', 'Max Lease TTL has been added');
assert.dom(GENERAL.infoRowValue('Max Lease TTL')).hasText('44s', 'Max Lease TTL has been added');
// cleanup
await runCmd(`delete sys/mounts/${path}`);
});

View File

@@ -97,8 +97,8 @@ module('Acceptance | aws secret backend', function (hooks) {
// delete role
await click(`${SES.secretLink(roleName)} [data-test-popup-menu-trigger]`);
await waitUntil(() => find(SES.aws.delete(roleName))); // flaky without
await click(SES.aws.delete(roleName));
await waitUntil(() => find(SES.aws.deleteRole(roleName))); // flaky without
await click(SES.aws.deleteRole(roleName));
await click(GENERAL.confirmButton);
assert.dom(SES.secretLink(roleName)).doesNotExist('aws: role is no longer in the list');
});

View File

@@ -3,6 +3,9 @@
* SPDX-License-Identifier: BUSL-1.1
*/
import { click, fillIn } from '@ember/test-helpers';
import { GENERAL } from 'vault/tests/helpers/general-selectors';
export const createSecretsEngine = (store, type, path) => {
store.pushPayload('secret-engine', {
modelName: 'secret-engine',
@@ -31,6 +34,19 @@ const createAwsRootConfig = (store, backend) => {
return store.peekRecord('aws/root-config', backend);
};
const createAwsLeaseConfig = (store, backend) => {
store.pushPayload('aws/lease-config', {
id: backend,
modelName: 'aws/lease-config',
data: {
backend: backend,
lease: '50s',
leaseMax: '55s',
},
});
return store.peekRecord('aws/lease-config', backend);
};
const createSshCaConfig = (store, backend) => {
store.pushPayload('ssh/ca-config', {
id: backend,
@@ -46,7 +62,9 @@ const createSshCaConfig = (store, backend) => {
export function configUrl(type, backend) {
switch (type) {
case 'aws':
return `${backend}/config/root`;
return `/${backend}/config/root`;
case 'aws-lease':
return `/${backend}/config/lease`;
case 'ssh':
return `/${backend}/config/ca`;
default:
@@ -58,6 +76,8 @@ export const createConfig = (store, backend, type) => {
switch (type) {
case 'aws':
return createAwsRootConfig(store, backend);
case 'aws-lease':
return createAwsLeaseConfig(store, backend);
case 'ssh':
return createSshCaConfig(store, backend);
}
@@ -104,3 +124,24 @@ export const expectedValueOfConfigKeys = (type, string) => {
return valueOfSshKeys(string);
}
};
export const fillInAwsConfig = async (withAccess = true, withAccessOptions = false, withLease = false) => {
if (withAccess) {
await fillIn(GENERAL.inputByAttr('accessKey'), 'foo');
await fillIn(GENERAL.inputByAttr('secretKey'), 'bar');
}
if (withAccessOptions) {
await click(GENERAL.toggleGroup('Root config options'));
await fillIn(GENERAL.selectByAttr('region'), 'ca-central-1');
await fillIn(GENERAL.inputByAttr('iamEndpoint'), 'iam-endpoint');
await fillIn(GENERAL.inputByAttr('stsEndpoint'), 'sts-endpoint');
await fillIn(GENERAL.inputByAttr('maxRetries'), '3');
}
await click(GENERAL.hdsTab('lease'));
if (withLease) {
await click(GENERAL.ttl.toggle('Lease'));
await fillIn(GENERAL.ttl.input('Lease'), '33');
await click(GENERAL.ttl.toggle('Maximum Lease'));
await fillIn(GENERAL.ttl.input('Maximum Lease'), '44');
}
};

View File

@@ -22,8 +22,12 @@ export const SECRET_ENGINE_SELECTORS = {
viewBackend: '[data-test-backend-view-link]',
warning: '[data-test-warning]',
aws: {
rootForm: '[data-test-aws-root-creds-form]',
delete: (role: string) => `[data-test-aws-role-delete="${role}"]`,
rootForm: '[data-test-root-form]',
leaseForm: '[data-test-lease-form]',
saveRootConfig: '[data-test-save-root-config]',
saveLeaseConfig: '[data-test-save-lease-config]',
cancelConfig: '[data-test-cancel-config]',
deleteRole: (role: string) => `[data-test-aws-role-delete="${role}"]`,
},
ssh: {
configureForm: '[data-test-configure-form]',

View File

@@ -0,0 +1,64 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import sinon from 'sinon';
import { setupRenderingTest } from 'vault/tests/helpers';
import { GENERAL } from 'vault/tests/helpers/general-selectors';
import { SECRET_ENGINE_SELECTORS as SES } from 'vault/tests/helpers/secret-engine/secret-engine-selectors';
import { render, click, fillIn } from '@ember/test-helpers';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { hbs } from 'ember-cli-htmlbars';
import { v4 as uuidv4 } from 'uuid';
import { createConfig } from 'vault/tests/helpers/secret-engine/secret-engine-helpers';
module('Integration | Component | SecretEngine/configure-aws', function (hooks) {
setupRenderingTest(hooks);
setupMirage(hooks);
hooks.beforeEach(function () {
this.store = this.owner.lookup('service:store');
this.uid = uuidv4();
this.id = `aws-${this.uid}`;
this.model = createConfig(this.store, this.id, 'aws-lease'); // currently when you queryRecord for secret-engine type aws it returns the lease/config. This is going to change in the refactor.
this.saveAWSLease = sinon.stub();
this.saveAWSRoot = sinon.stub();
this.renderComponent = () => {
return render(hbs`
<SecretEngine::ConfigureAws @model={{this.model}} @saveAWSLease={{this.saveAWSLease}} @saveAWSRoot={{this.saveAWSRoot}} @tab="root" @region="" />
`);
};
});
test('it renders fields', async function (assert) {
await this.renderComponent();
assert.dom(SES.aws.rootForm).exists('it lands on the aws root configuration form.');
assert.dom(GENERAL.inputByAttr('accessKey')).exists(`accessKey shows for Access section.`);
assert.dom(GENERAL.inputByAttr('secretKey')).exists(`secretKey shows for Access section.`);
await click(GENERAL.hdsTab('lease'));
assert.dom('[data-test-ttl-form-label="Lease"]').exists('Lease TTL is rendered');
assert.dom('[data-test-ttl-form-label="Maximum Lease"]').exists('Maximum Lease TTL is rendered');
});
test('it calls saveAWSRoot on save root config', async function (assert) {
await this.renderComponent();
await fillIn(GENERAL.inputByAttr('accessKey'), 'foo');
await fillIn(GENERAL.inputByAttr('secretKey'), 'bar');
await click(SES.aws.saveRootConfig);
assert.ok(this.saveAWSRoot.calledOnce, 'saveAWSRoot was called once');
assert.ok(this.saveAWSLease.notCalled, 'saveAWSLease was not called');
});
test('it calls saveAWSLease on save lease config', async function (assert) {
await this.renderComponent();
// createLease config already has ttls set so just save the values
await click(SES.aws.saveLeaseConfig);
assert.ok(this.saveAWSLease.calledOnce, 'saveAWSLease was called once');
assert.ok(this.saveAWSRoot.notCalled, 'saveAWSRoot was not called');
});
});