open-vault/ui/tests/acceptance/auth-test.js
Jordan Reimer 5c2a08de6d
Ember Upgrade to 3.24 (#13443)
* Update browserslist

* Add browserslistrc

* ember-cli-update --to 3.26, fix conflicts

* Run codemodes that start with ember-*

* More codemods - before cp*

* More codemods (curly data-test-*)

* WIP ember-basic-dropdown template errors

* updates ember-basic-dropdown and related deps to fix build issues

* updates basic dropdown instances to new version API

* updates more deps -- ember-template-lint is working again

* runs no-implicit-this codemod

* creates and runs no-quoteless-attributes codemod

* runs angle brackets codemod

* updates lint:hbs globs to only touch hbs files

* removes yield only templates

* creates and runs deprecated args transform

* supresses lint error for invokeAction on LinkTo component

* resolves remaining ambiguous path lint errors

* resolves simple-unless lint errors

* adds warnings for deprecated tagName arg on LinkTo components

* adds warnings for remaining curly component invocation

* updates global template lint rules

* resolves remaining template lint errors

* disables some ember specfic lint rules that target pre octane patterns

* js lint fix run

* resolves remaining js lint errors

* fixes test run

* adds npm-run-all dep

* fixes test attribute issues

* fixes console acceptance tests

* fixes tests

* adds yield only wizard/tutorial-active template

* fixes more tests

* attempts to fix more flaky tests

* removes commented out settled in transit test

* updates deprecations workflow and adds initializer to filter by version

* updates flaky policies acl old test

* updates to flaky transit test

* bumps ember deps down to LTS version

* runs linters after main merge

* fixes client count tests after bad merge conflict fixes

* fixes client count history test

* more updates to lint config

* another round of hbs lint fixes after extending stylistic rule

* updates lint-staged commands

* removes indent eslint rule since it seems to break things

* fixes bad attribute in transform-edit-form template

* test fixes

* fixes enterprise tests

* adds changelog

* removes deprecated ember-concurrency-test-waiters dep and adds @ember/test-waiters

* flaky test fix

Co-authored-by: hashishaw <cshaw@hashicorp.com>
2021-12-16 20:44:29 -07:00

126 lines
4.8 KiB
JavaScript

import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import sinon from 'sinon';
import { click, currentURL, visit, settled } from '@ember/test-helpers';
import { supportedAuthBackends } from 'vault/helpers/supported-auth-backends';
import authForm from '../pages/components/auth-form';
import jwtForm from '../pages/components/auth-jwt';
import { create } from 'ember-cli-page-object';
import apiStub from 'vault/tests/helpers/noop-all-api-requests';
import authPage from 'vault/tests/pages/auth';
import logout from 'vault/tests/pages/logout';
import consoleClass from 'vault/tests/pages/components/console/ui-panel';
const consoleComponent = create(consoleClass);
const component = create(authForm);
const jwtComponent = create(jwtForm);
module('Acceptance | auth', function (hooks) {
setupApplicationTest(hooks);
hooks.beforeEach(function () {
this.clock = sinon.useFakeTimers({
now: Date.now(),
shouldAdvanceTime: true,
});
this.server = apiStub({ usePassthrough: true });
return logout.visit();
});
hooks.afterEach(function () {
this.clock.restore();
this.server.shutdown();
return logout.visit();
});
test('auth query params', async function (assert) {
let backends = supportedAuthBackends();
assert.expect(backends.length + 1);
await visit('/vault/auth');
assert.equal(currentURL(), '/vault/auth?with=token');
for (let backend of backends.reverse()) {
await component.selectMethod(backend.type);
assert.equal(
currentURL(),
`/vault/auth?with=${backend.type}`,
`has the correct URL for ${backend.type}`
);
}
});
test('it clears token when changing selected auth method', async function (assert) {
await visit('/vault/auth');
assert.equal(currentURL(), '/vault/auth?with=token');
await component.token('token').selectMethod('github');
await component.selectMethod('token');
assert.equal(component.tokenValue, '', 'it clears the token value when toggling methods');
});
test('it sends the right attributes when authenticating', async function (assert) {
let backends = supportedAuthBackends();
await visit('/vault/auth');
for (let backend of backends.reverse()) {
await component.selectMethod(backend.type);
if (backend.type === 'github') {
await component.token('token');
}
if (backend.type === 'jwt' || backend.type === 'oidc') {
await jwtComponent.role('test');
}
await component.login();
let lastRequest = this.server.passthroughRequests[this.server.passthroughRequests.length - 1];
let body = JSON.parse(lastRequest.requestBody);
// Note: x-vault-token used to be lowercase prior to upgrade
if (backend.type === 'token') {
assert.ok(
Object.keys(lastRequest.requestHeaders).includes('X-Vault-Token'),
'token uses vault token header'
);
} else if (backend.type === 'github') {
assert.ok(Object.keys(body).includes('token'), 'GitHub includes token');
} else if (backend.type === 'jwt' || backend.type === 'oidc') {
let authReq = this.server.passthroughRequests[this.server.passthroughRequests.length - 2];
body = JSON.parse(authReq.requestBody);
assert.ok(Object.keys(body).includes('role'), `${backend.type} includes role`);
} else {
assert.ok(Object.keys(body).includes('password'), `${backend.type} includes password`);
}
}
});
test('it shows the token warning beacon on the menu', async function (assert) {
let authService = this.owner.lookup('service:auth');
await authPage.login();
await settled();
await consoleComponent.runCommands([
'write -field=client_token auth/token/create policies=default ttl=1h',
]);
let token = consoleComponent.lastTextOutput;
await logout.visit();
await settled();
await authPage.login(token);
await settled();
this.clock.tick(authService.IDLE_TIMEOUT);
authService.shouldRenew();
await settled();
assert.dom('[data-test-allow-expiration]').exists('shows expiration beacon');
await visit('/vault/access');
assert.dom('[data-test-allow-expiration]').doesNotExist('hides beacon when the api is used again');
});
test('it shows the push notification warning only for okta auth method after submit', async function (assert) {
await visit('/vault/auth');
await component.selectMethod('token');
await click('[data-test-auth-submit]');
assert
.dom('[data-test-auth-message="push"]')
.doesNotExist('message is not shown for other authentication methods');
await component.selectMethod('okta');
await click('[data-test-auth-submit]');
assert.dom('[data-test-auth-message="push"]').exists('shows push notification message');
});
});