Merge branch 'main' into sessions

This commit is contained in:
Randall Morey authored and GitHub committed 2021-09-02 15:07:04 -04:00
commit 372f8d5b96
109 files changed
+826 -456

No files matched your search

@@ -2,7 +2,6 @@ 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 a11yAudit from 'ember-a11y-testing/test-support/audit';
import { Response } from 'miragejs';
import {
authenticateSession,
@@ -12,7 +11,7 @@ import {
} from 'ember-simple-auth/test-support';
import { enableFeature } from 'ember-feature-flags/test-support';
module('Acceptance | auth methods', function (hooks) {
module('Acceptance | auth-methods | create ', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
@@ -20,9 +19,12 @@ module('Acceptance | auth methods', function (hooks) {
scopes: {
global: null,
org: null,
project: null,
},
authMethod: null,
orgScope: null,
};
const urls = {
orgScope: null,
authMethods: null,
@@ -31,58 +33,33 @@ module('Acceptance | auth methods', function (hooks) {
};
hooks.beforeEach(function () {
// Setup Mirage mock resources for this test
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.orgScope = this.server.create(
'scope',
{
type: 'org',
scope: { id: 'global', type: 'global' },
},
'withChildren'
);
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.orgScope.id, type: instances.orgScope.type },
});
instances.authMethod = this.server.create('auth-method', {
scope: instances.scopes.org,
scope: instances.orgScope,
});
// Generate route URLs for resources
urls.orgScope = `/scopes/${instances.scopes.org.id}`;
urls.orgScope = `/scopes/${instances.orgScope.id}`;
urls.authMethods = `${urls.orgScope}/auth-methods`;
urls.newAuthMethod = `${urls.authMethods}/new?type=password`;
urls.authMethod = `${urls.authMethods}/${instances.authMethod.id}`;
});
test('visiting auth methods', async function (assert) {
assert.expect(1);
await visit(urls.authMethods);
await a11yAudit();
assert.equal(currentURL(), urls.authMethods);
});
test('can navigate to an auth method form', async function (assert) {
assert.expect(1);
await visit(urls.authMethods);
await click('main tbody .rose-table-header-cell:nth-child(1) a');
await a11yAudit();
assert.equal(currentURL(), urls.authMethod);
});
test('can update an auth method and save changes', async function (assert) {
assert.expect(1);
await visit(urls.authMethod);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'update name');
await click('form [type="submit"]:not(:disabled)');
assert.equal(this.server.db.authMethods[0].name, 'update name');
});
test('can update an auth method and cancel changes', async function (assert) {
assert.expect(1);
await visit(urls.authMethod);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'update name');
await click('form button:not([type="submit"])');
assert.notEqual(this.server.db.authMethods[0].name, 'update name');
});
test('can create new auth method', async function (assert) {
test('Users can create new auth method', async function (assert) {
assert.expect(1);
const authMethodsCount = this.server.db.authMethods.length;
await visit(urls.newAuthMethod);
@@ -92,6 +69,33 @@ module('Acceptance | auth methods', function (hooks) {
assert.equal(this.server.db.authMethods.length, authMethodsCount + 1);
});
test('Users can navigate to new auth-methods route with proper authorization', async function (assert) {
assert.expect(2);
instances.orgScope.authorized_collection_actions['auth-methods'] = [
'create',
'list',
];
await visit(urls.orgScope);
assert.ok(
instances.orgScope.authorized_collection_actions['auth-methods'].includes(
'create'
)
);
assert.ok(find(`[href="${urls.authMethods}"]`));
});
test('Users cannot navigate to new auth-methods route without proper authorization', async function (assert) {
assert.expect(2);
instances.orgScope.authorized_collection_actions['auth-methods'] = [];
await visit(urls.orgScope);
assert.notOk(
instances.orgScope.authorized_collection_actions['auth-methods'].includes(
'create'
)
);
assert.notOk(find(`[href="${urls.authMethods}"]`));
});
test('can cancel new auth method creation', async function (assert) {
assert.expect(2);
const authMethodsCount = this.server.db.authMethods.length;
@@ -106,7 +110,7 @@ module('Acceptance | auth methods', function (hooks) {
test('user can make primary an auth method', async function (assert) {
assert.expect(2);
assert.notOk(
instances.scopes.org.primaryAuthMethodId,
instances.orgScope.primaryAuthMethodId,
'Primary auth method is not yet set.'
);
enableFeature('primary-auth-method');
@@ -114,7 +118,7 @@ module('Acceptance | auth methods', function (hooks) {
await click(
'.rose-layout-page-actions .rose-dropdown-content [type="button"]:first-child'
);
const scope = this.server.schema.scopes.find(instances.scopes.org.id);
const scope = this.server.schema.scopes.find(instances.orgScope.id);
assert.equal(
scope.primaryAuthMethodId,
instances.authMethod.id,
@@ -136,7 +140,7 @@ module('Acceptance | auth methods', function (hooks) {
);
});
assert.notOk(
instances.scopes.org.primaryAuthMethodId,
instances.orgScope.primaryAuthMethodId,
'Primary auth method is not yet set.'
);
enableFeature('primary-auth-method');
@@ -149,11 +153,11 @@ module('Acceptance | auth methods', function (hooks) {
test('user can remove as primary an auth method', async function (assert) {
assert.expect(2);
instances.scopes.org.update({
instances.orgScope.update({
primaryAuthMethodId: instances.authMethod.id,
});
assert.ok(
instances.scopes.org.primaryAuthMethodId,
instances.orgScope.primaryAuthMethodId,
'Primary auth method is set.'
);
enableFeature('primary-auth-method');
@@ -161,7 +165,7 @@ module('Acceptance | auth methods', function (hooks) {
await click(
'.rose-layout-page-actions .rose-dropdown-content [type="button"]:first-child'
);
const scope = this.server.schema.scopes.find(instances.scopes.org.id);
const scope = this.server.schema.scopes.find(instances.orgScope.id);
assert.notOk(scope.primaryAuthMethodId, 'Primary auth method is unset.');
});
@@ -178,11 +182,11 @@ module('Acceptance | auth methods', function (hooks) {
}
);
});
instances.scopes.org.update({
instances.orgScope.update({
primaryAuthMethodId: instances.authMethod.id,
});
assert.ok(
instances.scopes.org.primaryAuthMethodId,
instances.orgScope.primaryAuthMethodId,
'Primary auth method is set.'
);
enableFeature('primary-auth-method');
@@ -196,7 +200,7 @@ module('Acceptance | auth methods', function (hooks) {
test('user can make and remove primary auth methods from index', async function (assert) {
assert.expect(3);
assert.notOk(
instances.scopes.org.primaryAuthMethodId,
instances.orgScope.primaryAuthMethodId,
'Primary auth method is not yet set.'
);
enableFeature('primary-auth-method');
@@ -204,7 +208,7 @@ module('Acceptance | auth methods', function (hooks) {
await click(
'.rose-table-body .rose-table-row:first-child .rose-dropdown-content [type="button"]:first-child'
);
let scope = this.server.schema.scopes.find(instances.scopes.org.id);
let scope = this.server.schema.scopes.find(instances.orgScope.id);
assert.equal(
scope.primaryAuthMethodId,
instances.authMethod.id,
@@ -213,7 +217,7 @@ module('Acceptance | auth methods', function (hooks) {
await click(
'.rose-table-body .rose-table-row:first-child .rose-dropdown-content [type="button"]:first-child'
);
scope = this.server.schema.scopes.find(instances.scopes.org.id);
scope = this.server.schema.scopes.find(instances.orgScope.id);
assert.notOk(scope.primaryAuthMethodId, 'Primary auth method is unset.');
});
});
@@ -0,0 +1,79 @@
import { module, test } from 'qunit';
import { visit, find } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import {
authenticateSession,
// These are left here intentionally for future reference.
//currentSession,
//invalidateSession,
} from 'ember-simple-auth/test-support';
module('Acceptance | auth-methods | list', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
},
orgScope: null,
};
const urls = {
scopes: {
org: null,
},
authMethods: null,
orgScope: null,
};
hooks.beforeEach(function () {
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.orgScope = this.server.create(
'scope',
{
type: 'org',
scope: { id: 'global', type: 'global' },
},
'withChildren'
);
urls.orgScope = `/scopes/${instances.orgScope.id}`;
urls.authMethods = `/scopes/${instances.orgScope.id}/auth-methods`;
authenticateSession({});
});
test('Users can navigate to auth methods with proper authorization', async function (assert) {
assert.expect(2);
await visit(urls.orgScope);
assert.ok(
instances.orgScope.authorized_collection_actions['auth-methods'].includes(
'list'
)
);
assert.ok(find(`[href="${urls.authMethods}"]`));
});
test('Users cannot navigate to index without either list or create actions', async function (assert) {
assert.expect(2);
instances.orgScope.authorized_collection_actions['auth-methods'] = [];
await visit(urls.orgScope);
assert.notOk(
instances.orgScope.authorized_collection_actions['auth-methods'].includes(
'list'
)
);
assert.notOk(find(`[href="${urls.authMethods}"]`));
});
test('User can navigate to index with only create action', async function (assert) {
assert.expect(1);
instances.orgScope.authorized_collection_actions['auth-methods'] = [
'create',
];
await visit(urls.orgScope);
assert.ok(find(`[href="${urls.authMethods}"]`));
});
});
@@ -10,9 +10,10 @@ import {
//invalidateSession,
} from 'ember-simple-auth/test-support';
module('Acceptance | groups', function (hooks) {
module('Acceptance | groups | create', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
let orgURL;
const instances = {
scopes: {
@@ -20,9 +21,9 @@ module('Acceptance | groups', function (hooks) {
org: null,
},
group: null,
orgScope: null,
};
const urls = {
orgScope: null,
groups: null,
group: null,
newGroup: null,
@@ -30,17 +31,21 @@ module('Acceptance | groups', function (hooks) {
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.orgScope = this.server.create(
'scope',
{
type: 'org',
scope: { id: 'global', type: 'global' },
},
'withChildren'
);
instances.group = this.server.create('group', {
scope: instances.scopes.org,
scope: instances.orgScope,
});
urls.groups = `/scopes/${instances.scopes.org.id}/groups`;
urls.groups = `/scopes/${instances.orgScope.id}/groups`;
urls.group = `${urls.groups}/${instances.group.id}`;
urls.newGroup = `${urls.groups}/new`;
orgURL = `/scopes/${instances.orgScope.id}`;
});
test('can create new group', async function (assert) {
@@ -52,6 +57,24 @@ module('Acceptance | groups', function (hooks) {
assert.equal(this.server.db.groups.length, groupsCount + 1);
});
test('can navigate to new groups route with proper authorization', async function (assert) {
assert.expect(2);
await visit(orgURL);
assert.ok(
instances.orgScope.authorized_collection_actions.groups.includes('create')
);
assert.ok(find(`[href="${urls.groups}"]`));
});
test('cannot navigate to new groups route without proper authorization', async function (assert) {
assert.expect(2);
instances.orgScope.authorized_collection_actions.groups = [];
await visit(orgURL);
assert.notOk(
instances.orgScope.authorized_collection_actions.groups.includes('create')
);
assert.notOk(find(`[href="${urls.groups}"]`));
});
test('can cancel new group creation', async function (assert) {
assert.expect(2);
const groupsCount = this.server.db.groups.length;
@@ -0,0 +1,76 @@
import { module, test } from 'qunit';
import { visit, find } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import {
authenticateSession,
// These are left here intentionally for future reference.
//currentSession,
//invalidateSession,
} from 'ember-simple-auth/test-support';
module('Acceptance | groups | list', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
let orgURL;
const instances = {
scopes: {
global: null,
org: null,
},
orgScope: null,
};
const urls = {
scopes: {
org: null,
},
groups: null,
};
hooks.beforeEach(function () {
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.orgScope = this.server.create(
'scope',
{
type: 'org',
scope: { id: 'global', type: 'global' },
},
'withChildren'
);
instances.group = this.server.create('group', {
scope: instances.orgScope,
});
orgURL = `/scopes/${instances.orgScope.id}`;
urls.groups = `/scopes/${instances.orgScope.id}/groups`;
authenticateSession({});
});
test('can navigate to groups with proper authorization', async function (assert) {
assert.expect(2);
await visit(orgURL);
assert.ok(
instances.orgScope.authorized_collection_actions.groups.includes('list')
);
assert.ok(find(`[href="${urls.groups}"]`));
});
test('User cannot navigate to index without either list or create actions', async function (assert) {
assert.expect(2);
instances.orgScope.authorized_collection_actions.groups = [];
await visit(orgURL);
assert.notOk(
instances.orgScope.authorized_collection_actions.groups.includes('list')
);
assert.notOk(find(`[href="${urls.groups}"]`));
});
test('User can navigate to index with only create action', async function (assert) {
assert.expect(1);
instances.orgScope.authorized_collection_actions.groups = ['create'];
await visit(orgURL);
assert.ok(find(`[href="${urls.groups}"]`));
});
});
@@ -11,7 +11,7 @@ import {
//invalidateSession,
} from 'ember-simple-auth/test-support';
module('Acceptance | roles', function (hooks) {
module('Acceptance | roles | create', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
@@ -22,38 +22,44 @@ module('Acceptance | roles', function (hooks) {
project: null,
},
role: null,
orgScope: null,
};
const urls = {
orgScope: null,
roles: null,
role: null,
newRole: null,
orgScope: 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.orgScope = this.server.create(
'scope',
{
type: 'org',
scope: { id: 'global', type: 'global' },
},
'withChildren'
);
// The project scope is not yet used for role tests (though it will be
// in the future). This is created simply to test the grant scope loading
// mechanism.
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: instances.scopes.org.type },
scope: { id: instances.orgScope.id, type: instances.orgScope.type },
});
instances.role = this.server.create(
'role',
{
scope: instances.scopes.org,
scope: instances.orgScope,
},
'withPrincipals'
);
urls.roles = `/scopes/${instances.scopes.org.id}/roles`;
urls.roles = `/scopes/${instances.orgScope.id}/roles`;
urls.role = `${urls.roles}/${instances.role.id}`;
urls.newRole = `${urls.roles}/new`;
urls.orgScope = `/scopes/${instances.orgScope.id}`;
});
test('can create new role', async function (assert) {
@@ -65,6 +71,25 @@ module('Acceptance | roles', function (hooks) {
assert.equal(this.server.db.roles.length, rolesCount + 1);
});
test('Users can navigate to new roles route with proper authorization', async function (assert) {
assert.expect(2);
await visit(urls.orgScope);
assert.ok(
instances.orgScope.authorized_collection_actions.roles.includes('create')
);
assert.ok(find(`[href="${urls.roles}"]`));
});
test('Users cannot navigate to new roles route without proper authorization', async function (assert) {
assert.expect(2);
instances.orgScope.authorized_collection_actions.roles = [];
await visit(urls.orgScope);
assert.notOk(
instances.orgScope.authorized_collection_actions.roles.includes('create')
);
assert.notOk(find(`[href="${urls.roles}"]`));
});
test('can cancel new role creation', async function (assert) {
assert.expect(2);
const rolesCount = this.server.db.roles.length;
@@ -0,0 +1,75 @@
import { module, test } from 'qunit';
import { visit, find } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import {
authenticateSession,
// These are left here intentionally for future reference.
//currentSession,
//invalidateSession,
} from 'ember-simple-auth/test-support';
module('Acceptance | roles | list', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
},
orgScope: null,
};
const urls = {
scopes: {
org: null,
},
roles: null,
orgScope: null,
};
hooks.beforeEach(function () {
instances.orgScope = this.server.create(
'scope',
{
type: 'org',
scope: { id: 'global', type: 'global' },
},
'withChildren'
);
instances.role = this.server.create('role', {
scope: instances.orgScope,
});
urls.orgScope = `/scopes/${instances.orgScope.id}`;
urls.roles = `/scopes/${instances.orgScope.id}/roles`;
authenticateSession({});
});
test('Users can navigate to roles with proper authorization', async function (assert) {
assert.expect(2);
await visit(urls.orgScope);
assert.ok(
instances.orgScope.authorized_collection_actions.roles.includes('list')
);
assert.ok(find(`[href="${urls.roles}"]`));
});
test('Users cannot navigate to index without either list or create actions', async function (assert) {
assert.expect(2);
instances.orgScope.authorized_collection_actions.roles = [];
await visit(urls.orgScope);
assert.notOk(
instances.orgScope.authorized_collection_actions.roles.includes('list')
);
assert.notOk(find(`[href="${urls.roles}"]`));
});
test('Users can navigate to index with only create action', async function (assert) {
assert.expect(1);
instances.orgScope.authorized_collection_actions.roles = ['create'];
await visit(urls.orgScope);
assert.ok(find(`[href="${urls.roles}"]`));
});
});