vault/ui/tests/integration/components/keymgmt/distribute-test.js
Jordan Reimer d4766766f2
Ember Upgrade to 4.4 (#17086)
* runs ember-cli-update to 4.4.0

* updates yarn.lock

* updates dependencies causing runtime errors (#17135)

* Inject Store Service When Accessed Implicitly (#17345)

* adds codemod for injecting store service

* adds custom babylon parser with decorators-legacy plugin for jscodeshift transforms

* updates inject-store-service codemod to only look for .extend object expressions and adds recast options

* runs inject-store-service codemod on js files

* replace query-params helper with hash (#17404)

* Updates/removes dependencies throwing errors in Ember 4.4 (#17396)

* updates ember-responsive to latest

* updates ember-composable-helpers to latest and uses includes helper since contains was removed

* updates ember-concurrency to latest

* updates ember-cli-clipboard to latest

* temporary workaround for toolbar-link component throwing errors for using params arg with LinkTo

* adds missing store injection to auth configure route

* fixes issue with string-list component throwing error for accessing prop in same computation

* fixes non-iterable query params issue in mfa methods controller

* refactors field-to-attrs to handle belongsTo rather than fragments

* converts mount-config fragment to belongsTo on auth-method model

* removes ember-api-actions and adds tune method to auth-method adapter

* converts cluster replication attributes from fragment to relationship

* updates ember-data, removes ember-data-fragments and updates yarn to latest

* removes fragments from secret-engine model

* removes fragment from test-form-model

* removes commented out code

* minor change to inject-store-service codemod and runs again on js files

* Remove LinkTo positional params (#17421)

* updates ember-cli-page-object to latest version

* update toolbar-link to support link-to args and not positional params

* adds replace arg to toolbar-link component

* Clean up js lint errors (#17426)

* replaces assert.equal to assert.strictEqual

* update eslint no-console to error and disables invididual intended uses of console

* cleans up hbs lint warnings (#17432)

* Upgrade bug and test fixes (#17500)

* updates inject-service codemod to take arg for service name and runs for flashMessages service

* fixes hbs lint error after merging main

* fixes flash messages

* updates more deps

* bug fixes

* test fixes

* updates ember-cli-content-security-policy and prevents default form submission throwing errors

* more bug and test fixes

* removes commented out code

* fixes issue with code-mirror modifier sending change event on setup causing same computation error

* Upgrade Clean Up (#17543)

* updates deprecation workflow and filter

* cleans up build errors, removes unused ivy-codemirror and sass and updates ember-cli-sass and node-sass to latest

* fixes control groups test that was skipped after upgrade

* updates control group service tests

* addresses review feedback

* updates control group service handleError method to use router.currentURL rather that transition.intent.url

* adds changelog entry
2022-10-18 09:46:02 -06:00

171 lines
6.4 KiB
JavaScript

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import Pretender from 'pretender';
import { render, settled, select } from '@ember/test-helpers';
import { create } from 'ember-cli-page-object';
import { hbs } from 'ember-cli-htmlbars';
import { typeInSearch, clickTrigger } from 'ember-power-select/test-support/helpers';
import searchSelect from '../../../pages/components/search-select';
const SELECTORS = {
form: '[data-test-keymgmt-distribution-form]',
keySection: '[data-test-keymgmt-dist-key]',
keyTypeSection: '[data-test-keymgmt-dist-keytype]',
providerInput: '[data-test-keymgmt-dist-provider]',
operationsSection: '[data-test-keymgmt-dist-operations]',
protectionsSection: '[data-test-keymgmt-dist-protections]',
errorKey: '[data-test-keymgmt-error="key"]',
errorNewKey: '[data-test-keymgmt-error="new-key"]',
errorProvider: '[data-test-keymgmt-error="provider"]',
inlineError: '[data-test-keymgmt-error]',
};
const ssComponent = create(searchSelect);
module('Integration | Component | keymgmt/distribute', function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
this.set('backend', 'keymgmt');
this.set('providers', ['provider-aws', 'provider-gcp', 'provider-azure']);
this.server = new Pretender(function () {
this.get('/v1/keymgmt/key', (response) => {
return [
response,
{ 'Content-Type': 'application/json' },
JSON.stringify({
data: {
keys: ['example-1', 'example-2', 'example-3'],
},
}),
];
});
this.get('/v1/keymgmt/key/:name', (response) => {
const name = response.params.name;
return [
response,
{ 'Content-Type': 'application/json' },
JSON.stringify({
data: {
name,
type: 'aes256-gcm96', // incompatible with azurekeyvault only
},
}),
];
});
this.get('/v1/keymgmt/kms/:name', (response) => {
const name = response.params.name;
let provider;
switch (name) {
case 'provider-aws':
provider = 'awskms';
break;
case 'provider-azure':
provider = 'azurekeyvault';
break;
default:
provider = 'gcpckms';
break;
}
return [
response,
{ 'Content-Type': 'application/json' },
JSON.stringify({
data: {
name,
provider,
},
}),
];
});
this.get('/v1/keymgmt/kms', (response) => {
return [
response,
{ 'Content-Type': 'application/json' },
JSON.stringify({
data: {
keys: ['provider-aws', 'provider-azure', 'provider-gcp'],
},
}),
];
});
});
});
hooks.afterEach(function () {
this.server.shutdown();
});
test('it does not allow operation selection until valid key/provider combo selected', async function (assert) {
assert.expect(6);
await render(
hbs`<Keymgmt::Distribute @backend="keymgmt" @key="example-1" @providers={{this.providers}} @onClose={{fn (mut this.onClose)}} />`
);
assert.dom(SELECTORS.operationsSection).hasAttribute('disabled');
// Select
await clickTrigger();
assert.strictEqual(ssComponent.options.length, 3, 'shows all provider options');
await typeInSearch('aws');
await ssComponent.selectOption();
await settled();
assert.dom(SELECTORS.operationsSection).doesNotHaveAttribute('disabled');
// Remove selection
await ssComponent.deleteButtons.objectAt(0).click();
// Select Azure
await clickTrigger();
await typeInSearch('azure');
await ssComponent.selectOption();
// await select(SELECTORS.providerInput, 'provider-azure');
assert.dom(SELECTORS.operationsSection).hasAttribute('disabled');
assert.dom(SELECTORS.inlineError).exists({ count: 1 }, 'only shows single error');
assert.dom(SELECTORS.errorProvider).exists('Shows key/provider match error on provider');
});
test('it shows key type select field if new key created', async function (assert) {
assert.expect(2);
await render(
hbs`<Keymgmt::Distribute @backend="keymgmt" @providers={{this.providers}} @onClose={{fn (mut this.onClose)}} />`
);
assert.dom(SELECTORS.keyTypeSection).doesNotExist('Key Type section is not rendered by default');
// Add new item on search-select
await clickTrigger();
await typeInSearch('new-key');
await ssComponent.selectOption();
assert.dom(SELECTORS.keyTypeSection).exists('Key Type selector is shown');
});
test('it hides the provider field if passed from the parent', async function (assert) {
assert.expect(5);
await render(
hbs`<Keymgmt::Distribute @backend="keymgmt" @provider="provider-azure" @onClose={{fn (mut this.onClose)}} />`
);
assert.dom(SELECTORS.providerInput).doesNotExist('Provider input is hidden');
// Select existing key
await clickTrigger();
await ssComponent.selectOption();
await settled();
assert.dom(SELECTORS.inlineError).exists({ count: 1 }, 'only shows single error');
assert.dom(SELECTORS.errorKey).exists('Shows error on key selector when key/provider mismatch');
// Remove selection
await ssComponent.deleteButtons.objectAt(0).click();
// Select new key
await clickTrigger();
await typeInSearch('new-key');
await ssComponent.selectOption();
await select(SELECTORS.keyTypeSection, 'ecdsa-p256');
assert.dom(SELECTORS.inlineError).exists({ count: 1 }, 'only shows single error');
assert.dom(SELECTORS.errorNewKey).exists('Shows error on key type');
});
test('it hides the key field if passed from the parent', async function (assert) {
assert.expect(4);
await render(
hbs`<Keymgmt::Distribute @backend="keymgmt" @providers={{this.providers}} @key="example-1" @onClose={{fn (mut this.onClose)}} />`
);
assert.dom(SELECTORS.providerInput).exists('Provider input shown');
assert.dom(SELECTORS.keySection).doesNotExist('Key input not shown');
await clickTrigger();
await typeInSearch('azure');
await ssComponent.selectOption();
assert.dom(SELECTORS.inlineError).exists({ count: 1 }, 'only shows single error');
assert.dom(SELECTORS.errorProvider).exists('Shows error due to key/provider mismatch');
});
});