open-vault/ui/tests/acceptance/redirect-to-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

96 lines
3.3 KiB
JavaScript

import { currentURL, visit as _visit, settled } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
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 visit = async (url) => {
try {
await _visit(url);
} catch (e) {
if (e.message !== 'TransitionAborted') {
throw e;
}
}
await settled();
};
const consoleComponent = create(consoleClass);
const wrappedAuth = async () => {
await consoleComponent.runCommands(`write -field=token auth/token/create policies=default -wrap-ttl=5m`);
await settled();
// because of flaky test, trying to capture the token using a dom selector instead of the page object
let token = document.querySelector('[data-test-component="console/log-text"] pre').textContent;
if (token.includes('Error')) {
throw new Error(`Error mounting secrets engine: ${token}`);
}
return token;
};
const setupWrapping = async () => {
await auth.logout();
await settled();
await auth.visit();
await settled();
await auth.tokenInput('root').submit();
await settled();
let wrappedToken = await wrappedAuth();
return wrappedToken;
};
module('Acceptance | redirect_to query param functionality', function (hooks) {
setupApplicationTest(hooks);
hooks.beforeEach(function () {
// normally we'd use the auth.logout helper to visit the route and reset the app, but in this case that
// also routes us to the auth page, and then all of the transitions from the auth page get redirected back
// to the auth page resulting in no redirect_to query param being set
localStorage.clear();
});
test('redirect to a route after authentication', async function (assert) {
let url = '/vault/secrets/secret/create';
await visit(url);
assert.ok(
currentURL().includes(`redirect_to=${encodeURIComponent(url)}`),
'encodes url for the query param'
);
// the login method on this page does another visit call that we don't want here
await auth.tokenInput('root').submit();
await settled();
assert.equal(currentURL(), url, 'navigates to the redirect_to url after auth');
});
test('redirect from root does not include redirect_to', async function (assert) {
let url = '/';
await visit(url);
assert.ok(currentURL().indexOf('redirect_to') < 0, 'there is no redirect_to query param');
});
test('redirect to a route after authentication with a query param', async function (assert) {
let url = '/vault/secrets/secret/create?initialKey=hello';
await visit(url);
assert.ok(
currentURL().includes(`?redirect_to=${encodeURIComponent(url)}`),
'encodes url for the query param'
);
await auth.tokenInput('root').submit();
await settled();
assert.equal(currentURL(), url, 'navigates to the redirect_to with the query param after auth');
});
test('redirect to logout with wrapped token authenticates you', async function (assert) {
let wrappedToken = await setupWrapping();
let url = '/vault/secrets/cubbyhole/create';
await auth.logout({
redirect_to: url,
wrapped_token: wrappedToken,
});
await settled();
assert.equal(currentURL(), url, 'authenticates then navigates to the redirect_to url after auth');
});
});