diff --git a/addons/api/mirage/factories/credential-library.js b/addons/api/mirage/factories/credential-library.js index 06d8c4f6c..621ae6410 100644 --- a/addons/api/mirage/factories/credential-library.js +++ b/addons/api/mirage/factories/credential-library.js @@ -1,5 +1,6 @@ import factory from '../generated/factories/credential-library'; import { random, system } from 'faker'; +import permissions from '../helpers/permissions'; const types = ['vault']; @@ -7,6 +8,14 @@ export default factory.extend({ id: (i) => `credential-library-id-${i}`, type: (i) => types[i % types.length], + authorized_actions: () => + permissions.authorizedActionsFor('credential-library') || [ + 'no-op', + 'read', + 'update', + 'delete', + ], + attributes() { switch (this.type) { case 'vault': diff --git a/addons/api/mirage/factories/group.js b/addons/api/mirage/factories/group.js index 79b28cc2e..1f7256543 100644 --- a/addons/api/mirage/factories/group.js +++ b/addons/api/mirage/factories/group.js @@ -1,7 +1,15 @@ import factory from '../generated/factories/group'; import { trait } from 'ember-cli-mirage'; +import permissions from '../helpers/permissions'; export default factory.extend({ + authorized_actions: () => + permissions.authorizedActionsFor('group') || [ + 'no-op', + 'read', + 'update', + 'delete', + ], id: (i) => `group-${i}`, /** diff --git a/addons/api/mirage/factories/target.js b/addons/api/mirage/factories/target.js index e40df6abf..94a15d0bb 100644 --- a/addons/api/mirage/factories/target.js +++ b/addons/api/mirage/factories/target.js @@ -1,11 +1,19 @@ import factory from '../generated/factories/target'; import { trait } from 'ember-cli-mirage'; import { random, datatype } from 'faker'; +import permissions from '../helpers/permissions'; const randomBoolean = (chance = 0.5) => Math.random() < chance; const hostSetChance = 0.3; export default factory.extend({ + authorized_actions: () => + permissions.authorizedActionsFor('target') || [ + 'no-op', + 'read', + 'update', + 'delete', + ], /** * -1 means "unlimited" and we want to generate these on occasion. */ diff --git a/addons/api/mirage/factories/user.js b/addons/api/mirage/factories/user.js index 39c5abf96..b8463506d 100644 --- a/addons/api/mirage/factories/user.js +++ b/addons/api/mirage/factories/user.js @@ -1,5 +1,13 @@ import factory from '../generated/factories/user'; +import permissions from '../helpers/permissions'; export default factory.extend({ + authorized_actions: () => + permissions.authorizedActionsFor('user') || [ + 'no-op', + 'read', + 'update', + 'delete', + ], id: (i) => `user-${i}`, }); diff --git a/ui/admin/app/components/form/credential-library/index.hbs b/ui/admin/app/components/form/credential-library/index.hbs index 3e3add0ee..29d016e7c 100644 --- a/ui/admin/app/components/form/credential-library/index.hbs +++ b/ui/admin/app/components/form/credential-library/index.hbs @@ -118,10 +118,13 @@ {{/if}} - + {{#if (can 'save model' @model)}} + + {{/if}} + \ No newline at end of file diff --git a/ui/admin/app/components/form/group/index.hbs b/ui/admin/app/components/form/group/index.hbs index a0c3230ef..7ed797846 100644 --- a/ui/admin/app/components/form/group/index.hbs +++ b/ui/admin/app/components/form/group/index.hbs @@ -46,11 +46,12 @@ {{/if}} - - + {{#if (can 'save model' @model)}} + + {{/if}} \ No newline at end of file diff --git a/ui/admin/app/components/form/target/index.hbs b/ui/admin/app/components/form/target/index.hbs index 8ce121b0a..efdda831f 100644 --- a/ui/admin/app/components/form/target/index.hbs +++ b/ui/admin/app/components/form/target/index.hbs @@ -111,12 +111,12 @@ {{/if}} - - - + {{#if (can 'save model' @model)}} + + {{/if}} \ No newline at end of file diff --git a/ui/admin/app/components/form/user/index.hbs b/ui/admin/app/components/form/user/index.hbs index a0c3230ef..7ed797846 100644 --- a/ui/admin/app/components/form/user/index.hbs +++ b/ui/admin/app/components/form/user/index.hbs @@ -46,11 +46,12 @@ {{/if}} - - + {{#if (can 'save model' @model)}} + + {{/if}} \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/-actions.hbs b/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/-actions.hbs index 759b187d5..4399f847b 100644 --- a/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/-actions.hbs +++ b/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/-actions.hbs @@ -1,13 +1,15 @@ - - - {{t 'resources.credential-library.actions.delete'}} - - \ No newline at end of file + + {{t 'resources.credential-library.actions.delete'}} + + +{{/if}} \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/index.hbs b/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/index.hbs index e97d52411..2bb3101c2 100644 --- a/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/index.hbs +++ b/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/index.hbs @@ -12,12 +12,16 @@ {{#each @model as |credentialLibrary|}} - + {{#if (can 'read model' credentialLibrary)}} + + {{credentialLibrary.displayName}} + + {{else}} {{credentialLibrary.displayName}} - + {{/if}}

{{credentialLibrary.description}}

diff --git a/ui/admin/app/templates/scopes/scope/groups/group/-actions.hbs b/ui/admin/app/templates/scopes/scope/groups/group/-actions.hbs index c1a11742e..253b39ab0 100644 --- a/ui/admin/app/templates/scopes/scope/groups/group/-actions.hbs +++ b/ui/admin/app/templates/scopes/scope/groups/group/-actions.hbs @@ -6,12 +6,14 @@ {{t 'resources.group.actions.add-members'}} - - - {{t 'resources.group.actions.delete'}} - + {{#if (can 'delete model' @model)}} + + + {{t 'resources.group.actions.delete'}} + + {{/if}} \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/groups/index.hbs b/ui/admin/app/templates/scopes/scope/groups/index.hbs index 64abb45ad..cb59fde2e 100644 --- a/ui/admin/app/templates/scopes/scope/groups/index.hbs +++ b/ui/admin/app/templates/scopes/scope/groups/index.hbs @@ -35,9 +35,16 @@ {{#each @model as |group|}} - + {{#if (can 'read model' group)}} + + {{group.displayName}} + + {{else}} {{group.displayName}} - + {{/if}}

{{group.description}}

diff --git a/ui/admin/app/templates/scopes/scope/targets/index.hbs b/ui/admin/app/templates/scopes/scope/targets/index.hbs index ec9a8d5f1..f8dcec9b4 100644 --- a/ui/admin/app/templates/scopes/scope/targets/index.hbs +++ b/ui/admin/app/templates/scopes/scope/targets/index.hbs @@ -38,12 +38,16 @@ {{#each @model as |target|}} - + {{#if (can 'read model' target)}} + + {{target.displayName}} + + {{else}} {{target.displayName}} - + {{/if}}

{{target.description}}

diff --git a/ui/admin/app/templates/scopes/scope/targets/target/-actions.hbs b/ui/admin/app/templates/scopes/scope/targets/target/-actions.hbs index 9c95b8fa2..2de077d3d 100644 --- a/ui/admin/app/templates/scopes/scope/targets/target/-actions.hbs +++ b/ui/admin/app/templates/scopes/scope/targets/target/-actions.hbs @@ -13,12 +13,14 @@ {{t 'resources.target.actions.add-credential-libraries'}} {{/if}} - - - {{t 'resources.target.actions.delete'}} - + {{#if (can 'delete model' @model)}} + + + {{t 'resources.target.actions.delete'}} + + {{/if}} \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/users/index.hbs b/ui/admin/app/templates/scopes/scope/users/index.hbs index 5d44a46b0..ab31bc1cf 100644 --- a/ui/admin/app/templates/scopes/scope/users/index.hbs +++ b/ui/admin/app/templates/scopes/scope/users/index.hbs @@ -37,9 +37,13 @@ {{#each @model as |user|}} - + {{#if (can 'read model' user)}} + + {{user.displayName}} + + {{else}} {{user.displayName}} - + {{/if}}

{{user.description}}

diff --git a/ui/admin/app/templates/scopes/scope/users/user/-actions.hbs b/ui/admin/app/templates/scopes/scope/users/user/-actions.hbs index 0947bef21..4f993d425 100644 --- a/ui/admin/app/templates/scopes/scope/users/user/-actions.hbs +++ b/ui/admin/app/templates/scopes/scope/users/user/-actions.hbs @@ -1,17 +1,19 @@ - - - {{t 'resources.user.actions.add-accounts'}} - - - - {{t 'resources.user.actions.delete'}} - - \ No newline at end of file + + {{t 'resources.user.actions.add-accounts'}} + + + + {{t 'resources.user.actions.delete'}} + + +{{/if}} \ No newline at end of file diff --git a/ui/admin/jsconfig.json b/ui/admin/jsconfig.json new file mode 100644 index 000000000..f408cac8c --- /dev/null +++ b/ui/admin/jsconfig.json @@ -0,0 +1 @@ +{"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]} \ No newline at end of file diff --git a/ui/admin/tests/acceptance/accounts/update-test.js b/ui/admin/tests/acceptance/accounts/update-test.js index ecce31da0..163b7ac9e 100644 --- a/ui/admin/tests/acceptance/accounts/update-test.js +++ b/ui/admin/tests/acceptance/accounts/update-test.js @@ -59,7 +59,7 @@ module('Acceptance | accounts | update', function (hooks) { } }); - test('can update an account and save changes', async function (assert) { + test('can update resource and save changes', async function (assert) { assert.expect(1); await visit(urls.account); await click('form [type="button"]', 'Activate edit mode'); @@ -68,6 +68,14 @@ module('Acceptance | accounts | update', function (hooks) { assert.equal(this.server.db.accounts[0].name, 'update name'); }); + test('cannot update resource without proper authorization', async function (assert) { + assert.expect(1); + instances.account.authorized_actions = + instances.account.authorized_actions.filter((item) => item !== 'update'); + await visit(urls.account); + assert.notOk(find('form [type="button"]')); + }); + test('can update an account and cancel changes', async function (assert) { assert.expect(1); await visit(urls.account); diff --git a/ui/admin/tests/acceptance/credential-libraries-test.js b/ui/admin/tests/acceptance/credential-libraries-test.js new file mode 100644 index 000000000..d4dcce482 --- /dev/null +++ b/ui/admin/tests/acceptance/credential-libraries-test.js @@ -0,0 +1,138 @@ +import { module, test } from 'qunit'; +import { visit, click, fillIn, currentURL, find } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import a11yAudit from 'ember-a11y-testing/test-support/audit'; +import { authenticateSession } from 'ember-simple-auth/test-support'; +import { Response } from 'miragejs'; + +module('Acceptance | credential-libraries', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + let getCredentialLibraryCount; + + const instances = { + scopes: { + global: null, + org: null, + project: null, + }, + }; + + const urls = { + globalScope: null, + orgScope: null, + projectScope: null, + credentialStores: null, + credentialStore: null, + credentialLibrary: null, + credentialLibraries: null, + newCredentialLibrary: null, + unknownCredentialLibrary: null, + }; + + hooks.beforeEach(function () { + // Generate resources + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + instances.scopes.project = this.server.create('scope', { + type: 'project', + scope: { id: instances.scopes.org.id, type: 'org' }, + }); + instances.credentialStore = this.server.create('credential-store', { + scope: instances.scopes.project, + }); + instances.credentialLibrary = this.server.create('credential-library', { + scope: instances.scopes.project, + credentialStore: instances.credentialStore, + }); + // 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.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`; + urls.credentialLibraries = `${urls.credentialStore}/credential-libraries`; + urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`; + urls.newCredentialLibrary = `${urls.credentialLibraries}/new`; + urls.unknownCredentialLibrary = `${urls.credentialLibraries}/foo`; + // Generate resource counter + getCredentialLibraryCount = () => + this.server.schema.credentialLibraries.all().models.length; + authenticateSession({}); + }); + + test('visiting credential libraries', async function (assert) { + assert.expect(2); + await visit(urls.credentialLibraries); + await a11yAudit(); + assert.equal(currentURL(), urls.credentialLibraries); + await visit(urls.credentialLibrary); + await a11yAudit(); + assert.equal(currentURL(), urls.credentialLibrary); + }); + + test('visiting an unknown credential library displays 404 message', async function (assert) { + assert.expect(1); + await visit(urls.unknownCredentialLibrary); + await a11yAudit(); + console.debug(find('.rose-message-subtitle')); + assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404'); + }); + + test('can create a credential library', async function (assert) { + assert.expect(1); + const count = getCredentialLibraryCount(); + await visit(urls.newCredentialLibrary); + await fillIn('[name="name"]', 'random string'); + await click('[type="submit"]'); + assert.equal(getCredentialLibraryCount(), count + 1); + }); + + test('can cancel create a new credential library', async function (assert) { + assert.expect(2); + const count = getCredentialLibraryCount(); + await visit(urls.newCredentialLibrary); + await fillIn('[name="name"]', 'random string'); + await click('.rose-form-actions [type="button"]'); + assert.equal(currentURL(), urls.credentialLibraries); + assert.equal(getCredentialLibraryCount(), count); + }); + + test('saving a new credential library with invalid fields displays error messasges', async function (assert) { + assert.expect(2); + this.server.post('/credential-libraries', () => { + return new Response( + 400, + {}, + { + status: 400, + code: 'invalid_argument', + message: 'The request was invalid', + details: { + request_fields: [ + { + name: 'name', + description: 'Name is required.', + }, + ], + }, + } + ); + }); + await visit(urls.newCredentialLibrary); + await click('[type="submit"]'); + assert.ok( + find('[role="alert"]').textContent.trim(), + 'The request was invalid.' + ); + assert.ok( + find('.rose-form-error-message').textContent.trim(), + 'Name is required.' + ); + }); +}); diff --git a/ui/admin/tests/acceptance/credential-library/delete-test.js b/ui/admin/tests/acceptance/credential-library/delete-test.js new file mode 100644 index 000000000..e539d00e9 --- /dev/null +++ b/ui/admin/tests/acceptance/credential-library/delete-test.js @@ -0,0 +1,131 @@ +import { module, test } from 'qunit'; +import { visit, click, find } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { authenticateSession } from 'ember-simple-auth/test-support'; +import { Response } from 'miragejs'; +import { resolve, reject } from 'rsvp'; +import sinon from 'sinon'; + +module('Acceptance | credential-libraries | delete', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + let getCredentialLibraryCount; + + const instances = { + scopes: { + global: null, + org: null, + project: null, + }, + }; + + const urls = { + globalScope: null, + orgScope: null, + projectScope: null, + credentialStores: null, + credentialStore: null, + credentialLibrary: null, + credentialLibraries: null, + newCredentialLibrary: null, + unknownCredentialLibrary: null, + }; + + hooks.beforeEach(function () { + // Generate resources + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + instances.scopes.project = this.server.create('scope', { + type: 'project', + scope: { id: instances.scopes.org.id, type: 'org' }, + }); + instances.credentialStore = this.server.create('credential-store', { + scope: instances.scopes.project, + }); + instances.credentialLibrary = this.server.create('credential-library', { + scope: instances.scopes.project, + credentialStore: instances.credentialStore, + }); + // 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.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`; + urls.credentialLibraries = `${urls.credentialStore}/credential-libraries`; + urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`; + urls.newCredentialLibrary = `${urls.credentialLibraries}/new`; + urls.unknownCredentialLibrary = `${urls.credentialLibraries}/foo`; + // Generate resource counter + getCredentialLibraryCount = () => + this.server.schema.credentialLibraries.all().models.length; + authenticateSession({}); + }); + + test('can delete resource', async function (assert) { + assert.expect(1); + const count = getCredentialLibraryCount(); + await visit(urls.credentialLibrary); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(getCredentialLibraryCount(), count - 1); + }); + + test('cannot delete resource without proper authorization', async function (assert) { + assert.expect(1); + instances.credentialLibrary.authorized_actions = + instances.credentialLibrary.authorized_actions.filter( + (item) => item !== 'delete' + ); + await visit(urls.credentialLibrary); + assert.notOk( + find('.rose-layout-page-actions .rose-dropdown-button-danger') + ); + }); + + test('can accept delete credential library via dialog', async function (assert) { + assert.expect(2); + const confirmService = this.owner.lookup('service:confirm'); + confirmService.enabled = true; + confirmService.confirm = sinon.fake.returns(resolve()); + const count = getCredentialLibraryCount(); + await visit(urls.credentialLibrary); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(getCredentialLibraryCount(), count - 1); + assert.ok(confirmService.confirm.calledOnce); + }); + + test('cannot cancel delete credential library via dialog', async function (assert) { + assert.expect(2); + const confirmService = this.owner.lookup('service:confirm'); + confirmService.enabled = true; + confirmService.confirm = sinon.fake.returns(reject()); + const count = getCredentialLibraryCount(); + await visit(urls.credentialLibrary); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(getCredentialLibraryCount(), count); + assert.ok(confirmService.confirm.calledOnce); + }); + + test('deleting a credential library which errors displays error messages', async function (assert) { + assert.expect(1); + this.server.del('/credential-libraries/:id', () => { + return new Response( + 490, + {}, + { + status: 490, + code: 'error', + message: 'Oops.', + } + ); + }); + await visit(urls.credentialLibrary); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.'); + }); +}); diff --git a/ui/admin/tests/acceptance/credential-library/read-test.js b/ui/admin/tests/acceptance/credential-library/read-test.js new file mode 100644 index 000000000..6e94637da --- /dev/null +++ b/ui/admin/tests/acceptance/credential-library/read-test.js @@ -0,0 +1,80 @@ +import { module, test } from 'qunit'; +import { visit, click, currentURL, find } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import a11yAudit from 'ember-a11y-testing/test-support/audit'; +import { authenticateSession } from 'ember-simple-auth/test-support'; + +module('Acceptance | credential-libraries | read', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + const instances = { + scopes: { + global: null, + org: null, + project: null, + }, + }; + + const urls = { + globalScope: null, + orgScope: null, + projectScope: null, + credentialStores: null, + credentialStore: null, + credentialLibrary: null, + credentialLibraries: null, + newCredentialLibrary: null, + unknownCredentialLibrary: null, + }; + + hooks.beforeEach(function () { + // Generate resources + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + instances.scopes.project = this.server.create('scope', { + type: 'project', + scope: { id: instances.scopes.org.id, type: 'org' }, + }); + instances.credentialStore = this.server.create('credential-store', { + scope: instances.scopes.project, + }); + instances.credentialLibrary = this.server.create('credential-library', { + scope: instances.scopes.project, + credentialStore: instances.credentialStore, + }); + // 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.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`; + urls.credentialLibraries = `${urls.credentialStore}/credential-libraries`; + urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`; + urls.newCredentialLibrary = `${urls.credentialLibraries}/new`; + urls.unknownCredentialLibrary = `${urls.credentialLibraries}/foo`; + authenticateSession({}); + }); + + test('can navigate to resource', async function (assert) { + assert.expect(1); + await visit(urls.credentialLibraries); + await click('main tbody .rose-table-header-cell a'); + await a11yAudit(); + assert.equal(currentURL(), urls.credentialLibrary); + }); + + test('cannot navigate to resource without proper authorization', async function (assert) { + assert.expect(1); + instances.credentialLibrary.authorized_actions = + instances.credentialLibrary.authorized_actions.filter( + (item) => item !== 'read' + ); + await visit(urls.credentialLibraries); + assert.notOk(find('main tbody .rose-table-header-cell a')); + }); +}); diff --git a/ui/admin/tests/acceptance/credential-library/credential-library-test.js b/ui/admin/tests/acceptance/credential-library/update-test.js similarity index 56% rename from ui/admin/tests/acceptance/credential-library/credential-library-test.js rename to ui/admin/tests/acceptance/credential-library/update-test.js index c2b71f8f1..7958ccc6f 100644 --- a/ui/admin/tests/acceptance/credential-library/credential-library-test.js +++ b/ui/admin/tests/acceptance/credential-library/update-test.js @@ -2,18 +2,13 @@ import { module, test } from 'qunit'; import { visit, click, fillIn, currentURL, find } from '@ember/test-helpers'; import { setupApplicationTest } from 'ember-qunit'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; -import a11yAudit from 'ember-a11y-testing/test-support/audit'; import { authenticateSession } from 'ember-simple-auth/test-support'; import { Response } from 'miragejs'; -import { resolve, reject } from 'rsvp'; -import sinon from 'sinon'; -module('Acceptance | credential-library', function (hooks) { +module('Acceptance | credential-libraries | update', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); - let getCredentialLibraryCount; - const instances = { scopes: { global: null, @@ -50,6 +45,7 @@ module('Acceptance | credential-library', function (hooks) { }); instances.credentialLibrary = this.server.create('credential-library', { scope: instances.scopes.project, + credentialStore: instances.credentialStore, }); // Generate route URLs for resources urls.globalScope = `/scopes/global/scopes`; @@ -61,83 +57,10 @@ module('Acceptance | credential-library', function (hooks) { urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`; urls.newCredentialLibrary = `${urls.credentialLibraries}/new`; urls.unknownCredentialLibrary = `${urls.credentialLibraries}/foo`; - // Generate resource counter - getCredentialLibraryCount = () => - this.server.schema.credentialLibraries.all().models.length; authenticateSession({}); }); - test('visiting credential libraries', async function (assert) { - assert.expect(2); - await visit(urls.credentialLibraries); - await a11yAudit(); - assert.equal(currentURL(), urls.credentialLibraries); - await visit(urls.credentialLibrary); - await a11yAudit(); - assert.equal(currentURL(), urls.credentialLibrary); - }); - - test('visiting an unknown credential library displays 404 message', async function (assert) { - assert.expect(1); - await visit(urls.unknownCredentialLibrary); - await a11yAudit(); - console.debug(find('.rose-message-subtitle')); - assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404'); - }); - - test('can create a credential library', async function (assert) { - assert.expect(1); - const count = getCredentialLibraryCount(); - await visit(urls.newCredentialLibrary); - await fillIn('[name="name"]', 'random string'); - await click('[type="submit"]'); - assert.equal(getCredentialLibraryCount(), count + 1); - }); - - test('can cancel create a new credential library', async function (assert) { - assert.expect(2); - const count = getCredentialLibraryCount(); - await visit(urls.newCredentialLibrary); - await fillIn('[name="name"]', 'random string'); - await click('.rose-form-actions [type="button"]'); - assert.equal(currentURL(), urls.credentialLibraries); - assert.equal(getCredentialLibraryCount(), count); - }); - - test('saving a new credential library with invalid fields displays error messasges', async function (assert) { - assert.expect(2); - this.server.post('/credential-libraries', () => { - return new Response( - 400, - {}, - { - status: 400, - code: 'invalid_argument', - message: 'The request was invalid', - details: { - request_fields: [ - { - name: 'name', - description: 'Name is required.', - }, - ], - }, - } - ); - }); - await visit(urls.newCredentialLibrary); - await click('[type="submit"]'); - assert.ok( - find('[role="alert"]').textContent.trim(), - 'The request was invalid.' - ); - assert.ok( - find('.rose-form-error-message').textContent.trim(), - 'Name is required.' - ); - }); - - test('can save changes to existing credential library', async function (assert) { + test('can update resource and save changes', async function (assert) { assert.expect(3); assert.notEqual(instances.credentialLibrary.name, 'random string'); await visit(urls.credentialLibrary); @@ -151,7 +74,17 @@ module('Acceptance | credential-library', function (hooks) { ); }); - test('can cancel changes to existing credential library', async function (assert) { + test('cannot update resource without proper authorization', async function (assert) { + assert.expect(1); + instances.credentialLibrary.authorized_actions = + instances.credentialLibrary.authorized_actions.filter( + (item) => item !== 'update' + ); + await visit(urls.credentialLibrary); + assert.notOk(find('form [type="button"]')); + }); + + test('can update a credential library and cancel changes', async function (assert) { assert.expect(2); await visit(urls.credentialLibrary); await click('form [type="button"]', 'Activate edit mode'); @@ -245,54 +178,4 @@ module('Acceptance | credential-library', function (hooks) { ); } }); - - test('can delete credential library', async function (assert) { - assert.expect(1); - const count = getCredentialLibraryCount(); - await visit(urls.credentialLibrary); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.equal(getCredentialLibraryCount(), count - 1); - }); - - test('can accept delete credential library via dialog', async function (assert) { - assert.expect(2); - const confirmService = this.owner.lookup('service:confirm'); - confirmService.enabled = true; - confirmService.confirm = sinon.fake.returns(resolve()); - const count = getCredentialLibraryCount(); - await visit(urls.credentialLibrary); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.equal(getCredentialLibraryCount(), count - 1); - assert.ok(confirmService.confirm.calledOnce); - }); - - test('cannot cancel delete credential library via dialog', async function (assert) { - assert.expect(2); - const confirmService = this.owner.lookup('service:confirm'); - confirmService.enabled = true; - confirmService.confirm = sinon.fake.returns(reject()); - const count = getCredentialLibraryCount(); - await visit(urls.credentialLibrary); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.equal(getCredentialLibraryCount(), count); - assert.ok(confirmService.confirm.calledOnce); - }); - - test('deleting a credential library which errors displays error messages', async function (assert) { - assert.expect(1); - this.server.del('/credential-libraries/:id', () => { - return new Response( - 490, - {}, - { - status: 490, - code: 'error', - message: 'Oops.', - } - ); - }); - await visit(urls.credentialLibrary); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.'); - }); }); diff --git a/ui/admin/tests/acceptance/groups-test.js b/ui/admin/tests/acceptance/groups-test.js index 1dfb81a7c..38b95d60d 100644 --- a/ui/admin/tests/acceptance/groups-test.js +++ b/ui/admin/tests/acceptance/groups-test.js @@ -2,7 +2,6 @@ import { module, test } from 'qunit'; import { visit, currentURL, click, fillIn, find } from '@ember/test-helpers'; import { setupApplicationTest } from 'ember-qunit'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; -import a11yAudit from 'ember-a11y-testing/test-support/audit'; import { Response } from 'miragejs'; import { authenticateSession, @@ -44,20 +43,6 @@ module('Acceptance | groups', function (hooks) { urls.newGroup = `${urls.groups}/new`; }); - test('visiting groups', async function (assert) { - assert.expect(1); - await visit(urls.groups); - await a11yAudit(); - assert.equal(currentURL(), urls.groups); - }); - - test('visiting a group', async function (assert) { - assert.expect(1); - await visit(urls.newGroup); - await a11yAudit(); - assert.equal(currentURL(), urls.newGroup); - }); - test('can create new group', async function (assert) { assert.expect(1); const groupsCount = this.server.db.groups.length; @@ -112,90 +97,4 @@ module('Acceptance | groups', function (hooks) { 'Displays field-level errors.' ); }); - - test('can save changes to an existing group', async function (assert) { - assert.expect(2); - await visit(urls.group); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'Updated admin group'); - await click('.rose-form-actions [type="submit"]'); - assert.equal(currentURL(), urls.group); - assert.equal(this.server.db.groups[0].name, 'Updated admin group'); - }); - - test('can cancel changes to an existing group', async function (assert) { - assert.expect(1); - await visit(urls.group); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'Updated admin group'); - await click('.rose-form-actions [type="button"]'); - assert.notEqual(find('[name="name"]').value, 'Updated admin group'); - }); - - test('can delete a group', async function (assert) { - assert.expect(1); - const groupsCount = this.server.db.groups.length; - await visit(urls.group); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.equal(this.server.db.groups.length, groupsCount - 1); - }); - - test('saving an existing group with invalid fields displays error messages', async function (assert) { - assert.expect(2); - this.server.patch('/groups/:id', () => { - return new Response( - 400, - {}, - { - status: 400, - code: 'invalid_argument', - message: 'The request was invalid.', - details: { - request_fields: [ - { - name: 'name', - description: 'Name is required.', - }, - ], - }, - } - ); - }); - await visit(urls.group); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'random string'); - await click('[type="submit"]'); - assert.ok( - find('[role="alert"]').textContent.trim(), - 'The request was invalid.', - 'Displays primary error message.' - ); - assert.ok( - find('.rose-form-error-message').textContent.trim(), - 'Name is required.', - 'Displays field-level errors.' - ); - }); - - test('errors are displayed when delete project fails', async function (assert) { - assert.expect(1); - this.server.del('/groups/:id', () => { - return new Response( - 490, - {}, - { - status: 490, - code: 'error', - message: 'Oops.', - } - ); - }); - await visit(urls.group); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.ok( - find('[role="alert"]').textContent.trim(), - 'Oops.', - 'Displays primary error message.' - ); - }); }); diff --git a/ui/admin/tests/acceptance/groups/delete-test.js b/ui/admin/tests/acceptance/groups/delete-test.js new file mode 100644 index 000000000..c1dec7fdb --- /dev/null +++ b/ui/admin/tests/acceptance/groups/delete-test.js @@ -0,0 +1,85 @@ +import { module, test } from 'qunit'; +import { visit, click, find } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { Response } from 'miragejs'; +import { + authenticateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, +} from 'ember-simple-auth/test-support'; + +module('Acceptance | groups | delete', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + const instances = { + scopes: { + global: null, + org: null, + }, + group: null, + }; + const urls = { + orgScope: null, + groups: null, + group: null, + newGroup: null, + }; + + hooks.beforeEach(function () { + authenticateSession({}); + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + instances.group = this.server.create('group', { + scope: instances.scopes.org, + }); + urls.groups = `/scopes/${instances.scopes.org.id}/groups`; + urls.group = `${urls.groups}/${instances.group.id}`; + urls.newGroup = `${urls.groups}/new`; + }); + + test('can delete a group', async function (assert) { + assert.expect(1); + const groupsCount = this.server.db.groups.length; + await visit(urls.group); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(this.server.db.groups.length, groupsCount - 1); + }); + + test('cannot delete a group without proper authorization', async function (assert) { + assert.expect(1); + instances.group.authorized_actions = + instances.group.authorized_actions.filter((item) => item !== 'delete'); + await visit(urls.group); + assert.notOk( + find('.rose-layout-page-actions .rose-dropdown-button-danger') + ); + }); + + test('errors are displayed when delete project fails', async function (assert) { + assert.expect(1); + this.server.del('/groups/:id', () => { + return new Response( + 490, + {}, + { + status: 490, + code: 'error', + message: 'Oops.', + } + ); + }); + await visit(urls.group); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.ok( + find('[role="alert"]').textContent.trim(), + 'Oops.', + 'Displays primary error message.' + ); + }); +}); diff --git a/ui/admin/tests/acceptance/groups/read-test.js b/ui/admin/tests/acceptance/groups/read-test.js new file mode 100644 index 000000000..535ea1175 --- /dev/null +++ b/ui/admin/tests/acceptance/groups/read-test.js @@ -0,0 +1,60 @@ +import { module, test } from 'qunit'; +import { visit, currentURL, find } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +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'; + +module('Acceptance | groups | read', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + const instances = { + scopes: { + global: null, + org: null, + }, + group: null, + }; + const urls = { + orgScope: null, + groups: null, + group: null, + newGroup: null, + }; + + hooks.beforeEach(function () { + authenticateSession({}); + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + instances.group = this.server.create('group', { + scope: instances.scopes.org, + }); + urls.groups = `/scopes/${instances.scopes.org.id}/groups`; + urls.group = `${urls.groups}/${instances.group.id}`; + urls.newGroup = `${urls.groups}/new`; + }); + + test('visiting a group', async function (assert) { + assert.expect(1); + await visit(urls.newGroup); + await a11yAudit(); + assert.equal(currentURL(), urls.newGroup); + }); + + test('cannot navigate to a group form without proper authorization', async function (assert) { + assert.expect(1); + instances.group.authorized_actions = + instances.group.authorized_actions.filter((item) => item !== 'read'); + await visit(urls.group); + assert.notOk(find('main tbody .rose-table-header-cell:nth-child(1) a')); + }); +}); diff --git a/ui/admin/tests/acceptance/groups/update-test.js b/ui/admin/tests/acceptance/groups/update-test.js new file mode 100644 index 000000000..6d39cefbe --- /dev/null +++ b/ui/admin/tests/acceptance/groups/update-test.js @@ -0,0 +1,109 @@ +import { module, test } from 'qunit'; +import { visit, currentURL, click, find, fillIn } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { Response } from 'miragejs'; +import { + authenticateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, +} from 'ember-simple-auth/test-support'; + +module('Acceptance | groups | update', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + const instances = { + scopes: { + global: null, + org: null, + }, + group: null, + }; + const urls = { + orgScope: null, + groups: null, + group: null, + newGroup: null, + }; + + hooks.beforeEach(function () { + authenticateSession({}); + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + instances.group = this.server.create('group', { + scope: instances.scopes.org, + }); + urls.groups = `/scopes/${instances.scopes.org.id}/groups`; + urls.group = `${urls.groups}/${instances.group.id}`; + urls.newGroup = `${urls.groups}/new`; + }); + + test('can save changes to an existing group', async function (assert) { + assert.expect(2); + await visit(urls.group); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'Updated admin group'); + await click('.rose-form-actions [type="submit"]'); + assert.equal(currentURL(), urls.group); + assert.equal(this.server.db.groups[0].name, 'Updated admin group'); + }); + + test('cannot make changes to an existing group without proper authorization', async function (assert) { + assert.expect(1); + instances.group.authorized_actions = + instances.group.authorized_actions.filter((item) => item !== 'update'); + await visit(urls.group); + assert.notOk(find('.rose-layout-page-actions .rose-button-secondary')); + }); + + test('can cancel changes to an existing group', async function (assert) { + assert.expect(1); + await visit(urls.group); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'Updated admin group'); + await click('.rose-form-actions [type="button"]'); + assert.notEqual(find('[name="name"]').value, 'Updated admin group'); + }); + + test('saving an existing group with invalid fields displays error messages', async function (assert) { + assert.expect(2); + this.server.patch('/groups/:id', () => { + return new Response( + 400, + {}, + { + status: 400, + code: 'invalid_argument', + message: 'The request was invalid.', + details: { + request_fields: [ + { + name: 'name', + description: 'Name is required.', + }, + ], + }, + } + ); + }); + await visit(urls.group); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'random string'); + await click('[type="submit"]'); + assert.ok( + find('[role="alert"]').textContent.trim(), + 'The request was invalid.', + 'Displays primary error message.' + ); + assert.ok( + find('.rose-form-error-message').textContent.trim(), + 'Name is required.', + 'Displays field-level errors.' + ); + }); +}); diff --git a/ui/admin/tests/acceptance/targets-test.js b/ui/admin/tests/acceptance/targets-test.js index d6907503c..cf202c049 100644 --- a/ui/admin/tests/acceptance/targets-test.js +++ b/ui/admin/tests/acceptance/targets-test.js @@ -2,10 +2,7 @@ import { module, test } from 'qunit'; import { visit, currentURL, find, click, fillIn } from '@ember/test-helpers'; import { setupApplicationTest } from 'ember-qunit'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; -import a11yAudit from 'ember-a11y-testing/test-support/audit'; import { Response } from 'miragejs'; -import { resolve, reject } from 'rsvp'; -import sinon from 'sinon'; import { authenticateSession, // These are left here intentionally for future reference. @@ -62,23 +59,6 @@ module('Acceptance | targets', function (hooks) { authenticateSession({}); }); - test('visiting targets', async function (assert) { - assert.expect(2); - await visit(urls.targets); - await a11yAudit(); - assert.equal(currentURL(), urls.targets); - await visit(urls.target); - await a11yAudit(); - assert.equal(currentURL(), urls.target); - }); - - test('visiting an unknown target displays 404 message', async function (assert) { - assert.expect(1); - await visit(urls.unknownTarget); - await a11yAudit(); - assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404'); - }); - test('can create new targets', async function (assert) { assert.expect(1); const count = getTargetCount(); @@ -130,157 +110,4 @@ module('Acceptance | targets', function (hooks) { 'Name is required.' ); }); - - test('can save changes to existing target', async function (assert) { - assert.expect(3); - assert.notEqual(instances.target.name, 'random string'); - await visit(urls.target); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'random string'); - await click('.rose-form-actions [type="submit"]'); - assert.equal(currentURL(), urls.target); - assert.equal( - this.server.schema.targets.all().models[0].name, - 'random string' - ); - }); - - test('can cancel changes to existing target', async function (assert) { - assert.expect(2); - await visit(urls.target); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'random string'); - await click('.rose-form-actions [type="button"]'); - assert.notEqual(instances.target.name, 'random string'); - assert.equal(find('[name="name"]').value, instances.target.name); - }); - - test('saving an existing target with invalid fields displays error messages', async function (assert) { - assert.expect(2); - this.server.patch('/targets/:id', () => { - return new Response( - 400, - {}, - { - status: 400, - code: 'invalid_argument', - message: 'The request was invalid.', - details: { - request_fields: [ - { - name: 'name', - description: 'Name is required.', - }, - ], - }, - } - ); - }); - await visit(urls.target); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'random string'); - await click('[type="submit"]'); - assert.ok( - find('[role="alert"]').textContent.trim(), - 'The request was invalid.' - ); - assert.ok( - find('.rose-form-error-message').textContent.trim(), - 'Name is required.' - ); - }); - - test('can discard unsaved target changes via dialog', async function (assert) { - assert.expect(5); - const confirmService = this.owner.lookup('service:confirm'); - confirmService.enabled = true; - assert.notEqual(instances.target.name, 'random string'); - await visit(urls.target); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'random string'); - assert.equal(currentURL(), urls.target); - try { - await visit(urls.targets); - } catch (e) { - assert.ok(find('.rose-dialog')); - await click('.rose-dialog-footer button:first-child'); - assert.equal(currentURL(), urls.targets); - assert.notEqual( - this.server.schema.targets.all().models[0].name, - 'random string' - ); - } - }); - - test('can cancel discard unsaved target changes via dialog', async function (assert) { - assert.expect(5); - const confirmService = this.owner.lookup('service:confirm'); - confirmService.enabled = true; - assert.notEqual(instances.target.name, 'random string'); - await visit(urls.target); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'random string'); - assert.equal(currentURL(), urls.target); - try { - await visit(urls.targets); - } catch (e) { - assert.ok(find('.rose-dialog')); - await click('.rose-dialog-footer button:last-child'); - assert.equal(currentURL(), urls.target); - assert.notEqual( - this.server.schema.targets.all().models[0].name, - 'random string' - ); - } - }); - - test('can delete target', async function (assert) { - assert.expect(1); - const count = getTargetCount(); - await visit(urls.target); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.equal(getTargetCount(), count - 1); - }); - - test('can accept delete target via dialog', async function (assert) { - assert.expect(2); - const confirmService = this.owner.lookup('service:confirm'); - confirmService.enabled = true; - confirmService.confirm = sinon.fake.returns(resolve()); - const count = getTargetCount(); - await visit(urls.target); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.equal(getTargetCount(), count - 1); - assert.ok(confirmService.confirm.calledOnce); - }); - - test('cannot cancel delete target via dialog', async function (assert) { - assert.expect(2); - const confirmService = this.owner.lookup('service:confirm'); - confirmService.enabled = true; - confirmService.confirm = sinon.fake.returns(reject()); - const count = getTargetCount(); - await visit(urls.target); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.equal(getTargetCount(), count); - assert.ok(confirmService.confirm.calledOnce); - }); - - test('deleting a target which errors displays error messages', async function (assert) { - assert.expect(1); - this.server.del('/targets/:id', () => { - return new Response( - 490, - {}, - { - status: 490, - code: 'error', - message: 'Oops.', - } - ); - }); - await visit(urls.target); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.'); - }); }); diff --git a/ui/admin/tests/acceptance/targets/delete-test.js b/ui/admin/tests/acceptance/targets/delete-test.js new file mode 100644 index 000000000..01e491bd2 --- /dev/null +++ b/ui/admin/tests/acceptance/targets/delete-test.js @@ -0,0 +1,123 @@ +import { module, test } from 'qunit'; +import { visit, find, click } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { Response } from 'miragejs'; +import { resolve, reject } from 'rsvp'; +import sinon from 'sinon'; +import { + authenticateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, +} from 'ember-simple-auth/test-support'; + +module('Acceptance | targets | delete', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + let getTargetCount; + + const instances = { + scopes: { + global: null, + org: null, + project: null, + }, + }; + const urls = { + globalScope: null, + orgScope: null, + projectScope: null, + targets: null, + target: null, + newTarget: null, + }; + + hooks.beforeEach(function () { + // Generate resources + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + instances.scopes.project = this.server.create('scope', { + type: 'project', + scope: { id: instances.scopes.org.id, type: 'org' }, + }); + instances.target = this.server.create('target', { + scope: instances.scopes.project, + }); + // 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.unknownTarget = `${urls.targets}/foo`; + urls.newTarget = `${urls.targets}/new`; + // Generate resource couner + getTargetCount = () => this.server.schema.targets.all().models.length; + authenticateSession({}); + }); + + test('can delete target', async function (assert) { + assert.expect(1); + const count = getTargetCount(); + await visit(urls.target); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(getTargetCount(), count - 1); + }); + + test('can accept delete target via dialog', async function (assert) { + assert.expect(2); + const confirmService = this.owner.lookup('service:confirm'); + confirmService.enabled = true; + confirmService.confirm = sinon.fake.returns(resolve()); + const count = getTargetCount(); + await visit(urls.target); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(getTargetCount(), count - 1); + assert.ok(confirmService.confirm.calledOnce); + }); + + test('cannot cancel delete target via dialog', async function (assert) { + assert.expect(2); + const confirmService = this.owner.lookup('service:confirm'); + confirmService.enabled = true; + confirmService.confirm = sinon.fake.returns(reject()); + const count = getTargetCount(); + await visit(urls.target); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(getTargetCount(), count); + assert.ok(confirmService.confirm.calledOnce); + }); + + test('cannot delete target without proper authorization', async function (assert) { + assert.expect(1); + instances.target.authorized_actions = + instances.target.authorized_actions.filter((item) => item !== 'delete'); + await visit(urls.target); + assert.notOk( + find('.rose-layout-page-actions .rose-dropdown-button-danger') + ); + }); + + test('deleting a target which errors displays error messages', async function (assert) { + assert.expect(1); + this.server.del('/targets/:id', () => { + return new Response( + 490, + {}, + { + status: 490, + code: 'error', + message: 'Oops.', + } + ); + }); + await visit(urls.target); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.'); + }); +}); diff --git a/ui/admin/tests/acceptance/targets/read-test.js b/ui/admin/tests/acceptance/targets/read-test.js new file mode 100644 index 000000000..232887d8d --- /dev/null +++ b/ui/admin/tests/acceptance/targets/read-test.js @@ -0,0 +1,83 @@ +import { module, test } from 'qunit'; +import { visit, currentURL, find } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +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'; + +module('Acceptance | targets | read', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + const instances = { + scopes: { + global: null, + org: null, + project: null, + }, + }; + const urls = { + globalScope: null, + orgScope: null, + projectScope: null, + targets: null, + target: null, + newTarget: null, + }; + + hooks.beforeEach(function () { + // Generate resources + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + instances.scopes.project = this.server.create('scope', { + type: 'project', + scope: { id: instances.scopes.org.id, type: 'org' }, + }); + instances.target = this.server.create('target', { + scope: instances.scopes.project, + }); + // 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.unknownTarget = `${urls.targets}/foo`; + urls.newTarget = `${urls.targets}/new`; + // Generate resource couner + authenticateSession({}); + }); + + test('visiting targets', async function (assert) { + assert.expect(2); + await visit(urls.targets); + await a11yAudit(); + assert.equal(currentURL(), urls.targets); + await visit(urls.target); + await a11yAudit(); + assert.equal(currentURL(), urls.target); + }); + + test('cannot navigate to target form without proper authorization', async function (assert) { + assert.expect(1); + instances.target.authorized_actions = + instances.target.authorized_actions.filter((item) => item !== 'read'); + await visit(urls.target); + assert.notOk(find('main tbody .rose-table-header-cell:nth-child(1) a')); + }); + + test('visiting an unknown target displays 404 message', async function (assert) { + assert.expect(1); + await visit(urls.unknownTarget); + await a11yAudit(); + assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404'); + }); +}); diff --git a/ui/admin/tests/acceptance/targets/update-test.js b/ui/admin/tests/acceptance/targets/update-test.js new file mode 100644 index 000000000..01176ac13 --- /dev/null +++ b/ui/admin/tests/acceptance/targets/update-test.js @@ -0,0 +1,202 @@ +import { module, test } from 'qunit'; +import { visit, currentURL, find, click, fillIn } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { Response } from 'miragejs'; +import { + authenticateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, +} from 'ember-simple-auth/test-support'; + +module('Acceptance | targets | update', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + const instances = { + scopes: { + global: null, + org: null, + project: null, + }, + }; + const urls = { + globalScope: null, + orgScope: null, + projectScope: null, + targets: null, + target: null, + newTarget: null, + }; + + hooks.beforeEach(function () { + // Generate resources + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + instances.scopes.project = this.server.create('scope', { + type: 'project', + scope: { id: instances.scopes.org.id, type: 'org' }, + }); + instances.target = this.server.create('target', { + scope: instances.scopes.project, + }); + // 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.unknownTarget = `${urls.targets}/foo`; + urls.newTarget = `${urls.targets}/new`; + // Generate resource couner + authenticateSession({}); + }); + + test('saving a new target with invalid fields displays error messages', async function (assert) { + assert.expect(2); + this.server.post('/targets', () => { + return new Response( + 400, + {}, + { + status: 400, + code: 'invalid_argument', + message: 'The request was invalid.', + details: { + request_fields: [ + { + name: 'name', + description: 'Name is required.', + }, + ], + }, + } + ); + }); + await visit(urls.newTarget); + await click('[type="submit"]'); + assert.ok( + find('[role="alert"]').textContent.trim(), + 'The request was invalid.' + ); + assert.ok( + find('.rose-form-error-message').textContent.trim(), + 'Name is required.' + ); + }); + + test('can save changes to existing target', async function (assert) { + assert.expect(3); + assert.notEqual(instances.target.name, 'random string'); + await visit(urls.target); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'random string'); + await click('.rose-form-actions [type="submit"]'); + assert.equal(currentURL(), urls.target); + assert.equal( + this.server.schema.targets.all().models[0].name, + 'random string' + ); + }); + + test('can cancel changes to existing target', async function (assert) { + assert.expect(2); + await visit(urls.target); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'random string'); + await click('.rose-form-actions [type="button"]'); + assert.notEqual(instances.target.name, 'random string'); + assert.equal(find('[name="name"]').value, instances.target.name); + }); + + test('saving an existing target with invalid fields displays error messages', async function (assert) { + assert.expect(2); + this.server.patch('/targets/:id', () => { + return new Response( + 400, + {}, + { + status: 400, + code: 'invalid_argument', + message: 'The request was invalid.', + details: { + request_fields: [ + { + name: 'name', + description: 'Name is required.', + }, + ], + }, + } + ); + }); + await visit(urls.target); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'random string'); + await click('[type="submit"]'); + assert.ok( + find('[role="alert"]').textContent.trim(), + 'The request was invalid.' + ); + assert.ok( + find('.rose-form-error-message').textContent.trim(), + 'Name is required.' + ); + }); + + test('can discard unsaved target changes via dialog', async function (assert) { + assert.expect(5); + const confirmService = this.owner.lookup('service:confirm'); + confirmService.enabled = true; + assert.notEqual(instances.target.name, 'random string'); + await visit(urls.target); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'random string'); + assert.equal(currentURL(), urls.target); + try { + await visit(urls.targets); + } catch (e) { + assert.ok(find('.rose-dialog')); + await click('.rose-dialog-footer button:first-child'); + assert.equal(currentURL(), urls.targets); + assert.notEqual( + this.server.schema.targets.all().models[0].name, + 'random string' + ); + } + }); + + test('can cancel discard unsaved target changes via dialog', async function (assert) { + assert.expect(5); + const confirmService = this.owner.lookup('service:confirm'); + confirmService.enabled = true; + assert.notEqual(instances.target.name, 'random string'); + await visit(urls.target); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'random string'); + assert.equal(currentURL(), urls.target); + try { + await visit(urls.targets); + } catch (e) { + assert.ok(find('.rose-dialog')); + await click('.rose-dialog-footer button:last-child'); + assert.equal(currentURL(), urls.target); + assert.notEqual( + this.server.schema.targets.all().models[0].name, + 'random string' + ); + } + }); + + test('cannot make changes to an existing target without proper authorization', async function (assert) { + assert.expect(1); + instances.target.authorized_actions = + instances.target.authorized_actions.filter((item) => item !== 'update'); + await visit(urls.target); + assert.notOk(find('.rose-layout-page-actions .rose-button-secondary')); + }); +}); diff --git a/ui/admin/tests/acceptance/users-test.js b/ui/admin/tests/acceptance/users-test.js index 065f8974b..b047a0d2a 100644 --- a/ui/admin/tests/acceptance/users-test.js +++ b/ui/admin/tests/acceptance/users-test.js @@ -2,7 +2,6 @@ import { module, test } from 'qunit'; import { visit, currentURL, click, fillIn, find } from '@ember/test-helpers'; import { setupApplicationTest } from 'ember-qunit'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; -import a11yAudit from 'ember-a11y-testing/test-support/audit'; import { Response } from 'miragejs'; import { authenticateSession, @@ -17,7 +16,6 @@ module('Acceptance | users', function (hooks) { let orgScope; let usersURL; - let userURL; let newUserURL; hooks.beforeEach(function () { @@ -29,31 +27,12 @@ module('Acceptance | users', function (hooks) { 'withChildren' ); - const user = this.server.create('user', { - scope: orgScope, - }); - usersURL = `/scopes/${orgScope.id}/users`; - userURL = `${usersURL}/${user.id}`; newUserURL = `${usersURL}/new`; authenticateSession({}); }); - test('visiting users', async function (assert) { - assert.expect(1); - await visit(usersURL); - await a11yAudit(); - assert.equal(currentURL(), usersURL); - }); - - test('visiting a user', async function (assert) { - assert.expect(1); - await visit(newUserURL); - await a11yAudit(); - assert.equal(currentURL(), newUserURL); - }); - test('can create new users', async function (assert) { assert.expect(1); const usersCount = this.server.db.users.length; @@ -108,90 +87,4 @@ module('Acceptance | users', function (hooks) { 'Displays field-level errors.' ); }); - - test('can save changes to an existing user', async function (assert) { - assert.expect(2); - await visit(userURL); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'Updated user name'); - await click('.rose-form-actions [type="submit"]'); - assert.equal(currentURL(), userURL); - assert.equal(this.server.db.users[0].name, 'Updated user name'); - }); - - test('can cancel changes to an existing user', async function (assert) { - assert.expect(1); - await visit(userURL); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'Unsaved user name'); - await click('.rose-form-actions [type="button"]'); - assert.notEqual(find('[name="name"]').value, 'Unsaved user name'); - }); - - test('can delete an user', async function (assert) { - assert.expect(1); - const usersCount = this.server.db.users.length; - await visit(userURL); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.equal(this.server.db.users.length, usersCount - 1); - }); - - test('saving an existing user with invalid fields displays error messages', async function (assert) { - assert.expect(2); - this.server.patch('/users/:id', () => { - return new Response( - 400, - {}, - { - status: 400, - code: 'invalid_argument', - message: 'The request was invalid.', - details: { - request_fields: [ - { - name: 'name', - description: 'Name is required.', - }, - ], - }, - } - ); - }); - await visit(userURL); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'User name'); - await click('[type="submit"]'); - assert.ok( - find('[role="alert"]').textContent.trim(), - 'The request was invalid.', - 'Displays primary error message.' - ); - assert.ok( - find('.rose-form-error-message').textContent.trim(), - 'Name is required.', - 'Displays field-level errors.' - ); - }); - - test('errors are displayed when user deletion fails', async function (assert) { - assert.expect(1); - this.server.del('/users/:id', () => { - return new Response( - 490, - {}, - { - status: 490, - code: 'error', - message: 'Oops.', - } - ); - }); - await visit(userURL); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.ok( - find('[role="alert"]').textContent.trim(), - 'Oops.', - 'Displays primary error message.' - ); - }); }); diff --git a/ui/admin/tests/acceptance/users/delete-test.js b/ui/admin/tests/acceptance/users/delete-test.js new file mode 100644 index 000000000..14b5371fc --- /dev/null +++ b/ui/admin/tests/acceptance/users/delete-test.js @@ -0,0 +1,86 @@ +import { module, test } from 'qunit'; +import { visit, click, find } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { Response } from 'miragejs'; +import { + authenticateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, +} from 'ember-simple-auth/test-support'; + +module('Acceptance | users | delete', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + let orgScope; + let usersURL; + let userURL; + + const instances = { + scopes: { + global: null, + org: null, + }, + user: null, + }; + hooks.beforeEach(function () { + orgScope = this.server.create( + 'scope', + { + type: 'org', + }, + 'withChildren' + ); + + instances.user = this.server.create('user', { + scope: orgScope, + }); + //instances.user = this.server.schema.users.all().models[0]; + usersURL = `/scopes/${orgScope.id}/users`; + userURL = `${usersURL}/${instances.user.id}`; + + authenticateSession({}); + }); + + test('can delete an user', async function (assert) { + assert.expect(1); + const usersCount = this.server.db.users.length; + await visit(userURL); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(this.server.db.users.length, usersCount - 1); + }); + + test('cannot delete a user without proper authorization', async function (assert) { + assert.expect(1); + instances.user.authorized_actions = + instances.user.authorized_actions.filter((item) => item !== 'delete'); + await visit(userURL); + assert.notOk( + find('.rose-layout-page-actions .rose-dropdown-button-danger') + ); + }); + + test('errors are displayed when user deletion fails', async function (assert) { + assert.expect(1); + this.server.del('/users/:id', () => { + return new Response( + 490, + {}, + { + status: 490, + code: 'error', + message: 'Oops.', + } + ); + }); + await visit(userURL); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.ok( + find('[role="alert"]').textContent.trim(), + 'Oops.', + 'Displays primary error message.' + ); + }); +}); diff --git a/ui/admin/tests/acceptance/users/read-test.js b/ui/admin/tests/acceptance/users/read-test.js new file mode 100644 index 000000000..06b9f4880 --- /dev/null +++ b/ui/admin/tests/acceptance/users/read-test.js @@ -0,0 +1,57 @@ +import { module, test } from 'qunit'; +import { visit, currentURL, find } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +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'; + +module('Acceptance | users | read', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + let orgScope; + let usersURL; + + const instances = { + scopes: { + global: null, + org: null, + }, + user: null, + }; + + hooks.beforeEach(function () { + orgScope = this.server.create( + 'scope', + { + type: 'org', + }, + 'withChildren' + ); + instances.user = this.server.create('user', { + scope: orgScope, + }); + usersURL = `/scopes/${orgScope.id}/users`; + authenticateSession({}); + }); + + test('visiting users', async function (assert) { + assert.expect(1); + await visit(usersURL); + await a11yAudit(); + assert.equal(currentURL(), usersURL); + }); + + test('cannot navigate to an account form without proper authorization', async function (assert) { + assert.expect(1); + instances.user.authorized_actions = + instances.user.authorized_actions.filter((item) => item !== 'read'); + await visit(usersURL); + assert.notOk(find('main tbody .rose-table-header-cell:nth-child(1) a')); + }); +}); diff --git a/ui/admin/tests/acceptance/users/update-test.js b/ui/admin/tests/acceptance/users/update-test.js new file mode 100644 index 000000000..931a58641 --- /dev/null +++ b/ui/admin/tests/acceptance/users/update-test.js @@ -0,0 +1,110 @@ +import { module, test } from 'qunit'; +import { visit, currentURL, click, fillIn, find } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { Response } from 'miragejs'; +import { + authenticateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, +} from 'ember-simple-auth/test-support'; + +module('Acceptance | users | update', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + let orgScope; + let usersURL; + let userURL; + + const instances = { + scopes: { + global: null, + org: null, + }, + user: null, + }; + + hooks.beforeEach(function () { + orgScope = this.server.create( + 'scope', + { + type: 'org', + }, + 'withChildren' + ); + + instances.user = this.server.create('user', { + scope: orgScope, + }); + + usersURL = `/scopes/${orgScope.id}/users`; + userURL = `${usersURL}/${instances.user.id}`; + + authenticateSession({}); + }); + test('can save changes to an existing user', async function (assert) { + assert.expect(2); + await visit(userURL); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'Updated user name'); + await click('.rose-form-actions [type="submit"]'); + assert.equal(currentURL(), userURL); + assert.equal(this.server.db.users[0].name, 'Updated user name'); + }); + + test('cannot make changes to an existing user without proper authorization', async function (assert) { + assert.expect(1); + instances.user.authorized_actions = + instances.user.authorized_actions.filter((item) => item !== 'update'); + await visit(userURL); + assert.notOk(find('.rose-layout-page-actions .rose-button-secondary')); + }); + + test('can cancel changes to an existing user', async function (assert) { + assert.expect(1); + await visit(userURL); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'Unsaved user name'); + await click('.rose-form-actions [type="button"]'); + assert.notEqual(find('[name="name"]').value, 'Unsaved user name'); + }); + + test('saving an existing user with invalid fields displays error messages', async function (assert) { + assert.expect(2); + this.server.patch('/users/:id', () => { + return new Response( + 400, + {}, + { + status: 400, + code: 'invalid_argument', + message: 'The request was invalid.', + details: { + request_fields: [ + { + name: 'name', + description: 'Name is required.', + }, + ], + }, + } + ); + }); + await visit(userURL); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'User name'); + await click('[type="submit"]'); + assert.ok( + find('[role="alert"]').textContent.trim(), + 'The request was invalid.', + 'Displays primary error message.' + ); + assert.ok( + find('.rose-form-error-message').textContent.trim(), + 'Name is required.', + 'Displays field-level errors.' + ); + }); +}); diff --git a/ui/desktop/electron-app/package.json b/ui/desktop/electron-app/package.json index 7916fd3de..d06bbd054 100644 --- a/ui/desktop/electron-app/package.json +++ b/ui/desktop/electron-app/package.json @@ -45,6 +45,7 @@ "xmldom": "~0.5.0", "yargs-parser": "~20.2.7", "trim-newlines": "^3.0.1", - "normalize-url": "^4.5.1" + "normalize-url": "^4.5.1", + "jszip": "^3.7.0" } } diff --git a/ui/desktop/jsconfig.json b/ui/desktop/jsconfig.json new file mode 100644 index 000000000..f408cac8c --- /dev/null +++ b/ui/desktop/jsconfig.json @@ -0,0 +1 @@ +{"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]} \ No newline at end of file