Icu 5578 - introduce injected application credential on the api (#1269)
* chore: 🤖 include injected cred sources to the target model
This commit is contained in:
1 parent
bd0854b0f6
commit
2614b311a1
11 files changed
+395
-171
No files matched your search
+99
-79
@@ -4,20 +4,17 @@ import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { Response } from 'miragejs';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import {
|
||||
authenticateSession,
|
||||
// These are left here intentionally for future reference.
|
||||
//currentSession,
|
||||
//invalidateSession,
|
||||
} from 'ember-simple-auth/test-support';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
|
||||
module('Acceptance | targets | credential sources', function (hooks) {
|
||||
module('Acceptance | targets | brokered credential sources', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
let getCredentialLibraryCount;
|
||||
let getCredentialCount;
|
||||
let credentialSourceCount;
|
||||
let randomlySelectedCredentialLibraries;
|
||||
let randomlySelectedCredentials;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
@@ -41,6 +38,7 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
credentialLibraries: null,
|
||||
credentialLibrary: null,
|
||||
addBrokeredCredentialSources: null,
|
||||
brokeredCredentialSources: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
@@ -78,38 +76,54 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
instances.credential = instances.credentials[0];
|
||||
instances.target = this.server.create('target', {
|
||||
scope: instances.scopes.project,
|
||||
credentialLibraries: instances.credentialLibraries,
|
||||
});
|
||||
|
||||
randomlySelectedCredentials = this.server.schema.credentials
|
||||
.all()
|
||||
.models.filter(Boolean)
|
||||
.map((cred) => cred.id);
|
||||
randomlySelectedCredentialLibraries = this.server.schema.credentialLibraries
|
||||
.all()
|
||||
.models.filter(Boolean)
|
||||
.map((cred) => cred.id);
|
||||
|
||||
instances.target.update({
|
||||
brokeredCredentialSourceIds: [
|
||||
...randomlySelectedCredentialLibraries,
|
||||
...randomlySelectedCredentials,
|
||||
],
|
||||
});
|
||||
|
||||
// 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.targets = `${urls.projectScope}/targets`;
|
||||
urls.target = `${urls.targets}/${instances.target.id}`;
|
||||
urls.credentialSources = `${urls.target}/brokered-credential-sources`;
|
||||
urls.brokeredCredentialSources = `${urls.target}/brokered-credential-sources`;
|
||||
urls.credentialLibrary = `${urls.projectScope}/credential-stores/${instances.credentialLibrary.credentialStoreId}/credential-libraries/${instances.credentialLibrary.id}`;
|
||||
urls.credential = `${urls.projectScope}/credential-stores/${instances.credential.credentialStoreId}/credentials/${instances.credential.id}`;
|
||||
urls.addBrokeredCredentialSources = `${urls.target}/add-brokered-credential-sources`;
|
||||
// Generate resource counter
|
||||
getCredentialLibraryCount = () =>
|
||||
this.server.schema.credentialLibraries.all().models.length;
|
||||
getCredentialCount = () =>
|
||||
this.server.schema.credentials.all().models.length;
|
||||
credentialSourceCount = getCredentialLibraryCount() + getCredentialCount();
|
||||
|
||||
authenticateSession({});
|
||||
});
|
||||
|
||||
test('visiting target credential sources', async function (assert) {
|
||||
test('visiting target brokered credential sources', async function (assert) {
|
||||
assert.expect(2);
|
||||
await visit(urls.credentialSources);
|
||||
await visit(urls.brokeredCredentialSources);
|
||||
await a11yAudit();
|
||||
assert.strictEqual(currentURL(), urls.credentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, getCredentialLibraryCount());
|
||||
assert.strictEqual(currentURL(), urls.brokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialSourceCount);
|
||||
});
|
||||
|
||||
test('can navigate to a vault type credential library', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(urls.credentialSources);
|
||||
await visit(urls.brokeredCredentialSources);
|
||||
await click('main tbody .rose-table-header-cell:nth-child(1) a');
|
||||
await a11yAudit();
|
||||
assert.strictEqual(currentURL(), urls.credentialLibrary);
|
||||
@@ -118,51 +132,43 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
test('can navigate to a username & password type credential', async function (assert) {
|
||||
assert.expect(1);
|
||||
instances.target.update({
|
||||
credentialLibraries: [],
|
||||
credentials: instances.credentials,
|
||||
brokeredCredentialSourceIds: [...randomlySelectedCredentials],
|
||||
});
|
||||
await visit(urls.credentialSources);
|
||||
await visit(urls.brokeredCredentialSources);
|
||||
await click('main tbody .rose-table-header-cell:nth-child(1) a');
|
||||
await a11yAudit();
|
||||
assert.strictEqual(currentURL(), urls.credential);
|
||||
});
|
||||
|
||||
test('visiting add credential sources', async function (assert) {
|
||||
test('visiting add brokered credential sources', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(urls.addBrokeredCredentialSources);
|
||||
await a11yAudit();
|
||||
assert.strictEqual(currentURL(), urls.addBrokeredCredentialSources);
|
||||
});
|
||||
|
||||
test('displays list of all credential source types available', async function (assert) {
|
||||
test('displays list of all brokered credential source types available', async function (assert) {
|
||||
assert.expect(2);
|
||||
instances.target.update({ credentialLibraries: [] });
|
||||
instances.target.update({
|
||||
brokeredCredentialSourceIds: [],
|
||||
});
|
||||
await visit(urls.addBrokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialSourceCount);
|
||||
assert.notOk(find('.rose-message-title'));
|
||||
assert.dom('.rose-message-title').doesNotExist();
|
||||
});
|
||||
|
||||
test('displays list of credential sources with only credential libraries available', async function (assert) {
|
||||
test('displays list of brokered credential sources with only credential libraries available', async function (assert) {
|
||||
assert.expect(2);
|
||||
instances.target.update({ credentialLibraries: [] });
|
||||
this.server.db.credentials.remove();
|
||||
instances.target.update({
|
||||
brokeredCredentialSourceIds: [...randomlySelectedCredentialLibraries],
|
||||
});
|
||||
await visit(urls.addBrokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, getCredentialLibraryCount());
|
||||
assert.notOk(find('.rose-message-title'));
|
||||
assert.dom('.rose-message-title').doesNotExist();
|
||||
});
|
||||
|
||||
test('displays list of credential sources with only credentials available', async function (assert) {
|
||||
assert.expect(2);
|
||||
await visit(urls.addBrokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, getCredentialCount());
|
||||
assert.notOk(find('.rose-message-title'));
|
||||
});
|
||||
|
||||
test('displays no credential sources message when none available', async function (assert) {
|
||||
test('displays no brokered credential sources message when none available', async function (assert) {
|
||||
assert.expect(1);
|
||||
instances.target.update({ credentialLibraries: [] });
|
||||
this.server.db.credentialLibraries.remove();
|
||||
this.server.db.credentials.remove();
|
||||
await visit(urls.addBrokeredCredentialSources);
|
||||
assert.strictEqual(
|
||||
find('.rose-message-title').textContent.trim(),
|
||||
@@ -170,53 +176,59 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
);
|
||||
});
|
||||
|
||||
test('when no credential sources available, button routes to credential sources', async function (assert) {
|
||||
test('when no brokered credential sources available, button routes to add brokered credential sources', async function (assert) {
|
||||
assert.expect(1);
|
||||
instances.target.update({ credentialLibraries: [] });
|
||||
this.server.db.credentialLibraries.remove();
|
||||
this.server.db.credentials.remove();
|
||||
await visit(urls.addBrokeredCredentialSources);
|
||||
instances.target.update({
|
||||
brokeredCredentialSourceIds: [],
|
||||
});
|
||||
await visit(urls.brokeredCredentialSources);
|
||||
await click(find('.rose-message-link'));
|
||||
assert.strictEqual(currentURL(), urls.credentialSources);
|
||||
assert.strictEqual(currentURL(), urls.addBrokeredCredentialSources);
|
||||
});
|
||||
|
||||
test('can select and save a vault type credential library to add', async function (assert) {
|
||||
assert.expect(4);
|
||||
instances.target.update({ credentialLibraries: [] });
|
||||
await visit(urls.credentialSources);
|
||||
instances.target.update({
|
||||
brokeredCredentialSourceIds: [],
|
||||
});
|
||||
await visit(urls.brokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, 0);
|
||||
await visit(urls.addBrokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialSourceCount);
|
||||
await click('tbody tr:first-child label');
|
||||
await click('form [type="submit"]');
|
||||
assert.strictEqual(currentURL(), urls.credentialSources);
|
||||
assert.strictEqual(currentURL(), urls.brokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, 1);
|
||||
});
|
||||
|
||||
test('can select and save a username & password type credential to add', async function (assert) {
|
||||
assert.expect(4);
|
||||
instances.target.update({ credentialLibraries: [] });
|
||||
await visit(urls.credentialSources);
|
||||
instances.target.update({
|
||||
brokeredCredentialSourceIds: [],
|
||||
});
|
||||
await visit(urls.brokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, 0);
|
||||
await visit(urls.addBrokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialSourceCount);
|
||||
await click('tbody tr:last-child label');
|
||||
await click('form [type="submit"]');
|
||||
assert.strictEqual(currentURL(), urls.credentialSources);
|
||||
assert.strictEqual(currentURL(), urls.brokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, 1);
|
||||
});
|
||||
|
||||
test('can select and save both a credential-library and a credential to add', async function (assert) {
|
||||
assert.expect(4);
|
||||
instances.target.update({ credentialLibraries: [] });
|
||||
await visit(urls.credentialSources);
|
||||
instances.target.update({
|
||||
brokeredCredentialSourceIds: [],
|
||||
});
|
||||
await visit(urls.brokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, 0);
|
||||
await visit(urls.addBrokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialSourceCount);
|
||||
await click('tbody tr:last-child label');
|
||||
await click('tbody tr:first-child label');
|
||||
await click('form [type="submit"]');
|
||||
assert.strictEqual(currentURL(), urls.credentialSources);
|
||||
assert.strictEqual(currentURL(), urls.brokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, 2);
|
||||
});
|
||||
|
||||
@@ -226,34 +238,38 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
instances.target.authorized_actions.filter(
|
||||
(item) => item !== 'add-credential-sources'
|
||||
);
|
||||
await visit(urls.credentialSources);
|
||||
assert.notOk(find(`[href="${urls.addBrokeredCredentialSources}"]`));
|
||||
await visit(urls.brokeredCredentialSources);
|
||||
assert.dom(`[href="${urls.addBrokeredCredentialSources}"]`).doesNotExist();
|
||||
});
|
||||
|
||||
test('can select and cancel credential sources to add', async function (assert) {
|
||||
assert.expect(4);
|
||||
instances.target.update({ credentialLibraries: [] });
|
||||
await visit(urls.credentialSources);
|
||||
instances.target.update({
|
||||
brokeredCredentialSourceIds: [],
|
||||
});
|
||||
await visit(urls.brokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, 0);
|
||||
await visit(urls.addBrokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialSourceCount);
|
||||
await click('tbody label');
|
||||
await click('form [type="button"]');
|
||||
assert.strictEqual(currentURL(), urls.credentialSources);
|
||||
assert.strictEqual(currentURL(), urls.brokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, 0);
|
||||
});
|
||||
|
||||
test('can select multiple credential sources to add and cancel', async function (assert) {
|
||||
test('can select multiple brokered credential sources to add and cancel', async function (assert) {
|
||||
assert.expect(4);
|
||||
instances.target.update({ credentialLibraries: [] });
|
||||
await visit(urls.credentialSources);
|
||||
instances.target.update({
|
||||
brokeredCredentialSourceIds: [],
|
||||
});
|
||||
await visit(urls.brokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, 0);
|
||||
await visit(urls.addBrokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialSourceCount);
|
||||
await click('tbody tr:last-child label');
|
||||
await click('tbody tr:first-child label');
|
||||
await click('form [type="button"]');
|
||||
assert.strictEqual(currentURL(), urls.credentialSources);
|
||||
assert.strictEqual(currentURL(), urls.brokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, 0);
|
||||
});
|
||||
|
||||
@@ -271,40 +287,42 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
}
|
||||
);
|
||||
});
|
||||
instances.target.update({ credentialLibraries: [] });
|
||||
instances.target.update({
|
||||
brokeredCredentialSourceIds: [],
|
||||
});
|
||||
await visit(urls.addBrokeredCredentialSources);
|
||||
await click('tbody tr:last-child label');
|
||||
await click('tbody tr:first-child label');
|
||||
await click('form [type="submit"]');
|
||||
assert.ok(find('[role="alert"]'));
|
||||
assert.dom('[role="alert"]').isVisible();
|
||||
});
|
||||
|
||||
test('can remove a vault type credential library', async function (assert) {
|
||||
assert.expect(3);
|
||||
instances.target.update({
|
||||
brokeredCredentialSourceIds: [...randomlySelectedCredentialLibraries],
|
||||
});
|
||||
const credentialLibraryCount = getCredentialLibraryCount();
|
||||
const credentialCount = getCredentialCount();
|
||||
await visit(urls.credentialSources);
|
||||
await visit(urls.brokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialLibraryCount);
|
||||
await click('tbody tr .rose-dropdown-button-danger');
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialLibraryCount - 1);
|
||||
await visit(urls.addBrokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialCount + 1);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialLibraryCount + 1);
|
||||
});
|
||||
|
||||
test('can remove a username & password type credential', async function (assert) {
|
||||
assert.expect(3);
|
||||
instances.target.update({
|
||||
credentialLibraries: [],
|
||||
credentials: instances.credentials,
|
||||
brokeredCredentialSourceIds: [...randomlySelectedCredentials],
|
||||
});
|
||||
const credentialCount = getCredentialCount();
|
||||
const credentialLibraryCount = getCredentialLibraryCount();
|
||||
await visit(urls.credentialSources);
|
||||
await visit(urls.brokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialCount);
|
||||
await click('tbody tr .rose-dropdown-button-danger');
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialCount - 1);
|
||||
await visit(urls.addBrokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialLibraryCount + 1);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialCount + 1);
|
||||
});
|
||||
|
||||
test('cannot remove credential libraries without proper authorization', async function (assert) {
|
||||
@@ -313,12 +331,15 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
instances.target.authorized_actions.filter(
|
||||
(item) => item !== 'remove-credential-sources'
|
||||
);
|
||||
await visit(urls.credentialSources);
|
||||
assert.notOk(find('tbody tr .rose-dropdown-button-danger'));
|
||||
await visit(urls.brokeredCredentialSources);
|
||||
assert.dom('tbody tr .rose-dropdown-button-danger').doesNotExist();
|
||||
});
|
||||
|
||||
test('removing a target credential library which errors displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
instances.target.update({
|
||||
brokeredCredentialSourceIds: [...randomlySelectedCredentialLibraries],
|
||||
});
|
||||
this.server.post('/targets/:idMethod', () => {
|
||||
return new Response(
|
||||
400,
|
||||
@@ -332,17 +353,16 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
);
|
||||
});
|
||||
const count = getCredentialLibraryCount();
|
||||
await visit(urls.credentialSources);
|
||||
await visit(urls.brokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, count);
|
||||
await click('tbody tr .rose-dropdown-button-danger');
|
||||
assert.ok(find('[role="alert"]'));
|
||||
assert.dom('[role="alert"]').isVisible();
|
||||
});
|
||||
|
||||
test('removing a target credential which errors displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
instances.target.update({
|
||||
credentialLibraries: [],
|
||||
credentials: instances.credentials,
|
||||
brokeredCredentialSourceIds: [...randomlySelectedCredentials],
|
||||
});
|
||||
this.server.post('/targets/:idMethod', () => {
|
||||
return new Response(
|
||||
@@ -357,9 +377,9 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
);
|
||||
});
|
||||
const count = getCredentialCount();
|
||||
await visit(urls.credentialSources);
|
||||
await visit(urls.brokeredCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, count);
|
||||
await click('tbody tr .rose-dropdown-button-danger');
|
||||
assert.ok(find('[role="alert"]'));
|
||||
assert.dom('[role="alert"]').isVisible();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user