open-vault/ui/tests/acceptance/wrapped-token-test.js
Matthew Irish 8d9d8e3d0e
UI wrapped token fix (#7398)
* default to token auth method

* pass in selectedValue to the AuthForm

* adjust when and if tasks are called so there's no race condition with wrapped_token query param

* add some tests for wrapped_token

* adjust redirect_to behavior so that it also works with the logout route and the wrapped_token query param

* fix linting
2019-10-01 15:30:56 -05:00

38 lines
1.4 KiB
JavaScript

import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { currentURL } from '@ember/test-helpers';
import { create } from 'ember-cli-page-object';
import auth from 'vault/tests/pages/auth';
import consoleClass from 'vault/tests/pages/components/console/ui-panel';
const consoleComponent = create(consoleClass);
const wrappedAuth = async () => {
await consoleComponent.runCommands(`write -field=token auth/token/create policies=default -wrap-ttl=3m`);
return consoleComponent.lastLogOutput;
};
const setupWrapping = async () => {
await auth.logout();
await auth.visit();
await auth.tokenInput('root').submit();
let token = await wrappedAuth();
await auth.logout();
return token;
};
module('Acceptance | wrapped_token query param functionality', function(hooks) {
setupApplicationTest(hooks);
test('it authenticates you if the query param is present', async function(assert) {
let token = await setupWrapping();
await auth.visit({ wrapped_token: token });
assert.equal(currentURL(), '/vault/secrets', 'authenticates and redirects to home');
});
test('it authenticates when used with the with=token query param', async function(assert) {
let token = await setupWrapping();
await auth.visit({ wrapped_token: token, with: 'token' });
assert.equal(currentURL(), '/vault/secrets', 'authenticates and redirects to home');
});
});