refactor: rewrite OIDC polling for ember pollster
This commit is contained in:
3 files changed
+9
-40
No files matched your search
@@ -1,42 +1,22 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { getOwner } from '@ember/application';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { task, timeout } from 'ember-concurrency';
|
||||
import { action } from '@ember/object';
|
||||
import runEvery from 'ember-pollster/decorators/route/run-every';
|
||||
import { notifyError } from 'core/decorators/notify';
|
||||
import config from '../../../../../config/environment';
|
||||
|
||||
const POLL_TIMEOUT_SECONDS = config.oidcPollingTimeoutSeconds;
|
||||
|
||||
export default class ScopesScopeAuthenticateMethodOidcRoute extends Route {
|
||||
|
||||
// =services
|
||||
|
||||
@service session;
|
||||
@service windowManager;
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* A simple Ember Concurrency-based polling task that refreshes the route
|
||||
* every POLL_TIMEOUT_SECONDS seconds. This is necessary to display changes
|
||||
* to session `status` that may occur.
|
||||
*
|
||||
* NOTE: tasks are sort of attributes and sort of methods, but they are not
|
||||
* language-level constructs. Thus we annotate this task as if it
|
||||
* is an attribute.
|
||||
* @type {Task}
|
||||
*/
|
||||
@task(function * () {
|
||||
while(!this.session.isAuthenticated) {
|
||||
yield timeout(POLL_TIMEOUT_SECONDS * 1000);
|
||||
yield this.refresh();
|
||||
}
|
||||
/* eslint-disable-next-line prettier/prettier */
|
||||
}).drop() poller;
|
||||
|
||||
// =methods
|
||||
|
||||
beforeModel;
|
||||
model() {
|
||||
const scope = this.modelFor('scopes.scope');
|
||||
const authMethod = this.modelFor('scopes.scope.authenticate.method');
|
||||
@@ -47,18 +27,9 @@ export default class ScopesScopeAuthenticateMethodOidcRoute extends Route {
|
||||
return oidc.attemptFetchToken({ scope, authMethod });
|
||||
}
|
||||
|
||||
/**
|
||||
* If authenticated, redirects to index for further processing.
|
||||
*/
|
||||
redirect() {
|
||||
if (this.session.isAuthenticated) this.replaceWith('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* When this route is activated (entered), begin polling for changes.
|
||||
*/
|
||||
activate() {
|
||||
this.poller.perform();
|
||||
@runEvery(POLL_TIMEOUT_SECONDS * 1000)
|
||||
poller() {
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +37,6 @@ export default class ScopesScopeAuthenticateMethodOidcRoute extends Route {
|
||||
* any windows opened via the window manager service.
|
||||
*/
|
||||
deactivate() {
|
||||
this.poller.cancelAll();
|
||||
this.windowManager.closeAll();
|
||||
}
|
||||
|
||||
@@ -81,5 +51,4 @@ export default class ScopesScopeAuthenticateMethodOidcRoute extends Route {
|
||||
// rethrow the error to activate the notifyError decorator
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -151,9 +151,6 @@ module.exports = function (environment) {
|
||||
|
||||
// Notification timeout should be 0 for fast tests
|
||||
ENV.notifyTimeout = 0;
|
||||
// Polling timeouts should be short
|
||||
ENV.sessionPollingTimeoutSeconds = 0.25;
|
||||
ENV.oidcPollingTimeoutSeconds = 0;
|
||||
ENV.enableConfirmService = false;
|
||||
|
||||
// Enable tests for development features
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { Response } from 'miragejs';
|
||||
//import { run, later } from '@ember/runloop';
|
||||
import { runAllJobs } from 'ember-pollster/test-support';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import {
|
||||
currentSession,
|
||||
@@ -383,6 +383,9 @@ module('Acceptance | authentication', function (hooks) {
|
||||
);
|
||||
await visit(authMethodOIDCAuthenticateURL);
|
||||
await click('form [type="submit"]');
|
||||
// explicitly poll multiple times to trigger mock OIDC auth
|
||||
await runAllJobs();
|
||||
await runAllJobs();
|
||||
});
|
||||
|
||||
// TODO: test OIDC retry and cancel
|
||||
|
||||
Reference in new issue
Block a user