Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icu 15471 credential store tests #2663

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
8 changes: 0 additions & 8 deletions ui/admin/tests/acceptance/credential-store/create-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,6 @@ module('Acceptance | credential-stores | create', function (hooks) {
status: 400,
code: 'invalid_argument',
message: errorMsg,
details: {
request_fields: [
{
name: 'name',
description: 'Name is required.',
},
],
},
},
);
});
Expand Down
80 changes: 43 additions & 37 deletions ui/admin/tests/acceptance/credential-store/delete-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { authenticateSession } from 'ember-simple-auth/test-support';
import { Response } from 'miragejs';
import { resolve, reject } from 'rsvp';
import sinon from 'sinon';
import * as selectors from './selectors';
import * as commonSelectors from 'admin/tests/helpers/selectors';

module('Acceptance | credential-stores | delete', function (hooks) {
setupApplicationTest(hooks);
Expand All @@ -20,10 +22,6 @@ module('Acceptance | credential-stores | delete', function (hooks) {

let getStaticCredentialStoresCount;
let getVaultCredentialStoresCount;
const MANAGE_DROPDOWN_SELECTOR =
'[data-test-manage-credential-stores-dropdown] button:first-child';
const DELETE_ACTION_SELECTOR =
'[data-test-manage-credential-stores-dropdown] ul li button';

const instances = {
scopes: {
Expand All @@ -34,9 +32,6 @@ module('Acceptance | credential-stores | delete', function (hooks) {
};

const urls = {
globalScope: null,
orgScope: null,
projectScope: null,
credentialStores: null,
staticCredentialStore: null,
vaultCredentialStore: null,
Expand All @@ -62,10 +57,7 @@ module('Acceptance | credential-stores | delete', function (hooks) {
type: 'vault',
});
// Generate route URLs for resources
urls.globalScope = `/scopes/global/scopes`;
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
urls.credentialStores = `${urls.projectScope}/credential-stores`;
urls.credentialStores = `/scopes/${instances.scopes.project.id}/credential-stores`;
urls.staticCredentialStore = `${urls.credentialStores}/${instances.staticCredentialStore.id}`;
urls.vaultCredentialStore = `${urls.credentialStores}/${instances.vaultCredentialStore.id}`;
// Generate resource counter
Expand All @@ -83,16 +75,20 @@ module('Acceptance | credential-stores | delete', function (hooks) {
test('can delete credential store of type vault', async function (assert) {
const count = getVaultCredentialStoresCount();
await visit(urls.vaultCredentialStore);
await click(MANAGE_DROPDOWN_SELECTOR);
await click(DELETE_ACTION_SELECTOR);

await click(selectors.MANAGE_DROPDOWN);
await click(selectors.DELETE_ACTION);

assert.strictEqual(getVaultCredentialStoresCount(), count - 1);
});

test('can delete credential store of type static', async function (assert) {
const count = getStaticCredentialStoresCount();
await visit(urls.staticCredentialStore);
await click(MANAGE_DROPDOWN_SELECTOR);
await click(DELETE_ACTION_SELECTOR);

await click(selectors.MANAGE_DROPDOWN);
await click(selectors.DELETE_ACTION);

assert.strictEqual(getStaticCredentialStoresCount(), count - 1);
});

Expand All @@ -102,9 +98,10 @@ module('Acceptance | credential-stores | delete', function (hooks) {
(item) => item !== 'delete',
);
await visit(urls.vaultCredentialStore);
await click(MANAGE_DROPDOWN_SELECTOR);

assert.dom(DELETE_ACTION_SELECTOR).doesNotExist();
await click(selectors.MANAGE_DROPDOWN);

assert.dom(selectors.DELETE_ACTION).doesNotExist();
DhariniJeeva marked this conversation as resolved.
Show resolved Hide resolved
});

test('cannot delete a static credential store without proper authorization', async function (assert) {
Expand All @@ -113,9 +110,10 @@ module('Acceptance | credential-stores | delete', function (hooks) {
(item) => item !== 'delete',
);
await visit(urls.staticCredentialStore);
await click(MANAGE_DROPDOWN_SELECTOR);

assert.dom(DELETE_ACTION_SELECTOR).doesNotExist();
await click(selectors.MANAGE_DROPDOWN);

assert.dom(selectors.DELETE_ACTION).doesNotExist();
});

test('can accept delete static credential store via dialog', async function (assert) {
Expand All @@ -124,8 +122,10 @@ module('Acceptance | credential-stores | delete', function (hooks) {
confirmService.confirm = sinon.fake.returns(resolve());
const count = getStaticCredentialStoresCount();
await visit(urls.staticCredentialStore);
await click(MANAGE_DROPDOWN_SELECTOR);
await click(DELETE_ACTION_SELECTOR);

await click(selectors.MANAGE_DROPDOWN);
await click(selectors.DELETE_ACTION);

assert.strictEqual(getStaticCredentialStoresCount(), count - 1);
assert.ok(confirmService.confirm.calledOnce);
});
Expand All @@ -136,8 +136,10 @@ module('Acceptance | credential-stores | delete', function (hooks) {
confirmService.confirm = sinon.fake.returns(resolve());
const count = getVaultCredentialStoresCount();
await visit(urls.vaultCredentialStore);
await click(MANAGE_DROPDOWN_SELECTOR);
await click(DELETE_ACTION_SELECTOR);

await click(selectors.MANAGE_DROPDOWN);
await click(selectors.DELETE_ACTION);

assert.strictEqual(getVaultCredentialStoresCount(), count - 1);
assert.ok(confirmService.confirm.calledOnce);
});
Expand All @@ -148,8 +150,10 @@ module('Acceptance | credential-stores | delete', function (hooks) {
confirmService.confirm = sinon.fake.returns(reject());
const count = getStaticCredentialStoresCount();
await visit(urls.staticCredentialStore);
await click(MANAGE_DROPDOWN_SELECTOR);
await click(DELETE_ACTION_SELECTOR);

await click(selectors.MANAGE_DROPDOWN);
await click(selectors.DELETE_ACTION);

assert.strictEqual(getStaticCredentialStoresCount(), count);
assert.ok(confirmService.confirm.calledOnce);
});
Expand All @@ -160,8 +164,10 @@ module('Acceptance | credential-stores | delete', function (hooks) {
confirmService.confirm = sinon.fake.returns(reject());
const count = getVaultCredentialStoresCount();
await visit(urls.vaultCredentialStore);
await click(MANAGE_DROPDOWN_SELECTOR);
await click(DELETE_ACTION_SELECTOR);

await click(selectors.MANAGE_DROPDOWN);
await click(selectors.DELETE_ACTION);

assert.strictEqual(getVaultCredentialStoresCount(), count);
assert.ok(confirmService.confirm.calledOnce);
});
Expand All @@ -179,11 +185,11 @@ module('Acceptance | credential-stores | delete', function (hooks) {
);
});
await visit(urls.staticCredentialStore);
await click(MANAGE_DROPDOWN_SELECTOR);
await click(DELETE_ACTION_SELECTOR);
assert
.dom('[data-test-toast-notification] .hds-alert__description')
.hasText('Oops.');

await click(selectors.MANAGE_DROPDOWN);
await click(selectors.DELETE_ACTION);

assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText('Oops.');
});

test('deleting a vault credential store which errors displays error messages', async function (assert) {
Expand All @@ -199,10 +205,10 @@ module('Acceptance | credential-stores | delete', function (hooks) {
);
});
await visit(urls.vaultCredentialStore);
await click(MANAGE_DROPDOWN_SELECTOR);
await click(DELETE_ACTION_SELECTOR);
assert
.dom('[data-test-toast-notification] .hds-alert__description')
.hasText('Oops.');

await click(selectors.MANAGE_DROPDOWN);
await click(selectors.DELETE_ACTION);

assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText('Oops.');
});
});
82 changes: 44 additions & 38 deletions ui/admin/tests/acceptance/credential-store/list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,14 @@ import {
TYPE_CREDENTIAL_STORE_STATIC,
TYPE_CREDENTIAL_STORE_VAULT,
} from 'api/models/credential-store';
import * as selectors from './selectors';
import * as commonSelectors from 'admin/tests/helpers/selectors';

module('Acceptance | credential-stores | list', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
setupIndexedDb(hooks);

const SEARCH_INPUT_SELECTOR = '.search-filtering [type="search"]';
const NO_RESULTS_MSG_SELECTOR = '[data-test-no-credential-store-results]';
const FILTER_DROPDOWN_SELECTOR = (name) =>
`.search-filtering [name="${name}"] button`;
const FILTER_APPLY_BUTTON_SELECTOR =
'.search-filtering [data-test-dropdown-apply-button]';

const instances = {
scopes: {
global: null,
Expand Down Expand Up @@ -76,14 +71,14 @@ module('Acceptance | credential-stores | list', function (hooks) {
test('users can navigate to credential-stores with proper authorization', async function (assert) {
await visit(urls.orgScope);

await click(`[href="${urls.projectScope}"]`);
await click(commonSelectors.HREF(urls.projectScope));

assert.true(
instances.scopes.project.authorized_collection_actions[
'credential-stores'
].includes('list'),
);
assert.dom(`[href="${urls.credentialStores}"]`).exists();
assert.dom(commonSelectors.HREF(urls.credentialStores)).isVisible();
});

test('users cannot navigate to index without either list or create actions', async function (assert) {
Expand All @@ -92,7 +87,7 @@ module('Acceptance | credential-stores | list', function (hooks) {
] = [];
await visit(urls.orgScope);

await click(`[href="${urls.projectScope}"]`);
await click(commonSelectors.HREF(urls.projectScope));

assert.false(
instances.scopes.project.authorized_collection_actions[
Expand All @@ -104,7 +99,7 @@ module('Acceptance | credential-stores | list', function (hooks) {
'credential-stores'
].includes('create'),
);
assert.dom(`[href="${urls.credentialStores}"]`).doesNotExist();
assert.dom(commonSelectors.HREF(urls.credentialStores)).doesNotExist();
});

test('users can navigate to index with only create action', async function (assert) {
Expand All @@ -113,67 +108,78 @@ module('Acceptance | credential-stores | list', function (hooks) {
] = ['create'];
await visit(urls.orgScope);

await click(`[href="${urls.projectScope}"]`);
await click(commonSelectors.HREF(urls.projectScope));

assert.dom(`[href="${urls.credentialStores}"]`).exists();
assert.dom(commonSelectors.HREF(urls.credentialStores)).isVisible();
});

test('users can link to docs page for credential stores', async function (assert) {
await visit(urls.projectScope);

await click(`[href="${urls.credentialStores}"]`);
await click(commonSelectors.HREF(urls.credentialStores));

assert
.dom(
`[href="https://developer.hashicorp.com/boundary/docs/concepts/domain-model/credential-stores"]`,
)
.exists();
.isVisible();
});

test('user can search for a specific credential-store by id', async function (assert) {
await visit(urls.projectScope);

await click(`[href="${urls.credentialStores}"]`);
await click(commonSelectors.HREF(urls.credentialStores));

assert.dom(`[href="${urls.staticCredentialStore}"]`).exists();
assert.dom(`[href="${urls.vaultCredentialStore}"]`).exists();
assert.dom(commonSelectors.HREF(urls.staticCredentialStore)).isVisible();
assert.dom(commonSelectors.HREF(urls.vaultCredentialStore)).isVisible();

await fillIn(SEARCH_INPUT_SELECTOR, instances.staticCredentialStore.id);
await waitFor(`[href="${urls.vaultCredentialStore}"]`, { count: 0 });
await fillIn(
commonSelectors.SEARCH_INPUT,
instances.staticCredentialStore.id,
);
await waitFor(commonSelectors.HREF(urls.vaultCredentialStore), {
count: 0,
});

assert.dom(`[href="${urls.staticCredentialStore}"]`).exists();
assert.dom(`[href="${urls.vaultCredentialStore}"]`).doesNotExist();
assert.dom(commonSelectors.HREF(urls.staticCredentialStore)).isVisible();
assert.dom(commonSelectors.HREF(urls.vaultCredentialStore)).doesNotExist();
});

test('user can search for credential-stores and get no results', async function (assert) {
await visit(urls.projectScope);

await click(`[href="${urls.credentialStores}"]`);
await click(commonSelectors.HREF(urls.credentialStores));

assert.dom(`[href="${urls.staticCredentialStore}"]`).exists();
assert.dom(`[href="${urls.vaultCredentialStore}"]`).exists();
assert.dom(commonSelectors.HREF(urls.staticCredentialStore)).isVisible();
assert.dom(commonSelectors.HREF(urls.vaultCredentialStore)).isVisible();

await fillIn(SEARCH_INPUT_SELECTOR, 'fake cred store that does not exist');
await waitFor(NO_RESULTS_MSG_SELECTOR, { count: 1 });
await fillIn(
commonSelectors.SEARCH_INPUT,
'fake cred store that does not exist',
);
await waitFor(selectors.NO_RESULTS_MSG, { count: 1 });

assert.dom(`[href="${urls.staticCredentialStore}"]`).doesNotExist();
assert.dom(`[href="${urls.vaultCredentialStore}"]`).doesNotExist();
assert.dom(NO_RESULTS_MSG_SELECTOR).includesText('No results found');
assert.dom(commonSelectors.HREF(urls.staticCredentialStore)).doesNotExist();
assert.dom(commonSelectors.HREF(urls.vaultCredentialStore)).doesNotExist();
assert.dom(selectors.NO_RESULTS_MSG).includesText('No results found');
});

test('user can filter for credential-stores by type', async function (assert) {
await visit(urls.projectScope);

await click(`[href="${urls.credentialStores}"]`);
await click(commonSelectors.HREF(urls.credentialStores));

assert.dom(commonSelectors.HREF(urls.staticCredentialStore)).isVisible();
assert.dom(commonSelectors.HREF(urls.vaultCredentialStore)).isVisible();

assert.dom(`[href="${urls.staticCredentialStore}"]`).exists();
assert.dom(`[href="${urls.vaultCredentialStore}"]`).exists();
await click(commonSelectors.FILTER_DROPDOWN('type'));

await click(FILTER_DROPDOWN_SELECTOR('type'));
await click(`input[value="${TYPE_CREDENTIAL_STORE_VAULT}"]`);
await click(FILTER_APPLY_BUTTON_SELECTOR);
await click(
commonSelectors.FILTER_DROPDOWN_ITEM(TYPE_CREDENTIAL_STORE_VAULT),
);
await click(commonSelectors.FILTER_DROPDOWN_ITEM_APPLY_BTN('type'));

assert.dom(`[href="${urls.staticCredentialStore}"]`).doesNotExist();
assert.dom(`[href="${urls.vaultCredentialStore}"]`).exists();
assert.dom(commonSelectors.HREF(urls.staticCredentialStore)).doesNotExist();
assert.dom(commonSelectors.HREF(urls.vaultCredentialStore)).isVisible();
});
});
Loading