diff --git a/ui/app/components/oidc-auth-buttons/index.hbs b/ui/app/components/oidc-auth-buttons/index.hbs index a42fdfa5b6a..636ebdf47dc 100644 --- a/ui/app/components/oidc-auth-buttons/index.hbs +++ b/ui/app/components/oidc-auth-buttons/index.hbs @@ -2,6 +2,7 @@ {{#if this.initializeOIDCFlow.isRunning}} diff --git a/ui/mirage/config.ts b/ui/mirage/config.ts index 35a0a66bc3c..a04222fff61 100644 --- a/ui/mirage/config.ts +++ b/ui/mirage/config.ts @@ -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'; @@ -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 diff --git a/ui/mirage/factories/auth-method.ts b/ui/mirage/factories/auth-method.ts new file mode 100644 index 00000000000..cd53c440662 --- /dev/null +++ b/ui/mirage/factories/auth-method.ts @@ -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', + }), +}); diff --git a/ui/mirage/models/auth-method.ts b/ui/mirage/models/auth-method.ts new file mode 100644 index 00000000000..788ebee4bd2 --- /dev/null +++ b/ui/mirage/models/auth-method.ts @@ -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; + }, +}); diff --git a/ui/mirage/services/oidc-auth-methods.ts b/ui/mirage/services/oidc-auth-methods.ts new file mode 100644 index 00000000000..7b1973c0384 --- /dev/null +++ b/ui/mirage/services/oidc-auth-methods.ts @@ -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'); +} diff --git a/ui/tests/acceptance/auth-test.ts b/ui/tests/acceptance/auth-test.ts index cdd492a6854..c94aed212d4 100644 --- a/ui/tests/acceptance/auth-test.ts +++ b/ui/tests/acceptance/auth-test.ts @@ -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`);