From 6056b50939081370d8d5a9f642ee7ce97fcfd110 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 15 Mar 2021 17:08:47 -0400 Subject: [PATCH] chore: manual merge from main --- addons/api/mirage/factories/auth-method.js | 5 +- addons/api/mirage/route-handlers/auth.js | 82 +++++++++++-------- addons/auth/addon/authenticators/oidc.js | 9 +- .../tests/unit/authenticators/oidc-test.js | 2 +- addons/core/addon/authenticators/oidc.js | 10 +-- .../app/components/form/authenticate/oidc.js | 2 +- ui/admin/app/router.js | 2 +- .../scopes/scope/authenticate/method.js | 9 +- .../scopes/scope/authenticate/method/index.js | 3 +- .../scopes/scope/authenticate/method/oidc.js | 1 + .../tests/acceptance/authentication-test.js | 4 +- .../scope/authenticate/method/index-test.js | 19 +++-- .../scope/authenticate/method/oidc-test.js | 19 +++-- ui/desktop/electron-app/src/index.js | 14 ++-- 14 files changed, 102 insertions(+), 79 deletions(-) diff --git a/addons/api/mirage/factories/auth-method.js b/addons/api/mirage/factories/auth-method.js index ed8ca6947..b7dc8ddda 100644 --- a/addons/api/mirage/factories/auth-method.js +++ b/addons/api/mirage/factories/auth-method.js @@ -1,10 +1,7 @@ import factory from '../generated/factories/auth-method'; import { trait } from 'ember-cli-mirage'; -const types = [ - 'password', - 'oidc' -]; +const types = ['password', 'oidc']; export default factory.extend({ id: (i) => `auth-method-id-${i}`, diff --git a/addons/api/mirage/route-handlers/auth.js b/addons/api/mirage/route-handlers/auth.js index 59a2f896e..8873d5333 100644 --- a/addons/api/mirage/route-handlers/auth.js +++ b/addons/api/mirage/route-handlers/auth.js @@ -35,20 +35,24 @@ const methodHandlers = { if (payload.credentials.login_name === 'error') { return new Response(400); } else { - return new Response(200, {}, { - scope: scopeAttrs, - id: 'token123', - token: 'thetokenstring', - account_id: '1', - user_id: 'user123', - auth_method_id: 'authmethod123', - created_time: '', - updated_time: '', - last_used_time: '', - expiration_time: '' - }); + return new Response( + 200, + {}, + { + scope: scopeAttrs, + id: 'token123', + token: 'thetokenstring', + account_id: '1', + user_id: 'user123', + auth_method_id: 'authmethod123', + created_time: '', + updated_time: '', + last_used_time: '', + expiration_time: '', + } + ); } - } + }, }, /** @@ -63,37 +67,47 @@ const methodHandlers = { */ oidc: { 'authenticate:start': () => - new Response(200, {}, { - authorization_request_url: 'https://www.duckduckgo.com', - retreival_url: '', - token_request_id: 'token_request_1234', - state: 'base_58_encoded_string' - }), + new Response( + 200, + {}, + { + authorization_request_url: 'https://www.duckduckgo.com', + retreival_url: '', + token_request_id: 'token_request_1234', + state: 'base_58_encoded_string', + } + ), 'authenticate:token': (_, scopeAttrs) => { oidcAttemptCounter++; if (oidcAttemptCounter < oidcRequiredAttempts) { return new Response(100); } else { - return new Response(200, {}, { - scope: scopeAttrs, - id: 'token123', - token: 'thetokenstring', - account_id: '1', - user_id: 'user123', - auth_method_id: 'authmethod123', - created_time: '', - updated_time: '', - last_used_time: '', - expiration_time: '' - }); + return new Response( + 200, + {}, + { + scope: scopeAttrs, + id: 'token123', + token: 'thetokenstring', + account_id: '1', + user_id: 'user123', + auth_method_id: 'authmethod123', + created_time: '', + updated_time: '', + last_used_time: '', + expiration_time: '', + } + ); } - } - } + }, + }, }; export function authHandler({ scopes, authMethods }, request) { const payload = JSON.parse(request.requestBody); - const [, id, method] = request.params.id_method.match(/(?.[^:]*)(?::)?(?.*)?/); + const [, id, method] = request.params.id_method.match( + /(?.[^:]*)(?::)?(?.*)?/ + ); const authMethod = authMethods.find(id); const scope = scopes.find(authMethod.scopeId); const scopeAttrs = this.serialize(scopes.find(scope.id)); diff --git a/addons/auth/addon/authenticators/oidc.js b/addons/auth/addon/authenticators/oidc.js index ad3b1c760..583154b2a 100644 --- a/addons/auth/addon/authenticators/oidc.js +++ b/addons/auth/addon/authenticators/oidc.js @@ -22,7 +22,6 @@ import fetch from 'fetch'; * `authenticators/application.js` and extend this class. */ export default class OIDCAuthenticator extends BaseAuthenticator { - // =services @service session; @@ -40,7 +39,7 @@ export default class OIDCAuthenticator extends BaseAuthenticator { buildStartAuthEndpointURL(/* { scope: { id: scopeID }, authMethod: { id: authMethodID }, - } */) { } + } */) {} /** * Generates an auth method URL with which to authenticate. @@ -53,7 +52,7 @@ export default class OIDCAuthenticator extends BaseAuthenticator { buildTokenAuthEndpointURL(/* { scope: { id: scopeID }, authMethod: { id: authMethodID }, - } */) { } + } */) {} /** * Kicks-off the OIDC flow: calls the `authenticate:start` action on the @@ -72,7 +71,7 @@ export default class OIDCAuthenticator extends BaseAuthenticator { if (response.status < 400) { // Store meta about the pending OIDC flow this.session.set('data.pending', { - oidc: json + oidc: json, }); return json; } else { @@ -108,7 +107,7 @@ export default class OIDCAuthenticator extends BaseAuthenticator { const url = this.buildTokenAuthEndpointURL(options); const body = JSON.stringify({ state: this.session.get('data.pending.oidc.state'), - token_request_id: this.session.get('data.pending.oidc.token_request_id') + token_request_id: this.session.get('data.pending.oidc.token_request_id'), }); // Fetch the endpoint and get the response JSON const response = await fetch(url, { method: 'post', body }); diff --git a/addons/auth/tests/unit/authenticators/oidc-test.js b/addons/auth/tests/unit/authenticators/oidc-test.js index c5498f123..d40df7d15 100644 --- a/addons/auth/tests/unit/authenticators/oidc-test.js +++ b/addons/auth/tests/unit/authenticators/oidc-test.js @@ -1,4 +1,4 @@ -import { module/*, test */} from 'qunit'; +import { module /*, test */ } from 'qunit'; import { setupTest } from 'ember-qunit'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; diff --git a/addons/core/addon/authenticators/oidc.js b/addons/core/addon/authenticators/oidc.js index 68ae846d4..abb9179e3 100644 --- a/addons/core/addon/authenticators/oidc.js +++ b/addons/core/addon/authenticators/oidc.js @@ -5,7 +5,6 @@ import { inject as service } from '@ember/service'; * An OIDC authenticator that handles flow kick-off and polling. */ export default class OIDCAuthenticator extends BaseOIDCAuthenticator { - // =services @service store; @@ -28,8 +27,8 @@ export default class OIDCAuthenticator extends BaseOIDCAuthenticator { const options = { adapterOptions: { scopeID, - method: 'authenticate:start' - } + method: 'authenticate:start', + }, }; return adapter.buildURL('auth-method', authMethodID, options, 'findRecord'); } @@ -49,7 +48,9 @@ export default class OIDCAuthenticator extends BaseOIDCAuthenticator { authMethod: { id: authMethodID }, }) { const adapter = this.store.adapterFor('application'); - const options = { adapterOptions: { scopeID, method: 'authenticate:token' } }; + const options = { + adapterOptions: { scopeID, method: 'authenticate:token' }, + }; return adapter.buildURL('auth-method', authMethodID, options, 'findRecord'); } @@ -63,5 +64,4 @@ export default class OIDCAuthenticator extends BaseOIDCAuthenticator { const adapter = this.store.adapterFor('auth-token'); return adapter.buildURL('auth-token', tokenID, {}, 'findRecord'); } - } diff --git a/addons/core/app/components/form/authenticate/oidc.js b/addons/core/app/components/form/authenticate/oidc.js index cbb3b8ab4..7e7fe7a85 100644 --- a/addons/core/app/components/form/authenticate/oidc.js +++ b/addons/core/app/components/form/authenticate/oidc.js @@ -1 +1 @@ -export { default } from 'core/components/form/authenticate/oidc'; \ No newline at end of file +export { default } from 'core/components/form/authenticate/oidc'; diff --git a/ui/admin/app/router.js b/ui/admin/app/router.js index 848cc8e8f..b300a1333 100644 --- a/ui/admin/app/router.js +++ b/ui/admin/app/router.js @@ -10,7 +10,7 @@ Router.map(function () { this.route('scopes', function () { this.route('scope', { path: ':scope_id' }, function () { this.route('authenticate', function () { - this.route('method', { path: ':auth_method_id' }, function() { + this.route('method', { path: ':auth_method_id' }, function () { this.route('oidc'); }); }); diff --git a/ui/admin/app/routes/scopes/scope/authenticate/method.js b/ui/admin/app/routes/scopes/scope/authenticate/method.js index 075c4ae3a..7adf58b98 100644 --- a/ui/admin/app/routes/scopes/scope/authenticate/method.js +++ b/ui/admin/app/routes/scopes/scope/authenticate/method.js @@ -49,10 +49,10 @@ export default class ScopesScopeAuthenticateMethodRoute extends Route { this.transitionTo('index'); break; case 'oidc': - await this.startOIDCAuthentication( - authenticatorName, - { scope, authMethod } - ); + await this.startOIDCAuthentication(authenticatorName, { + scope, + authMethod, + }); this.transitionTo('scopes.scope.authenticate.method.oidc'); break; } @@ -78,5 +78,4 @@ export default class ScopesScopeAuthenticateMethodRoute extends Route { // TODO don't use window directly await window.open(url); } - } diff --git a/ui/admin/app/routes/scopes/scope/authenticate/method/index.js b/ui/admin/app/routes/scopes/scope/authenticate/method/index.js index 17d37582a..fc9b10575 100644 --- a/ui/admin/app/routes/scopes/scope/authenticate/method/index.js +++ b/ui/admin/app/routes/scopes/scope/authenticate/method/index.js @@ -1,4 +1,3 @@ import Route from '@ember/routing/route'; -export default class ScopesScopeAuthenticateMethodIndexRoute extends Route { -} +export default class ScopesScopeAuthenticateMethodIndexRoute extends Route {} diff --git a/ui/admin/app/routes/scopes/scope/authenticate/method/oidc.js b/ui/admin/app/routes/scopes/scope/authenticate/method/oidc.js index cb0a9b564..1e3f97e79 100644 --- a/ui/admin/app/routes/scopes/scope/authenticate/method/oidc.js +++ b/ui/admin/app/routes/scopes/scope/authenticate/method/oidc.js @@ -29,6 +29,7 @@ export default class ScopesScopeAuthenticateMethodOidcRoute extends Route { yield timeout(POLL_TIMEOUT_SECONDS * 1000); yield this.refresh(); } + /* eslint-disable-next-line prettier/prettier */ }).drop() poller; // =methods diff --git a/ui/admin/tests/acceptance/authentication-test.js b/ui/admin/tests/acceptance/authentication-test.js index b51db943d..3578ae935 100644 --- a/ui/admin/tests/acceptance/authentication-test.js +++ b/ui/admin/tests/acceptance/authentication-test.js @@ -66,11 +66,11 @@ module('Acceptance | authentication', function (hooks) { scope = { id: orgScope.id, type: orgScope.type }; globalAuthMethod = this.server.create('auth-method', { scope: globalScope, - type: 'password' + type: 'password', }); authMethod = this.server.create('auth-method', { scope: orgScope, - type: 'password' + type: 'password', }); orgScopeID = orgScope.id; globalAuthMethodID = globalAuthMethod.id; diff --git a/ui/admin/tests/unit/routes/scopes/scope/authenticate/method/index-test.js b/ui/admin/tests/unit/routes/scopes/scope/authenticate/method/index-test.js index 5f6cfcf5f..10a6a561c 100644 --- a/ui/admin/tests/unit/routes/scopes/scope/authenticate/method/index-test.js +++ b/ui/admin/tests/unit/routes/scopes/scope/authenticate/method/index-test.js @@ -1,11 +1,16 @@ import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; -module('Unit | Route | scopes/scope/authenticate/method/index', function(hooks) { - setupTest(hooks); +module( + 'Unit | Route | scopes/scope/authenticate/method/index', + function (hooks) { + setupTest(hooks); - test('it exists', function(assert) { - let route = this.owner.lookup('route:scopes/scope/authenticate/method/index'); - assert.ok(route); - }); -}); + test('it exists', function (assert) { + let route = this.owner.lookup( + 'route:scopes/scope/authenticate/method/index' + ); + assert.ok(route); + }); + } +); diff --git a/ui/admin/tests/unit/routes/scopes/scope/authenticate/method/oidc-test.js b/ui/admin/tests/unit/routes/scopes/scope/authenticate/method/oidc-test.js index a51f158cd..2c2764470 100644 --- a/ui/admin/tests/unit/routes/scopes/scope/authenticate/method/oidc-test.js +++ b/ui/admin/tests/unit/routes/scopes/scope/authenticate/method/oidc-test.js @@ -1,11 +1,16 @@ import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; -module('Unit | Route | scopes/scope/authenticate/method/oidc', function(hooks) { - setupTest(hooks); +module( + 'Unit | Route | scopes/scope/authenticate/method/oidc', + function (hooks) { + setupTest(hooks); - test('it exists', function(assert) { - let route = this.owner.lookup('route:scopes/scope/authenticate/method/oidc'); - assert.ok(route); - }); -}); + test('it exists', function (assert) { + let route = this.owner.lookup( + 'route:scopes/scope/authenticate/method/oidc' + ); + assert.ok(route); + }); + } +); diff --git a/ui/desktop/electron-app/src/index.js b/ui/desktop/electron-app/src/index.js index 4ed11956a..9dff06506 100644 --- a/ui/desktop/electron-app/src/index.js +++ b/ui/desktop/electron-app/src/index.js @@ -57,7 +57,8 @@ app.on('ready', async () => { // Register custom protocol // This file protocol is the exclusive protocol for this application. All // other protocols are disabled. - ses.protocol.registerFileProtocol(emberAppProtocol, (request, callback) => { /* eng-disable PROTOCOL_HANDLER_JS_CHECK */ + ses.protocol.registerFileProtocol(emberAppProtocol, (request, callback) => { + /* eng-disable PROTOCOL_HANDLER_JS_CHECK */ const isDir = request.url.endsWith('/'); const absolutePath = request.url.substr(emberAppURL.length); const normalizedPath = isDir @@ -71,7 +72,8 @@ app.on('ready', async () => { // Disallow all permissions requests, // per Electronegativity PERMISSION_REQUEST_HANDLER_GLOBAL_CHECK - ses.setPermissionRequestHandler((webContents, permission, callback) => { /* eng-disable PERMISSION_REQUEST_HANDLER_JS_CHECK */ + ses.setPermissionRequestHandler((webContents, permission, callback) => { + /* eng-disable PERMISSION_REQUEST_HANDLER_JS_CHECK */ return callback(false); }); @@ -119,7 +121,7 @@ app.on('ready', async () => { allowRunningInsecureContent: false, // The preload script establishes the message-based IPC pathway without // exposing new modules to the renderer. - preload: preloadPath, /* eng-disable PRELOAD_JS_CHECK */ + preload: preloadPath /* eng-disable PRELOAD_JS_CHECK */, disableBlinkFeatures: 'Auxclick', }, }); @@ -151,10 +153,12 @@ app.on('ready', async () => { // Prevent navigation outside of serve://boundary per // Electronegativity LIMIT_NAVIGATION_GLOBAL_CHECK - mainWindow.webContents.on('will-navigate', (event, url) => { /* eng-disable LIMIT_NAVIGATION_JS_CHECK */ + mainWindow.webContents.on('will-navigate', (event, url) => { + /* eng-disable LIMIT_NAVIGATION_JS_CHECK */ if (!url.startsWith('serve://boundary')) event.preventDefault(); }); - mainWindow.webContents.on('new-window', (event, url) => { /* eng-disable LIMIT_NAVIGATION_JS_CHECK */ + mainWindow.webContents.on('new-window', (event, url) => { + /* eng-disable LIMIT_NAVIGATION_JS_CHECK */ if (!url.startsWith('serve://boundary')) event.preventDefault(); });