From 96ef767e6548e69c85c39d6daa32f1dbdd17f47a Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Fri, 19 Mar 2021 17:03:03 -0400 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20start=20auth=20oid?= =?UTF-8?q?c=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/dummy/app/authenticators/oidc.js | 15 ++++++++++ .../tests/unit/authenticators/oidc-test.js | 30 ++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 addons/auth/tests/dummy/app/authenticators/oidc.js diff --git a/addons/auth/tests/dummy/app/authenticators/oidc.js b/addons/auth/tests/dummy/app/authenticators/oidc.js new file mode 100644 index 000000000..f8ac3d57f --- /dev/null +++ b/addons/auth/tests/dummy/app/authenticators/oidc.js @@ -0,0 +1,15 @@ +import OIDCAuthenticator from 'auth/authenticators/oidc'; + +export default class ApplicationOIDCAuthenticator extends OIDCAuthenticator { + buildTokenValidationEndpointURL(id) { + return `/validate/${id}`; + } + + buildStartAuthEndpointURL() { + return '/authenticate:start'; + } + + buildDeauthEndpointURL() { + return '/deauthenticate'; + } +} diff --git a/addons/auth/tests/unit/authenticators/oidc-test.js b/addons/auth/tests/unit/authenticators/oidc-test.js index d40df7d15..e8dfd7216 100644 --- a/addons/auth/tests/unit/authenticators/oidc-test.js +++ b/addons/auth/tests/unit/authenticators/oidc-test.js @@ -1,8 +1,36 @@ -import { module /*, test */ } from 'qunit'; +import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; +import { Response } from 'miragejs'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; module('Unit | Authenticator | OIDC', function (hooks) { setupTest(hooks); setupMirage(hooks); + + test('`startAuthentication` initiates the authentication flow and returns the response', async function (assert) { + assert.expect(2); + const authenticator = this.owner.lookup('authenticator:oidc'); + this.server.post( + authenticator.buildStartAuthEndpointURL(), + () => new Response(200, {}, { foo: 'bar' }) + ); + const response = await authenticator.startAuthentication(); + assert.ok(true, 'authentication succeeded'); + assert.deepEqual(response, { foo: 'bar' }); + }); + + test('`startAuthentication` rejects/errors if API returns an error response', async function (assert) { + assert.expect(1); + const authenticator = this.owner.lookup('authenticator:oidc'); + this.server.post( + authenticator.buildStartAuthEndpointURL(), + () => new Response(400) + ); + // Because assert.throws doesn't work with async errors/promise rejections + try { + await authenticator.startAuthentication(); + } catch (e) { + assert.ok(true); + } + }); });