Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Add mocks and add OIDC provider test
Browse files Browse the repository at this point in the history
  • Loading branch information
gregone committed Nov 9, 2021
1 parent 938fbd7 commit 8d89b15
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 11 deletions.
1 change: 1 addition & 0 deletions ui/app/components/oidc-auth-buttons/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<Pds::Button
@variant="primary"
disabled={{this.initializeOIDCFlow.isRunning}}
data-test-oidc-provider={{authMethod.name}}
{{on "click" (perform this.initializeOIDCFlow authMethod)}}>
{{#if this.initializeOIDCFlow.isRunning}}
<Spinner @size="16"/>
Expand Down
24 changes: 13 additions & 11 deletions ui/mirage/config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import Ember from 'ember';
import { logRequestConsole } from './utils';
import failUnhandledRequest from './helpers/fail-unhandled-request';
import { Server } from 'miragejs';

import * as OIDCAuthMethods from './services/oidc-auth-methods';
import * as build from './services/build';
import * as project from './services/project';
import * as config from './services/config';
import * as deployment from './services/deployment';
import * as token from './services/token';
import * as inviteToken from './services/invite-token';
import * as release from './services/release';
import * as versionInfo from './services/version-info';
import * as statusReport from './services/status-report';
import * as job from './services/job';
import * as log from './services/log';
import * as project from './services/project';
import * as pushedArtifact from './services/pushed-artifact';
import * as config from './services/config';
import * as release from './services/release';
import * as statusReport from './services/status-report';
import * as token from './services/token';
import * as versionInfo from './services/version-info';

import Ember from 'ember';
import { Server } from 'miragejs';
import failUnhandledRequest from './helpers/fail-unhandled-request';
import { logRequestConsole } from './utils';

export default function (this: Server): void {
this.namespace = 'hashicorp.waypoint.Waypoint';
Expand Down Expand Up @@ -57,6 +58,7 @@ export default function (this: Server): void {
this.post('/ExpediteStatusReport', statusReport.expediteStatusReport);
this.post('/GetConfig', config.get);
this.post('/SetConfig', config.set);
this.post('/ListOIDCAuthMethods', OIDCAuthMethods.list);

if (!Ember.testing) {
// Pass through all other requests
Expand Down
13 changes: 13 additions & 0 deletions ui/mirage/factories/auth-method.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Factory, trait } from 'ember-cli-mirage';

import faker from '../faker';

export default Factory.extend({
name: () => faker.company.companyName(),
displayName: () => faker.company.companyName(),
kind: 0,
google: trait({
name: 'google',
displayName: 'google',
}),
});
13 changes: 13 additions & 0 deletions ui/mirage/models/auth-method.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Model } from 'miragejs';
import { OIDCAuthMethod } from 'waypoint-pb';

export default Model.extend({
toProtobuf(): OIDCAuthMethod {
let result = new OIDCAuthMethod();

result.setDisplayName(this.displayName);
result.setKind(0);
result.setName(this.name);
return result;
},
});
13 changes: 13 additions & 0 deletions ui/mirage/services/oidc-auth-methods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Request, Response, RouteHandler } from 'miragejs';

import { ListOIDCAuthMethodsResponse } from 'waypoint-pb';

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
export function list(this: RouteHandler, schema: any, { requestBody }: Request): Response {
let authMethods = schema.authMethods.all();
let authMethodsProtos = authMethods.models?.map((model) => model?.toProtobuf());

let resp = new ListOIDCAuthMethodsResponse();
resp.setAuthMethodsList(authMethodsProtos);
return this.serialize(resp, 'application');
}
7 changes: 7 additions & 0 deletions ui/tests/acceptance/auth-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ module('Acceptance | auth', function (hooks: NestedHooks) {
assert.equal(currentURL(), `/auth`);
});

test('has an OIDC provider button when it exists', async function (assert) {
this.server.create('auth-method', 'google');
await visit(`/default`);
assert.equal(currentURL(), `/auth`);
assert.dom('[data-test-oidc-provider="google"]').exists();
});

test('does not redirect to /auth from authenticated routes when logged in', async function (assert) {
await login();
await visit(`/default`);
Expand Down

0 comments on commit 8d89b15

Please sign in to comment.