Skip to content

Commit

Permalink
General cleanup and test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Nov 14, 2022
1 parent 3166b7a commit 60f7b60
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 76 deletions.
2 changes: 2 additions & 0 deletions ui/app/adapters/auth-method.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// @ts-check
import { default as ApplicationAdapter, namespace } from './application';
import { dasherize } from '@ember/string';
import classic from 'ember-classic-decorator';

@classic
export default class AuthMethodAdapter extends ApplicationAdapter {
namespace = `${namespace}/acl`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';

export default class OidcTestRoutePleaseDeleteController extends Controller {
export default class OidcMockController extends Controller {
queryParams = ['auth_method', 'client_nonce', 'redirect_uri', 'meta'];

@action
Expand Down
12 changes: 6 additions & 6 deletions ui/app/controllers/settings/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class Tokens extends Controller {

tokenIsValid = false;
tokenIsInvalid = false;
SSOFailure = false;

@alias('token.selfToken') tokenRecord;

resetStore() {
Expand Down Expand Up @@ -63,8 +63,7 @@ export default class Tokens extends Controller {

this.setProperties({
tokenIsValid: true,
tokenIsInvalid: false,
SSOFailure: false,
tokenIsInvalid: false
});
this.token.set('tokenNotFound', false);
},
Expand Down Expand Up @@ -112,9 +111,6 @@ export default class Tokens extends Controller {
this.validateSSO();
return true;
} else {
if (this.state === 'failure') {
this.SSOFailure = true;
}
return false;
}
}
Expand All @@ -140,4 +136,8 @@ export default class Tokens extends Controller {
}
});
}

get SSOFailure() {
return this.state === 'failure';
}
}
3 changes: 2 additions & 1 deletion ui/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ Router.map(function () {
path: '/path/*absolutePath',
});
});
// Mirage-only route for testing OIDC flow
if (config['ember-cli-mirage']) {
this.route('oidc-test-route-please-delete'); // TODO: TEMP
this.route('oidc-mock');
}
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Route from '@ember/routing/route';

export default class OidcTestRoutePleaseDeleteRoute extends Route {
export default class OidcMockRoute extends Route {
// This route only exists for testing SSO/OIDC flow in development, backed by our mirage server.
// This route won't load outside of a mirage environment, nor will the model hook here return anything meaningful.
model() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{page-title "OidcTestRoutePleaseDelete"}}
{{page-title "Mock OIDC Test Page"}}

<section class="mock-sso-provider">
<h1>Pretend this is {{this.auth_method}} for a sec</h1>
Expand Down
26 changes: 14 additions & 12 deletions ui/app/templates/settings/tokens.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@
</div>
</div>
{{else}}
<div class="notification is-info">
<div class="columns">
<div class="column">
<h3 class="title is-4">Token Storage</h3>
<p>Tokens are stored client-side in <a target="_blank" rel="noopener noreferrer" href="https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage">local storage</a>. This will persist your token across sessions. You can manually clear your token here.</p>
</div>
<div class="column is-centered is-minimum">
<button data-test-token-clear class="button is-info" {{action "clearTokenProperties"}} type="button">Clear Token</button>
</div>
</div>
</div>

{{#unless this.tokenIsValid}}
<div class="field">
Expand Down Expand Up @@ -108,7 +97,7 @@
<p>Your OIDC has failed to sign in; please try again or contact your SSO administrator.</p>
</div>
<div class="column is-centered is-minimum">
<button data-test-token-clear class="button is-info" {{action (mut this.SSOFailure) false}} type="button">Clear</button>
<button data-test-token-clear class="button is-info" {{action (mut this.state)}} type="button">Clear</button>
</div>
</div>
</div>
Expand All @@ -117,6 +106,19 @@
{{/if}}

{{#if this.tokenRecord}}

<div class="notification is-info">
<div class="columns">
<div class="column">
<h3 class="title is-4">Token Storage</h3>
<p>Tokens are stored client-side in <a target="_blank" rel="noopener noreferrer" href="https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage">local storage</a>. This will persist your token across sessions. You can manually clear your token here.</p>
</div>
<div class="column is-centered is-minimum">
<button data-test-token-clear class="button is-info" {{action "clearTokenProperties"}} type="button">Clear Token</button>
</div>
</div>
</div>

{{#unless this.tokenRecord.isExpired}}
<h3 class="title is-4">Token: {{this.tokenRecord.name}}</h3>
<div class="content">
Expand Down
5 changes: 2 additions & 3 deletions ui/mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export function filesForPath(allocFiles, filterPath) {
export default function () {
this.timing = 0; // delay for each request, automatically set to 0 during testing

// TODO: TEMP
this.logging = true; //window.location.search.includes('mirage-logging=true');
this.logging = window.location.search.includes('mirage-logging=true');

this.namespace = 'v1';
this.trackRequests = Ember.testing;
Expand Down Expand Up @@ -939,7 +938,7 @@ export default function () {
this.post('/acl/oidc/auth-url', (schema, req) => {
const {AuthMethod, ClientNonce, RedirectUri, Meta} = JSON.parse(req.requestBody);
return new Response(200, {}, {
AuthURL: `/ui/oidc-test-route-please-delete?auth_method=${AuthMethod}&client_nonce=${ClientNonce}&redirect_uri=${RedirectUri}&meta=${Meta}`
AuthURL: `/ui/oidc-mock?auth_method=${AuthMethod}&client_nonce=${ClientNonce}&redirect_uri=${RedirectUri}&meta=${Meta}`
});
});

Expand Down
3 changes: 1 addition & 2 deletions ui/tests/acceptance/token-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ module('Acceptance | tokens', function (hooks) {
await Tokens.visit();

// Token with no TTL
await Tokens.clear();
await Tokens.secret(clientToken.secretId).submit();
assert
.dom('[data-test-token-expiry]')
Expand Down Expand Up @@ -306,7 +305,7 @@ module('Acceptance | tokens', function (hooks) {
});

await Tokens.visit();
await Tokens.clear();
// await Tokens.clear();
// Ember Concurrency makes testing iterations convoluted: https://ember-concurrency.com/docs/testing-debugging/
// Waiting for half a second to validate that there's no warning;
// then a further 5 seconds to validate that there is a warning, and to explicitly cancelAllTimers(),
Expand Down
14 changes: 0 additions & 14 deletions ui/tests/unit/controllers/oidc-test-route-please-delete-test.js

This file was deleted.

13 changes: 0 additions & 13 deletions ui/tests/unit/models/auth-method-test.js

This file was deleted.

11 changes: 0 additions & 11 deletions ui/tests/unit/routes/oidc-test-route-please-delete-test.js

This file was deleted.

11 changes: 0 additions & 11 deletions ui/tests/unit/routes/settings/tokens-test.js

This file was deleted.

0 comments on commit 60f7b60

Please sign in to comment.