fix: 🐛 OIDC authentications not properly showing username (#2930)
* fix: 🐛 properly show username for oidc auth method in user menu * test: 💍 fix admin ui tests * test: 💍 fix desktop ui tests * refactor: 💡 admin to not store username in authenticated object * refactor: 💡 use getter in app controller * test: 💍 POC for how we could update our tests to use auth account * refactor: 💡 remove unused service * test: 💍 fix all tests in ui/admin * test: 💍 revert one change * refactor: 💡 update ui/desktop w/ feedback + fix tests * refactor: 💡 add in error handling * refactor: 💡 cleanup unused service * test: 💍 fix e2e test selector ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-17231
This commit is contained in:
1 parent
838bc37243
commit
72f7c8a92d
195 files changed
+720
-1112
No files matched your search
@@ -5,8 +5,7 @@
|
||||
|
||||
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 { setupApplicationTest } from 'desktop/tests/helpers';
|
||||
import sinon from 'sinon';
|
||||
import { invalidateSession } from 'ember-simple-auth/test-support';
|
||||
import { setupBrowserFakes } from 'ember-browser-services/test-support';
|
||||
@@ -14,7 +13,6 @@ import { setupBrowserFakes } from 'ember-browser-services/test-support';
|
||||
module('Acceptance | Application', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupBrowserFakes(hooks, { window: true });
|
||||
setupMirage(hooks);
|
||||
|
||||
const TOAST = '[data-test-toast-notification]';
|
||||
const TOAST_DO_NOT_SHOW_AGAIN_BUTTON =
|
||||
|
||||
@@ -11,8 +11,7 @@ import {
|
||||
click,
|
||||
triggerEvent,
|
||||
} from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupApplicationTest } from 'desktop/tests/helpers';
|
||||
import { Response } from 'miragejs';
|
||||
import {
|
||||
currentSession,
|
||||
@@ -26,7 +25,6 @@ import { setRunOptions } from 'ember-a11y-testing/test-support';
|
||||
|
||||
module('Acceptance | authentication', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
@@ -39,6 +37,7 @@ module('Acceptance | authentication', function (hooks) {
|
||||
global: null,
|
||||
org: null,
|
||||
},
|
||||
account: null,
|
||||
user: null,
|
||||
target: null,
|
||||
session: null,
|
||||
@@ -80,17 +79,13 @@ module('Acceptance | authentication', function (hooks) {
|
||||
};
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
instances.user = this.server.create('user', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
|
||||
await invalidateSession();
|
||||
|
||||
const ipcService = this.owner.lookup('service:ipc');
|
||||
this.ipcStub = sinon.stub(ipcService, 'invoke');
|
||||
|
||||
// create scopes
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.scopes.global = this.server.schema.scopes.find('global');
|
||||
stubs.global = { id: 'global', type: 'global' };
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
@@ -108,15 +103,13 @@ module('Acceptance | authentication', function (hooks) {
|
||||
type: 'org',
|
||||
scope: stubs.global,
|
||||
});
|
||||
instances.authMethods.global = this.server.create('auth-method', {
|
||||
scope: instances.scopes.global,
|
||||
type: 'password',
|
||||
});
|
||||
instances.authMethods.global = this.server.schema.authMethods.first();
|
||||
instances.account = this.server.schema.accounts.first();
|
||||
instances.user = this.server.schema.users.first();
|
||||
instances.authMethods.org = this.server.create('auth-method', {
|
||||
scope: instances.scopes.org,
|
||||
type: 'password',
|
||||
});
|
||||
|
||||
instances.target = this.server.create(
|
||||
'target',
|
||||
{ scope: instances.scopes.project },
|
||||
@@ -235,6 +228,7 @@ module('Acceptance | authentication', function (hooks) {
|
||||
|
||||
assert.expect(3);
|
||||
await authenticateSession({
|
||||
account_id: instances.account.id,
|
||||
scope: {
|
||||
id: instances.scopes.global.id,
|
||||
type: instances.scopes.global.type,
|
||||
@@ -285,7 +279,7 @@ module('Acceptance | authentication', function (hooks) {
|
||||
|
||||
await visit(urls.authenticate.methods.global);
|
||||
|
||||
await authenticateSession({ username: 'test' });
|
||||
await authenticateSession({ account_id: instances.account.id });
|
||||
|
||||
assert.ok(currentSession().isAuthenticated);
|
||||
|
||||
@@ -317,7 +311,7 @@ module('Acceptance | authentication', function (hooks) {
|
||||
|
||||
await visit(urls.authenticate.methods.global);
|
||||
|
||||
await authenticateSession({ username: 'test' });
|
||||
await authenticateSession({ account_id: instances.account.id });
|
||||
|
||||
assert.ok(currentSession().isAuthenticated);
|
||||
|
||||
@@ -367,7 +361,7 @@ module('Acceptance | authentication', function (hooks) {
|
||||
|
||||
await visit(urls.authenticate.methods.global);
|
||||
|
||||
await authenticateSession({ username: 'test' });
|
||||
await authenticateSession({ account_id: instances.account.id });
|
||||
|
||||
assert.ok(currentSession().isAuthenticated);
|
||||
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, currentURL, fillIn, click, find } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupApplicationTest } from 'desktop/tests/helpers';
|
||||
import sinon from 'sinon';
|
||||
import { invalidateSession } from 'ember-simple-auth/test-support';
|
||||
import { setupBrowserFakes } from 'ember-browser-services/test-support';
|
||||
@@ -16,7 +15,6 @@ import config from '../../config/environment';
|
||||
module('Acceptance | clusterUrl', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupBrowserFakes(hooks, { window: true });
|
||||
setupMirage(hooks);
|
||||
|
||||
const currentOrigin = window.location.origin;
|
||||
let mockIPC;
|
||||
@@ -79,10 +77,7 @@ module('Acceptance | clusterUrl', function (hooks) {
|
||||
});
|
||||
stubs.project = { id: instances.scopes.project.id, type: 'project' };
|
||||
|
||||
instances.authMethods.global = this.server.create('auth-method', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
|
||||
instances.authMethods.global = this.server.schema.authMethods.first();
|
||||
instances.hostCatalog = this.server.create(
|
||||
'host-catalog',
|
||||
{ scope: instances.scopes.project },
|
||||
|
||||
@@ -5,18 +5,15 @@
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, currentURL } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupApplicationTest } from 'desktop/tests/helpers';
|
||||
import {
|
||||
currentSession,
|
||||
authenticateSession,
|
||||
invalidateSession,
|
||||
} from 'ember-simple-auth/test-support';
|
||||
import WindowMockIPC from '../helpers/window-mock-ipc';
|
||||
|
||||
module('Acceptance | projects', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
@@ -58,10 +55,8 @@ module('Acceptance | projects', function (hooks) {
|
||||
};
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
await authenticateSession({ username: 'admin' });
|
||||
|
||||
// create scopes
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.scopes.global = this.server.schema.scopes.find('global');
|
||||
instances.authMethods.global = this.server.schema.authMethods.first();
|
||||
stubs.global = { id: 'global', type: 'global' };
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
@@ -74,10 +69,6 @@ module('Acceptance | projects', function (hooks) {
|
||||
});
|
||||
stubs.project = { id: instances.scopes.project.id, type: 'project' };
|
||||
|
||||
instances.authMethods.global = this.server.create('auth-method', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
|
||||
instances.hostCatalog = this.server.create(
|
||||
'host-catalog',
|
||||
{ scope: instances.scopes.project },
|
||||
|
||||
@@ -5,13 +5,11 @@
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, currentURL, click } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupApplicationTest } from 'desktop/tests/helpers';
|
||||
import { Response } from 'miragejs';
|
||||
import WindowMockIPC from '../../../helpers/window-mock-ipc';
|
||||
import {
|
||||
currentSession,
|
||||
authenticateSession,
|
||||
invalidateSession,
|
||||
} from 'ember-simple-auth/test-support';
|
||||
import {
|
||||
@@ -25,7 +23,6 @@ import { setRunOptions } from 'ember-a11y-testing/test-support';
|
||||
|
||||
module('Acceptance | projects | sessions | index', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupStubs(hooks);
|
||||
|
||||
const APP_STATE_TITLE =
|
||||
@@ -75,20 +72,8 @@ module('Acceptance | projects | sessions | index', function (hooks) {
|
||||
};
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
instances.user = this.server.create('user', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
|
||||
await authenticateSession({
|
||||
user_id: instances.user.id,
|
||||
username: 'admin',
|
||||
});
|
||||
|
||||
// create scopes
|
||||
instances.scopes.global = this.server.create('scope', {
|
||||
id: 'global',
|
||||
name: 'Global',
|
||||
});
|
||||
instances.scopes.global = this.server.schema.scopes.find('global');
|
||||
const globalScope = { id: 'global', type: 'global' };
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
@@ -110,14 +95,13 @@ module('Acceptance | projects | sessions | index', function (hooks) {
|
||||
});
|
||||
|
||||
// create resources
|
||||
instances.authMethods.global = this.server.create('auth-method', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
instances.authMethods.global = this.server.schema.authMethods.first();
|
||||
instances.target = this.server.create(
|
||||
'target',
|
||||
{ scope: instances.scopes.project },
|
||||
'withAssociations',
|
||||
);
|
||||
instances.user = this.server.schema.users.first();
|
||||
instances.session = this.server.create(
|
||||
'session',
|
||||
{
|
||||
|
||||
@@ -7,10 +7,8 @@
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, currentURL, click } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupApplicationTest } from 'desktop/tests/helpers';
|
||||
import { Response } from 'miragejs';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import WindowMockIPC from '../../../helpers/window-mock-ipc';
|
||||
import { STATUS_SESSION_ACTIVE } from 'api/models/session';
|
||||
import setupStubs from 'api/test-support/handlers/cache-daemon-search';
|
||||
@@ -18,7 +16,6 @@ import { setRunOptions } from 'ember-a11y-testing/test-support';
|
||||
|
||||
module('Acceptance | projects | sessions | session', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupStubs(hooks);
|
||||
|
||||
const TARGET_CONNECT_BUTTON = '[data-test-target-detail-connect-button]';
|
||||
@@ -63,17 +60,8 @@ module('Acceptance | projects | sessions | session', function (hooks) {
|
||||
let originalUncaughtException = QUnit.onUncaughtException;
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
instances.user = this.server.create('user', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
|
||||
await authenticateSession({
|
||||
user_id: instances.user.id,
|
||||
username: 'admin',
|
||||
});
|
||||
|
||||
// create scopes
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.scopes.global = this.server.schema.scopes.find('global');
|
||||
const globalScope = { id: 'global', type: 'global' };
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
@@ -92,9 +80,8 @@ module('Acceptance | projects | sessions | session', function (hooks) {
|
||||
scope: instances.scopes.project,
|
||||
hostCatalog: instances.hostCatalog,
|
||||
});
|
||||
instances.authMethods.global = this.server.create('auth-method', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
instances.authMethods.global = this.server.schema.authMethods.first();
|
||||
instances.user = this.server.schema.users.first();
|
||||
instances.target = this.server.create(
|
||||
'target',
|
||||
{ scope: instances.scopes.project, address: 'localhost' },
|
||||
|
||||
@@ -11,8 +11,7 @@ import {
|
||||
getRootElement,
|
||||
select,
|
||||
} from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupApplicationTest } from 'desktop/tests/helpers';
|
||||
import {
|
||||
authenticateSession,
|
||||
currentSession,
|
||||
@@ -23,7 +22,6 @@ import { setRunOptions } from 'ember-a11y-testing/test-support';
|
||||
|
||||
module('Acceptance | projects | settings | index', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupStubs(hooks);
|
||||
|
||||
const instances = {
|
||||
@@ -35,6 +33,7 @@ module('Acceptance | projects | settings | index', function (hooks) {
|
||||
authMethods: {
|
||||
global: null,
|
||||
},
|
||||
account: null,
|
||||
target: null,
|
||||
target2: null,
|
||||
session: null,
|
||||
@@ -67,13 +66,8 @@ module('Acceptance | projects | settings | index', function (hooks) {
|
||||
};
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
await authenticateSession();
|
||||
|
||||
// Generate scopes
|
||||
instances.scopes.global = this.server.create('scope', {
|
||||
id: 'global',
|
||||
name: 'Global',
|
||||
});
|
||||
instances.scopes.global = this.server.schema.scopes.find('global');
|
||||
const globalScope = { id: 'global', type: 'global' };
|
||||
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
@@ -86,6 +80,7 @@ module('Acceptance | projects | settings | index', function (hooks) {
|
||||
type: 'project',
|
||||
scope: orgScope,
|
||||
});
|
||||
instances.account = this.server.schema.accounts.first();
|
||||
urls.scopes.org = `/scopes/${instances.scopes.org.id}`;
|
||||
urls.scopes.global = `/scopes/${instances.scopes.global.id}`;
|
||||
urls.projects = `${urls.scopes.org}/projects`;
|
||||
@@ -184,10 +179,10 @@ module('Acceptance | projects | settings | index', function (hooks) {
|
||||
},
|
||||
});
|
||||
|
||||
await authenticateSession({ username: 'testuser' });
|
||||
await authenticateSession({ account_id: instances.account.id });
|
||||
assert.expect(2);
|
||||
|
||||
await authenticateSession({ username: 'testuser' });
|
||||
await authenticateSession({ account_id: instances.account.id });
|
||||
assert.ok(currentSession().isAuthenticated);
|
||||
|
||||
await visit(urls.settings);
|
||||
@@ -215,7 +210,7 @@ module('Acceptance | projects | settings | index', function (hooks) {
|
||||
const stopAllSessions = this.ipcStub.withArgs('stopAll');
|
||||
this.ipcStub.withArgs('hasRunningSessions').returns(true);
|
||||
|
||||
await authenticateSession({ username: 'testuser' });
|
||||
await authenticateSession({ account_id: instances.account.id });
|
||||
assert.ok(currentSession().isAuthenticated);
|
||||
|
||||
await visit(urls.settings);
|
||||
|
||||
@@ -10,11 +10,9 @@ import {
|
||||
currentRouteName,
|
||||
click,
|
||||
} from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupApplicationTest } from 'desktop/tests/helpers';
|
||||
import WindowMockIPC from '../../../helpers/window-mock-ipc';
|
||||
import {
|
||||
authenticateSession,
|
||||
invalidateSession,
|
||||
currentSession,
|
||||
} from 'ember-simple-auth/test-support';
|
||||
@@ -27,7 +25,6 @@ import {
|
||||
|
||||
module('Acceptance | projects | targets | index', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupStubs(hooks);
|
||||
|
||||
let getTargetCount;
|
||||
@@ -88,15 +85,11 @@ module('Acceptance | projects | targets | index', function (hooks) {
|
||||
};
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
await authenticateSession({ username: 'admin' });
|
||||
// bypass mirage config that expects recursive to be passed in as queryParam
|
||||
this.server.get('/targets', ({ targets }) => targets.all());
|
||||
|
||||
// Generate scopes
|
||||
instances.scopes.global = this.server.create('scope', {
|
||||
id: 'global',
|
||||
name: 'Global',
|
||||
});
|
||||
instances.scopes.global = this.server.schema.scopes.find('global');
|
||||
const globalScope = { id: 'global', type: 'global' };
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
@@ -118,9 +111,7 @@ module('Acceptance | projects | targets | index', function (hooks) {
|
||||
});
|
||||
|
||||
// Generate resources
|
||||
instances.authMethods.global = this.server.create('auth-method', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
instances.authMethods.global = this.server.schema.authMethods.first();
|
||||
instances.hostCatalog = this.server.create(
|
||||
'host-catalog',
|
||||
{ scope: instances.scopes.project },
|
||||
|
||||
@@ -13,16 +13,13 @@ import {
|
||||
fillIn,
|
||||
waitFor,
|
||||
} 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 { setupApplicationTest } from 'desktop/tests/helpers';
|
||||
import WindowMockIPC from '../../../helpers/window-mock-ipc';
|
||||
import setupStubs from 'api/test-support/handlers/cache-daemon-search';
|
||||
import { setRunOptions } from 'ember-a11y-testing/test-support';
|
||||
|
||||
module('Acceptance | projects | targets | target', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupStubs(hooks);
|
||||
|
||||
const TARGET_RESOURCE_LINK = (id) => `[data-test-visit-target="${id}"]`;
|
||||
@@ -82,12 +79,11 @@ module('Acceptance | projects | targets | target', function (hooks) {
|
||||
};
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
await authenticateSession();
|
||||
// bypass mirage config that expects recursive to be passed in as queryParam
|
||||
this.server.get('/targets', ({ targets }) => targets.all());
|
||||
|
||||
// Generate scopes
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.scopes.global = this.server.schema.scopes.find('global');
|
||||
const globalScope = { id: 'global', type: 'global' };
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
@@ -100,9 +96,7 @@ module('Acceptance | projects | targets | target', function (hooks) {
|
||||
});
|
||||
|
||||
// Generate resources
|
||||
instances.authMethods.global = this.server.create('auth-method', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
instances.authMethods.global = this.server.schema.authMethods.first();
|
||||
instances.hostCatalog = this.server.create(
|
||||
'host-catalog',
|
||||
{ scope: instances.scopes.project },
|
||||
|
||||
@@ -12,12 +12,10 @@ import {
|
||||
findAll,
|
||||
waitFor,
|
||||
} from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupApplicationTest } from 'desktop/tests/helpers';
|
||||
import { Response } from 'miragejs';
|
||||
import {
|
||||
currentSession,
|
||||
authenticateSession,
|
||||
invalidateSession,
|
||||
} from 'ember-simple-auth/test-support';
|
||||
import WindowMockIPC from '../helpers/window-mock-ipc';
|
||||
@@ -26,7 +24,6 @@ import { setRunOptions } from 'ember-a11y-testing/test-support';
|
||||
|
||||
module('Acceptance | scopes', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupStubs(hooks);
|
||||
|
||||
const APP_STATE_TITLE = '.hds-application-state__title';
|
||||
@@ -81,12 +78,11 @@ module('Acceptance | scopes', function (hooks) {
|
||||
};
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
await authenticateSession({ username: 'admin' });
|
||||
// bypass mirage config that expects recursive to be passed in as queryParam
|
||||
this.server.get('/targets', ({ targets }) => targets.all());
|
||||
|
||||
// create scopes
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.scopes.global = this.server.schema.scopes.find('global');
|
||||
const globalScope = { id: 'global', type: 'global' };
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
@@ -102,9 +98,7 @@ module('Acceptance | scopes', function (hooks) {
|
||||
scope: orgScope,
|
||||
});
|
||||
|
||||
instances.authMethods.global = this.server.create('auth-method', {
|
||||
scope: instances.scopes.global,
|
||||
});
|
||||
instances.authMethods.global = this.server.schema.authMethods.first();
|
||||
|
||||
instances.hostCatalog = this.server.create(
|
||||
'host-catalog',
|
||||
|
||||
@@ -8,6 +8,8 @@ import {
|
||||
setupRenderingTest as upstreamSetupRenderingTest,
|
||||
setupTest as upstreamSetupTest,
|
||||
} from 'ember-qunit';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
|
||||
// This file exists to provide wrappers around ember-qunit's
|
||||
// test setup functions. This way, you can easily extend the setup that is
|
||||
@@ -21,15 +23,23 @@ function setupApplicationTest(hooks, options) {
|
||||
// For example, if you need an authenticated session for each
|
||||
// application test, you could do:
|
||||
//
|
||||
// hooks.beforeEach(async function () {
|
||||
// await authenticateSession(); // ember-simple-auth
|
||||
// });
|
||||
//
|
||||
setupMirage(hooks);
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
const scope = this.server.create(
|
||||
'scope',
|
||||
{ id: 'global' },
|
||||
'withGlobalAuth',
|
||||
);
|
||||
const account_id = this.server.schema.accounts.first().id;
|
||||
const user = this.server.create('user', { scope });
|
||||
await authenticateSession({ isGlobal: true, account_id, user_id: user.id });
|
||||
});
|
||||
|
||||
// This is also a good place to call test setup functions coming
|
||||
// from other addons:
|
||||
//
|
||||
// setupIntl(hooks, 'en-us'); // ember-intl
|
||||
// setupMirage(hooks); // ember-cli-mirage
|
||||
}
|
||||
|
||||
function setupRenderingTest(hooks, options) {
|
||||
|
||||
@@ -12,7 +12,6 @@ import Service from '@ember/service';
|
||||
|
||||
const data = {
|
||||
authenticated: {
|
||||
username: 'admin',
|
||||
authenticator: 'authenticator:password',
|
||||
},
|
||||
};
|
||||
@@ -35,6 +34,7 @@ module('Integration | Component | settings-card/user', function (hooks) {
|
||||
class extends Service {
|
||||
data = data;
|
||||
isAuthenticated = true;
|
||||
username = 'admin';
|
||||
},
|
||||
);
|
||||
|
||||
@@ -55,6 +55,7 @@ module('Integration | Component | settings-card/user', function (hooks) {
|
||||
class extends Service {
|
||||
data = oidcData;
|
||||
isAuthenticated = true;
|
||||
username = 'admin';
|
||||
},
|
||||
);
|
||||
|
||||
@@ -75,6 +76,7 @@ module('Integration | Component | settings-card/user', function (hooks) {
|
||||
class extends Service {
|
||||
data = ldapData;
|
||||
isAuthenticated = true;
|
||||
username = 'admin';
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import { visit, currentURL, settled } from '@ember/test-helpers';
|
||||
import { setupIntl } from 'ember-intl/test-support';
|
||||
import { TYPE_AUTH_METHOD_PASSWORD } from 'api/models/auth-method';
|
||||
import WindowMockIPC from '../../../../../../helpers/window-mock-ipc';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/authenticate/method/index',
|
||||
@@ -24,26 +24,41 @@ module(
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
org: null,
|
||||
},
|
||||
authMethod: null,
|
||||
account: null,
|
||||
};
|
||||
|
||||
const urls = {
|
||||
targets: null,
|
||||
};
|
||||
|
||||
const setDefaultClusterUrl = (test) => {
|
||||
const windowOrigin = window.location.origin;
|
||||
const clusterUrl = test.owner.lookup('service:clusterUrl');
|
||||
clusterUrl.rendererClusterUrl = windowOrigin;
|
||||
};
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
await authenticateSession({});
|
||||
controller = this.owner.lookup(
|
||||
'controller:scopes/scope/authenticate/method/index',
|
||||
);
|
||||
store = this.owner.lookup('service:store');
|
||||
session = this.owner.lookup('service:session');
|
||||
|
||||
instances.scopes.global = this.server.create('scope', {
|
||||
id: 'global',
|
||||
type: 'global',
|
||||
});
|
||||
instances.authMethod = this.server.create('auth-method', {
|
||||
scope: instances.scopes.global,
|
||||
type: TYPE_AUTH_METHOD_PASSWORD,
|
||||
});
|
||||
instances.scopes.global = this.server.create(
|
||||
'scope',
|
||||
{ id: 'global' },
|
||||
'withGlobalAuth',
|
||||
);
|
||||
instances.authMethod = this.server.schema.authMethods.first();
|
||||
instances.account = this.server.schema.accounts.first();
|
||||
|
||||
urls.targets = '/scopes/global/projects/targets';
|
||||
|
||||
this.owner.register('service:browser/window', WindowMockIPC);
|
||||
setDefaultClusterUrl(this);
|
||||
});
|
||||
|
||||
test('it exists', function (assert) {
|
||||
@@ -51,29 +66,34 @@ module(
|
||||
});
|
||||
|
||||
test('authenticate action saves login information', async function (assert) {
|
||||
const identification = 'admin123';
|
||||
await visit('/');
|
||||
const identification = instances.account.attributes.login_name;
|
||||
const authMethod = await store.findRecord(
|
||||
'auth-method',
|
||||
instances.authMethod.id,
|
||||
);
|
||||
const { authenticator: authBefore, username: usernameBefore } =
|
||||
const { authenticator: authBefore, account_id: accountIdBefore } =
|
||||
session.data.authenticated;
|
||||
|
||||
assert.notOk(usernameBefore);
|
||||
assert.strictEqual(authBefore, 'authenticator:test');
|
||||
assert.notOk(accountIdBefore);
|
||||
assert.notOk(authBefore);
|
||||
assert.ok(identification);
|
||||
|
||||
await controller.authenticate(authMethod, {
|
||||
identification,
|
||||
password: 'password',
|
||||
});
|
||||
const { authenticator: authAfter, username: usernameAfter } =
|
||||
await settled();
|
||||
|
||||
const { authenticator: authAfter, account_id: accountIdAfter } =
|
||||
session.data.authenticated;
|
||||
|
||||
assert.strictEqual(
|
||||
authAfter,
|
||||
`authenticator:${instances.authMethod.type}`,
|
||||
);
|
||||
assert.strictEqual(usernameAfter, identification);
|
||||
assert.strictEqual(instances.account.id, accountIdAfter);
|
||||
assert.strictEqual(currentURL(), urls.targets);
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -44,13 +44,17 @@ module(
|
||||
};
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
await authenticateSession({});
|
||||
store = this.owner.lookup('service:store');
|
||||
controller = this.owner.lookup(
|
||||
'controller:scopes/scope/projects/sessions/index',
|
||||
);
|
||||
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.scopes.global = this.server.create(
|
||||
'scope',
|
||||
{ id: 'global' },
|
||||
'withGlobalAuth',
|
||||
);
|
||||
instances.account = this.server.schema.accounts.first();
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
scope: { id: 'global', type: 'global' },
|
||||
@@ -73,6 +77,7 @@ module(
|
||||
|
||||
this.ipcStub.withArgs('isCacheDaemonRunning').returns(true);
|
||||
this.stubCacheDaemonSearch('sessions', 'sessions', 'targets');
|
||||
await authenticateSession({ account_id: instances.account.id });
|
||||
});
|
||||
|
||||
test('it exists', function (assert) {
|
||||
|
||||
@@ -48,13 +48,17 @@ module(
|
||||
};
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
await authenticateSession({});
|
||||
store = this.owner.lookup('service:store');
|
||||
controller = this.owner.lookup(
|
||||
'controller:scopes/scope/projects/targets/index',
|
||||
);
|
||||
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.scopes.global = this.server.create(
|
||||
'scope',
|
||||
{ id: 'global' },
|
||||
'withGlobalAuth',
|
||||
);
|
||||
instances.account = this.server.schema.accounts.first();
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
scope: { id: 'global', type: 'global' },
|
||||
@@ -77,6 +81,7 @@ module(
|
||||
|
||||
this.ipcStub.withArgs('isCacheDaemonRunning').returns(true);
|
||||
this.stubCacheDaemonSearch('sessions', 'targets', 'aliases', 'sessions');
|
||||
await authenticateSession({ account_id: instances.account.id });
|
||||
});
|
||||
|
||||
test('it exists', function (assert) {
|
||||
|
||||
Reference in new issue
Block a user