vault/ui/tests/integration/components/oidc-consent-block-test.js
Chelsea Shaw 9c6bd51754
UI/OIDC provider (#12800)
* Add new route w/ controller oidc-provider

* oidc-provider controller has params, template has success message (temporary), model requests correct endpoint

* Move oidc-provider route to under identity

* Do not redirect after poll if on oidc-provider page

* WIP provider -- beforeModel handles prompt, logout, redirect

* Auth service fetch method rejects with fetch response if status >= 300

* New component OidcConsentBlock

* Fix redirect to/from auth with cluster name, show error and consent form if applicable

* Show error and consent form on template

* Add component test, update docs

* Test for oidc-consent-block component

* Add changelog

* fix tests

* Add authorize to end of router path

* Remove unused tests

* Update changelog with feature name

* Add descriptions for OidcConsentBlock component

* glimmerize token-expire-warning and don't override yield if on oidc-provider route

* remove text on token-expire-warning

* Fix null transition.to on cluster redirect

* Hide nav links if oidc-provider route
2021-10-13 15:04:39 -05:00

106 lines
4.2 KiB
JavaScript

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, click } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import sinon from 'sinon';
const redirectBase = 'https://hashicorp.com';
module('Integration | Component | oidc-consent-block', function(hooks) {
setupRenderingTest(hooks);
test('it renders', async function(assert) {
this.set('redirect', redirectBase);
await render(hbs`
<OidcConsentBlock @redirect={{redirect}} @code="1234" />
`);
assert.dom('[data-test-consent-title]').hasText('Consent', 'Title is correct on initial render');
assert
.dom('[data-test-consent-form]')
.includesText(
'In order to complete the login process, you must consent to Vault sharing your profile, email, address, and phone with the client.',
'shows the correct copy for consent form'
);
assert.dom('[data-test-edit-form-submit]').hasText('Yes', 'form button has correct submit text');
assert.dom('[data-test-cancel-button]').hasText('No', 'form button has correct cancel text');
});
test('it calls the success callback when user clicks "Yes"', async function(assert) {
const spy = sinon.spy();
this.set('successSpy', spy);
this.set('redirect', redirectBase);
await render(hbs`
<OidcConsentBlock @redirect={{redirect}} @code="1234" @testRedirect={{successSpy}} @foo="make sure this doesn't get passed" />
`);
assert.dom('[data-test-consent-title]').hasText('Consent', 'Title is correct on initial render');
assert.dom('[data-test-consent-form]').exists('Consent form exists');
assert
.dom('[data-test-consent-form]')
.includesText(
'In order to complete the login process, you must consent to Vault sharing your profile, email, address, and phone with the client.',
'shows the correct copy for consent form'
);
await click('[data-test-edit-form-submit]');
assert.ok(spy.calledWith(`${redirectBase}/?code=1234`), 'Redirects to correct route');
});
test('it shows the termination message when user clicks "No"', async function(assert) {
const spy = sinon.spy();
this.set('successSpy', spy);
this.set('redirect', redirectBase);
await render(hbs`
<OidcConsentBlock @redirect={{redirectBase}} @code="1234" @testRedirect={{successSpy}} />
`);
assert.dom('[data-test-consent-title]').hasText('Consent', 'Title is correct on initial render');
assert.dom('[data-test-consent-form]').exists('Consent form exists');
assert
.dom('[data-test-consent-form]')
.includesText(
'In order to complete the login process, you must consent to Vault sharing your profile, email, address, and phone with the client.',
'shows the correct copy for consent form'
);
await click('[data-test-cancel-button]');
assert.dom('[data-test-consent-title]').hasText('Consent Not Given', 'Title changes to not given');
assert.dom('[data-test-consent-form]').doesNotExist('Consent form is hidden');
assert.ok(spy.notCalled, 'Does not call the success method');
});
test('it calls the success callback with correct params', async function(assert) {
const spy = sinon.spy();
this.set('successSpy', spy);
this.set('redirect', redirectBase);
this.set('code', 'unescaped<string');
await render(hbs`
<OidcConsentBlock
@redirect={{redirect}}
@code={{code}}
@state="foo"
@foo="make sure this doesn't get passed"
@testRedirect={{successSpy}}
/>
`);
assert.dom('[data-test-consent-title]').hasText('Consent', 'Title is correct on initial render');
assert.dom('[data-test-consent-form]').exists('Consent form exists');
assert
.dom('[data-test-consent-form]')
.includesText(
'In order to complete the login process, you must consent to Vault sharing your profile, email, address, and phone with the client.',
'shows the correct copy for consent form'
);
await click('[data-test-edit-form-submit]');
console.log(spy, spy.args);
assert.ok(
spy.calledWith(`${redirectBase}/?code=unescaped%3Cstring&state=foo`),
'Redirects to correct route, with escaped values and without superflous params'
);
});
});