From a3c12b36e764dbd706ea36c29dab8cd653ebdcd2 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Fri, 15 Jan 2021 17:32:30 -0500 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20mock=20authenticate?= =?UTF-8?q?=20should=20handle=20multiple=20auth=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/mirage/route-handlers/auth.js | 36 +++++++++++-------- addons/auth/addon/authenticators/oidc.js | 8 ++--- .../tests/unit/authenticators/oidc-test.js | 2 +- .../components/form/authenticate/oidc-test.js | 26 -------------- .../tests/acceptance/authentication-test.js | 6 +++- yarn.lock | 27 +++----------- 6 files changed, 36 insertions(+), 69 deletions(-) delete mode 100644 addons/core/tests/integration/components/form/authenticate/oidc-test.js diff --git a/addons/api/mirage/route-handlers/auth.js b/addons/api/mirage/route-handlers/auth.js index 96813a7d5..84d755324 100644 --- a/addons/api/mirage/route-handlers/auth.js +++ b/addons/api/mirage/route-handlers/auth.js @@ -23,28 +23,34 @@ import { Response } from 'miragejs'; // } // } +const methodHandlers = { + password: { + authenticate: (scopeAttrs) => + 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); if (payload.credentials.login_name === 'error') { return new Response(400); } else { - const id = request.params.id_method.split(':')[0]; + 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)); - 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: '' - }); + const scopeAttrs = this.serialize(scopes.find(scope.id)); + return methodHandlers[authMethod.type][method](scopeAttrs); } } diff --git a/addons/auth/addon/authenticators/oidc.js b/addons/auth/addon/authenticators/oidc.js index 0d641da41..4fd24845c 100644 --- a/addons/auth/addon/authenticators/oidc.js +++ b/addons/auth/addon/authenticators/oidc.js @@ -1,7 +1,7 @@ import BaseAuthenticator from './base'; // import { resolve, reject } from 'rsvp'; // import fetch from 'fetch'; -import { Promise } from 'rsvp'; +//import { Promise } from 'rsvp'; /** * @@ -17,9 +17,9 @@ export default class OIDCAuthenticator extends BaseAuthenticator { } */) { } async authenticate( - creds, - requestCookies = true, - options + // creds, + // requestCookies = true, + // options ) { return false; } diff --git a/addons/auth/tests/unit/authenticators/oidc-test.js b/addons/auth/tests/unit/authenticators/oidc-test.js index 0d4a9b492..c5498f123 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/tests/integration/components/form/authenticate/oidc-test.js b/addons/core/tests/integration/components/form/authenticate/oidc-test.js deleted file mode 100644 index 3345d3e3d..000000000 --- a/addons/core/tests/integration/components/form/authenticate/oidc-test.js +++ /dev/null @@ -1,26 +0,0 @@ -import { module, test } from 'qunit'; -import { setupRenderingTest } from 'ember-qunit'; -import { render } from '@ember/test-helpers'; -import { hbs } from 'ember-cli-htmlbars'; - -module('Integration | Component | form/authenticate/oidc', function(hooks) { - setupRenderingTest(hooks); - - test('it renders', async function(assert) { - // Set any properties with this.set('myProperty', 'value'); - // Handle any actions with this.set('myAction', function(val) { ... }); - - await render(hbs``); - - assert.equal(this.element.textContent.trim(), ''); - - // Template block usage: - await render(hbs` - - template block text - - `); - - assert.equal(this.element.textContent.trim(), 'template block text'); - }); -}); diff --git a/ui/admin/tests/acceptance/authentication-test.js b/ui/admin/tests/acceptance/authentication-test.js index f39c4d9bd..82a7184db 100644 --- a/ui/admin/tests/acceptance/authentication-test.js +++ b/ui/admin/tests/acceptance/authentication-test.js @@ -66,8 +66,12 @@ module('Acceptance | authentication', function (hooks) { scope = { id: orgScope.id, type: orgScope.type }; globalAuthMethod = this.server.create('auth-method', { scope: globalScope, + type: 'password' + }); + authMethod = this.server.create('auth-method', { + scope: orgScope, + type: 'password' }); - authMethod = this.server.create('auth-method', { scope: orgScope }); orgScopeID = orgScope.id; globalAuthMethodID = globalAuthMethod.id; authMethodID = authMethod.id; diff --git a/yarn.lock b/yarn.lock index 9544a1b3b..7ecac33ed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7503,7 +7503,7 @@ debug@~4.1.0: dependencies: ms "^2.1.1" -debuglog@*, debuglog@^1.0.1: +debuglog@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492" integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI= @@ -12311,7 +12311,7 @@ import-lazy@^4.0.0: resolved "https://registry.yarnpkg.com/import-lazy/-/import-lazy-4.0.0.tgz#e8eb627483a0a43da3c03f3e35548be5cb0cc153" integrity sha512-rKtvo6a868b5Hu3heneU+L4yEQ4jYKLtjpnPeUdK7h0yzXGmyBTypknlkCvHFBqfX9YlorEiMM6Dnq/5atfHkw== -imurmurhash@*, imurmurhash@^0.1.4: +imurmurhash@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" integrity sha1-khi5srkoojixPcT7a21XbyMUU+o= @@ -14004,11 +14004,6 @@ lodash._baseflatten@^3.0.0: lodash.isarguments "^3.0.0" lodash.isarray "^3.0.0" -lodash._baseindexof@*: - version "3.1.0" - resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c" - integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw= - lodash._baseuniq@~4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8" @@ -14017,16 +14012,11 @@ lodash._baseuniq@~4.6.0: lodash._createset "~4.0.0" lodash._root "~3.0.0" -lodash._bindcallback@*, lodash._bindcallback@^3.0.0: +lodash._bindcallback@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e" integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4= -lodash._cacheindexof@*: - version "3.0.2" - resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92" - integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI= - lodash._createassigner@^3.0.0: version "3.1.1" resolved "https://registry.yarnpkg.com/lodash._createassigner/-/lodash._createassigner-3.1.1.tgz#838a5bae2fdaca63ac22dee8e19fa4e6d6970b11" @@ -14036,19 +14026,12 @@ lodash._createassigner@^3.0.0: lodash._isiterateecall "^3.0.0" lodash.restparam "^3.0.0" -lodash._createcache@*: - version "3.1.2" - resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093" - integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM= - dependencies: - lodash._getnative "^3.0.0" - lodash._createset@~4.0.0: version "4.0.3" resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26" integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY= -lodash._getnative@*, lodash._getnative@^3.0.0: +lodash._getnative@^3.0.0: version "3.9.1" resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5" integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U= @@ -14261,7 +14244,7 @@ lodash.pick@^4.4.0: resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3" integrity sha1-UvBWEP/53tQiYRRB7R/BI6AwAbM= -lodash.restparam@*, lodash.restparam@^3.0.0: +lodash.restparam@^3.0.0: version "3.6.1" resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=