-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI - support redirecting to an intended URL after authentication (#7088)
* add redirect_to query param * alias auth controller state to vault controller where the query param is defined * capture the current url before redirecting a user to auth if they're being redirected * consume and reset the redirectTo query param when authenticating * make sure that the current url when logging out does not get set as the redirect_to query param * add unit tests for the mixin and make it so that redirects from the root don't end up in redirect_to * acceptance tests for redirect
- Loading branch information
Showing
7 changed files
with
114 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { currentURL, visit } from '@ember/test-helpers'; | ||
import { module, test } from 'qunit'; | ||
import { setupApplicationTest } from 'ember-qunit'; | ||
import authPage from 'vault/tests/pages/auth'; | ||
|
||
module('Acceptance | redirect_to functionality', function(hooks) { | ||
setupApplicationTest(hooks); | ||
|
||
test('redirect to a route after authentication', async function(assert) { | ||
let url = '/vault/secrets/secret/create'; | ||
await visit(url); | ||
assert.equal( | ||
currentURL(), | ||
`/vault/auth?redirect_to=${encodeURIComponent(url)}&with=token`, | ||
'encodes url for the query param' | ||
); | ||
// the login method on this page does another visit call that we don't want here | ||
await authPage.tokenInput('root').submit(); | ||
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.equal(currentURL(), `/vault/auth?with=token`, '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.equal( | ||
currentURL(), | ||
`/vault/auth?redirect_to=${encodeURIComponent(url)}&with=token`, | ||
'encodes url for the query param' | ||
); | ||
await authPage.tokenInput('root').submit(); | ||
assert.equal(currentURL(), url, 'navigates to the redirect_to with the query param after auth'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters