Icu 5476 refactor target model serializer and mirage (#1235)
chore: 🤖 refactor target model to support credentials
This commit is contained in:
1 parent
2cda4f639e
commit
1f0baceb5e
12 files changed
+210
-66
No files matched your search
@@ -10,15 +10,19 @@ export default class ScopesScopeTargetsTargetCredentialSourcesRoute extends Rout
|
||||
|
||||
/**
|
||||
* Loads all credential libraries under the current target.
|
||||
* @return {Promise{[CredentialLibraryModel]}}
|
||||
* @return {Promise{[CredentialLibraryModel, CredentialModel]}}
|
||||
*/
|
||||
beforeModel() {
|
||||
const { application_credential_source_ids: sourceIDFragments } =
|
||||
this.modelFor('scopes.scope.targets.target');
|
||||
return all(
|
||||
sourceIDFragments.map(({ value }) => {
|
||||
const isStoreOrLibrary = !value.includes('cred');
|
||||
if (isStoreOrLibrary) {
|
||||
const isStatic = value.includes('cred');
|
||||
if (isStatic) {
|
||||
return this.store.findRecord('credential', value, {
|
||||
reload: true,
|
||||
});
|
||||
} else {
|
||||
return this.store.findRecord('credential-library', value, {
|
||||
reload: true,
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
</page.actions>
|
||||
|
||||
<page.body>
|
||||
{{#if @model.credentialLibraries}}
|
||||
{{#if @model.credentialSources}}
|
||||
|
||||
<Rose::Table as |table|>
|
||||
<table.header as |header|>
|
||||
@@ -31,35 +31,48 @@
|
||||
</header.row>
|
||||
</table.header>
|
||||
<table.body as |body|>
|
||||
{{#each @model.credentialLibraries as |credentialLibrary|}}
|
||||
{{#each @model.credentialSources as |credentialSource|}}
|
||||
<body.row as |row|>
|
||||
<row.headerCell>
|
||||
<LinkTo
|
||||
@route='scopes.scope.credential-stores.credential-store.credential-libraries.credential-library'
|
||||
@models={{array
|
||||
credentialLibrary.credential_store_id
|
||||
credentialLibrary.id
|
||||
}}
|
||||
>
|
||||
{{credentialLibrary.displayName}}
|
||||
</LinkTo>
|
||||
<p>{{credentialLibrary.description}}</p>
|
||||
{{#if (eq credentialSource.type 'username_password')}}
|
||||
<LinkTo
|
||||
@route='scopes.scope.credential-stores.credential-store.credentials.credential'
|
||||
@models={{array
|
||||
credentialSource.credential_store_id
|
||||
credentialSource.id
|
||||
}}
|
||||
>
|
||||
{{credentialSource.displayName}}
|
||||
</LinkTo>
|
||||
{{else}}
|
||||
<LinkTo
|
||||
@route='scopes.scope.credential-stores.credential-store.credential-libraries.credential-library'
|
||||
@models={{array
|
||||
credentialSource.credential_store_id
|
||||
credentialSource.id
|
||||
}}
|
||||
>
|
||||
{{credentialSource.displayName}}
|
||||
</LinkTo>
|
||||
{{/if}}
|
||||
|
||||
<p>{{credentialSource.description}}</p>
|
||||
</row.headerCell>
|
||||
<row.cell>
|
||||
<Rose::Badge>{{t
|
||||
(concat
|
||||
'resources.credential-library.types.'
|
||||
credentialLibrary.type
|
||||
'resources.target.credential-source.types.'
|
||||
credentialSource.type
|
||||
)
|
||||
}}</Rose::Badge>
|
||||
</row.cell>
|
||||
<row.cell>
|
||||
<Copyable
|
||||
@text={{credentialLibrary.id}}
|
||||
@text={{credentialSource.id}}
|
||||
@buttonText={{t 'actions.copy-to-clipboard'}}
|
||||
@acknowledgeText={{t 'states.copied'}}
|
||||
>
|
||||
<code>{{credentialLibrary.id}}</code>
|
||||
<code>{{credentialSource.id}}</code>
|
||||
</Copyable>
|
||||
</row.cell>
|
||||
<row.cell>
|
||||
@@ -77,7 +90,7 @@
|
||||
{{on
|
||||
'click'
|
||||
(route-action
|
||||
'removeCredentialSource' @model credentialLibrary
|
||||
'removeCredentialSource' @model credentialSource
|
||||
)
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -30,6 +30,7 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
credentialLibraries: null,
|
||||
credentialLibrary: null,
|
||||
credentials: null,
|
||||
credential: null,
|
||||
};
|
||||
const urls = {
|
||||
globalScope: null,
|
||||
@@ -74,6 +75,7 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
}
|
||||
);
|
||||
instances.credentialLibrary = instances.credentialLibraries[0];
|
||||
instances.credential = instances.credentials[0];
|
||||
instances.target = this.server.create('target', {
|
||||
scope: instances.scopes.project,
|
||||
credentialLibraries: instances.credentialLibraries,
|
||||
@@ -86,6 +88,7 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
urls.target = `${urls.targets}/${instances.target.id}`;
|
||||
urls.credentialSources = `${urls.target}/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.addCredentialSources = `${urls.target}/add-credential-sources`;
|
||||
// Generate resource counter
|
||||
getCredentialLibraryCount = () =>
|
||||
@@ -104,7 +107,7 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
assert.strictEqual(findAll('tbody tr').length, getCredentialLibraryCount());
|
||||
});
|
||||
|
||||
test('can navigate to a credential library', async function (assert) {
|
||||
test('can navigate to a vault type credential library', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(urls.credentialSources);
|
||||
await click('main tbody .rose-table-header-cell:nth-child(1) a');
|
||||
@@ -112,6 +115,18 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
assert.strictEqual(currentURL(), urls.credentialLibrary);
|
||||
});
|
||||
|
||||
test('can navigate to a username & password type credential', async function (assert) {
|
||||
assert.expect(1);
|
||||
instances.target.update({
|
||||
credentialLibraries: [],
|
||||
credentials: instances.credentials,
|
||||
});
|
||||
await visit(urls.credentialSources);
|
||||
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) {
|
||||
assert.expect(1);
|
||||
await visit(urls.addCredentialSources);
|
||||
@@ -165,19 +180,46 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
assert.strictEqual(currentURL(), urls.credentialSources);
|
||||
});
|
||||
|
||||
test('can select and save credential sources to add', async function (assert) {
|
||||
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);
|
||||
assert.strictEqual(findAll('tbody tr').length, 0);
|
||||
await visit(urls.addCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialSourceCount);
|
||||
await click('tbody label');
|
||||
await click('tbody tr:first-child label');
|
||||
await click('form [type="submit"]');
|
||||
assert.strictEqual(currentURL(), urls.credentialSources);
|
||||
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);
|
||||
assert.strictEqual(findAll('tbody tr').length, 0);
|
||||
await visit(urls.addCredentialSources);
|
||||
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(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);
|
||||
assert.strictEqual(findAll('tbody tr').length, 0);
|
||||
await visit(urls.addCredentialSources);
|
||||
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(findAll('tbody tr').length, 2);
|
||||
});
|
||||
|
||||
test('cannot add credential sources without proper authorization', async function (assert) {
|
||||
assert.expect(1);
|
||||
instances.target.authorized_actions =
|
||||
@@ -201,6 +243,20 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
assert.strictEqual(findAll('tbody tr').length, 0);
|
||||
});
|
||||
|
||||
test('can select multiple credential sources to add and cancel', async function (assert) {
|
||||
assert.expect(4);
|
||||
instances.target.update({ credentialLibraries: [] });
|
||||
await visit(urls.credentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, 0);
|
||||
await visit(urls.addCredentialSources);
|
||||
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(findAll('tbody tr').length, 0);
|
||||
});
|
||||
|
||||
test('adding credential sources which errors displays error message', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/targets/:idMethod', () => {
|
||||
@@ -217,18 +273,38 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
});
|
||||
instances.target.update({ credentialLibraries: [] });
|
||||
await visit(urls.addCredentialSources);
|
||||
await click('tbody label');
|
||||
await click('tbody tr:last-child label');
|
||||
await click('tbody tr:first-child label');
|
||||
await click('form [type="submit"]');
|
||||
assert.ok(find('[role="alert"]'));
|
||||
});
|
||||
|
||||
test('can remove a credential library', async function (assert) {
|
||||
assert.expect(2);
|
||||
const count = getCredentialLibraryCount();
|
||||
test('can remove a vault type credential library', async function (assert) {
|
||||
assert.expect(3);
|
||||
const credentialLibraryCount = getCredentialLibraryCount();
|
||||
const credentialCount = getCredentialCount();
|
||||
await visit(urls.credentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, count);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialLibraryCount);
|
||||
await click('tbody tr .rose-dropdown-button-danger');
|
||||
assert.strictEqual(findAll('tbody tr').length, count - 1);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialLibraryCount - 1);
|
||||
await visit(urls.addCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialCount + 1);
|
||||
});
|
||||
|
||||
test('can remove a username & password type credential', async function (assert) {
|
||||
assert.expect(3);
|
||||
instances.target.update({
|
||||
credentialLibraries: [],
|
||||
credentials: instances.credentials,
|
||||
});
|
||||
const credentialCount = getCredentialCount();
|
||||
const credentialLibraryCount = getCredentialLibraryCount();
|
||||
await visit(urls.credentialSources);
|
||||
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.addCredentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, credentialLibraryCount + 1);
|
||||
});
|
||||
|
||||
test('cannot remove credential libraries without proper authorization', async function (assert) {
|
||||
@@ -261,4 +337,29 @@ module('Acceptance | targets | credential sources', function (hooks) {
|
||||
await click('tbody tr .rose-dropdown-button-danger');
|
||||
assert.ok(find('[role="alert"]'));
|
||||
});
|
||||
|
||||
test('removing a target credential which errors displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
instances.target.update({
|
||||
credentialLibraries: [],
|
||||
credentials: instances.credentials,
|
||||
});
|
||||
this.server.post('/targets/:idMethod', () => {
|
||||
return new Response(
|
||||
400,
|
||||
{},
|
||||
{
|
||||
status: 400,
|
||||
code: 'invalid_argument',
|
||||
message: 'The request was invalid.',
|
||||
details: {},
|
||||
}
|
||||
);
|
||||
});
|
||||
const count = getCredentialCount();
|
||||
await visit(urls.credentialSources);
|
||||
assert.strictEqual(findAll('tbody tr').length, count);
|
||||
await click('tbody tr .rose-dropdown-button-danger');
|
||||
assert.ok(find('[role="alert"]'));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user