Skip to content

Commit 3d8945f

Browse files
Merge pull request #9820 from dukex/improve-login-exp
Redirect user back to landing page
2 parents d09c0e6 + 9c87e19 commit 3d8945f

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed

deps/rabbitmq_management/priv/www/js/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ function startWithLoginPage() {
1919
start_app_login();
2020
}
2121
function startWithOAuthLogin () {
22+
store_pref("oauth-return-to", window.location.hash);
23+
2224
if (!oauth.logged_in) {
2325
if (oauth.sp_initiated) {
2426
get(oauth.readiness_url, 'application/json', function (req) {

deps/rabbitmq_management/priv/www/js/oidc-oauth/helper.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,13 @@ function oauth_initiateLogin() {
148148
function oauth_redirectToHome(oauth) {
149149
console.log("oauth_redirectToHome set_token_auth")
150150
set_token_auth(oauth.access_token)
151-
go_to_home()
151+
152+
path = get_pref("oauth-return-to");
153+
clear_pref("oauth-return-to")
154+
go_to(path)
152155
}
153-
function go_to_home() {
154-
location.href = rabbit_path_prefix() + "/"
156+
function go_to(path) {
157+
location.href = rabbit_path_prefix() + "/" + path
155158
}
156159
function go_to_authority() {
157160
location.href = oauth.authority

deps/rabbitmq_management/priv/www/js/prefs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ function default_pref(k) {
185185
if (k.substring(0, 11) == 'chart-line-') return 'true';
186186
if (k == 'truncate') return '100';
187187
if (k == 'chart-range') return '60|5';
188+
if (k == 'oauth-return-to') return '';
188189
if (k.substring(0, 7) == 'column-')
189190
return default_column_pref(k.substring(7));
190191
return null;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const { By, Key, until, Builder } = require('selenium-webdriver')
2+
require('chromedriver')
3+
const assert = require('assert')
4+
const { buildDriver, goToExchanges, captureScreensFor, teardown, goToHome } = require('../../utils')
5+
6+
const SSOHomePage = require('../../pageobjects/SSOHomePage')
7+
const UAALoginPage = require('../../pageobjects/UAALoginPage')
8+
const ExchangesPage = require('../../pageobjects/ExchangesPage')
9+
10+
describe('A user which accesses a protected URL without a session', function () {
11+
let homePage
12+
let uaaLogin
13+
let exchanges
14+
let captureScreen
15+
16+
before(async function () {
17+
driver = buildDriver()
18+
homePage = new SSOHomePage(driver)
19+
uaaLogin = new UAALoginPage(driver)
20+
exchanges = new ExchangesPage(driver)
21+
22+
await goToExchanges(driver)
23+
24+
captureScreen = captureScreensFor(driver, __filename)
25+
})
26+
27+
it('redirect to previous accessed page after login ', async function () {
28+
await homePage.clickToLogin()
29+
30+
await uaaLogin.login('rabbit_admin', 'rabbit_admin')
31+
32+
if (!await exchanges.isLoaded()) {
33+
throw new Error('Failed to login')
34+
}
35+
36+
assert.equal("All exchanges (8)", await exchanges.getPagingSectionHeaderText())
37+
})
38+
39+
40+
after(async function () {
41+
await teardown(driver, this, captureScreen)
42+
})
43+
})

deps/rabbitmq_management/selenium/test/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { By, Key, until, Builder, logging } = require('selenium-webdriver')
66
require('chromedriver')
77

88
const uaaUrl = process.env.UAA_URL || 'http://localhost:8080'
9-
const baseUrl = process.env.RABBITMQ_URL || 'http://localhost:15672'
9+
const baseUrl = process.env.RABBITMQ_URL || 'http://localhost:15672/'
1010
const hostname = process.env.RABBITMQ_HOSTNAME || 'localhost'
1111
const runLocal = String(process.env.RUN_LOCAL).toLowerCase() != 'false'
1212
const seleniumUrl = process.env.SELENIUM_URL || 'http://selenium:4444'
@@ -59,7 +59,11 @@ module.exports = {
5959
},
6060

6161
goToLogin: (driver, token) => {
62-
return driver.get(baseUrl + '/#/login?access_token=' + token)
62+
return driver.get(baseUrl + '#/login?access_token=' + token)
63+
},
64+
65+
goToExchanges: (driver) => {
66+
return driver.get(baseUrl + '#/exchanges')
6367
},
6468

6569
goTo: (driver, address) => {

0 commit comments

Comments
 (0)