Skip to content

Commit 9134d0e

Browse files
Merge pull request #15823 from rabbitmq/mergify/bp/v4.3.x/pr-15814
rabbitmq_management: Fix preference cookie expiry to respect session timeout (backport #15814)
2 parents fc88e3f + 1e0bfd9 commit 9134d0e

6 files changed

Lines changed: 72 additions & 8 deletions

File tree

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,14 @@ function parse_cookie() {
235235
}
236236

237237
function store_cookie(dict) {
238-
var date = new Date();
239-
date.setFullYear(date.getFullYear() + 1);
238+
var sessionTimeout = dict[short_key(LOGIN_SESSION_TIMEOUT)];
239+
var date;
240+
if (sessionTimeout != undefined) {
241+
date = new Date();
242+
date.setMinutes(date.getMinutes() + parseInt(sessionTimeout, 10));
243+
} else {
244+
date = default_hard_session_timeout();
245+
}
240246
store_cookie_with_expiration(dict, date);
241247
}
242248

deps/rabbitmq_management/priv/www/js/tmpl/overview.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<% }}} %>
3333
</div>
3434

35-
<div class="section">
35+
<div class="section" id="totals-section">
3636
<h2>Totals</h2>
3737
<div class="hider updatable">
3838
<% if(!disable_stats) { %>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const { By, Key, until, Builder } = require('selenium-webdriver')
2+
require('chromedriver')
3+
const assert = require('assert')
4+
const { buildDriver, goToHome, captureScreensFor, teardown, delay } = require('../utils')
5+
6+
const LoginPage = require('../pageobjects/LoginPage')
7+
const OverviewPage = require('../pageobjects/OverviewPage')
8+
9+
describe('Once user is logged in and no refresh is configured', function () {
10+
let driver
11+
let login
12+
let overview
13+
let captureScreen
14+
this.timeout(65000)
15+
16+
before(async function () {
17+
driver = buildDriver()
18+
await goToHome(driver)
19+
login = new LoginPage(driver)
20+
overview = new OverviewPage(driver)
21+
captureScreen = captureScreensFor(driver, __filename)
22+
await login.login('guest', 'guest')
23+
await overview.isLoaded()
24+
await overview.selectRefreshOption("Do not refresh")
25+
// Trigger a UI preference change to verify it does not extend the session.
26+
await overview.ensureTotalsSectionIsInvisible()
27+
})
28+
29+
it('any authorized request after the session has expired should log the user out', async function () {
30+
await delay(60000)
31+
await overview.clickOnConnectionsTab()
32+
await login.isLoaded()
33+
})
34+
35+
after(async function () {
36+
await teardown(driver, this, captureScreen)
37+
})
38+
})

selenium/test/basic-auth/session-expired.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ describe('Once user is logged in', function () {
2020
captureScreen = captureScreensFor(driver, __filename)
2121
await login.login('guest', 'guest')
2222
await overview.isLoaded()
23-
23+
// Trigger a UI preference change to verify it does not extend the session.
24+
await overview.ensureTotalsSectionIsInvisible()
2425
})
2526

2627
it('it has to login after the session expires', async function () {
27-
2828
await delay(60000)
29-
await login.isLoaded()
29+
await login.isLoaded()
3030
await login.login('guest', 'guest')
31-
await overview.isLoaded()
31+
await overview.isLoaded()
3232
await overview.clickOnConnectionsTab() // and we can still interact with the ui
3333
})
3434

selenium/test/pageobjects/BasePage.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,20 @@ module.exports = class BasePage {
3333
this.polling = parseInt(process.env.SELENIUM_POLLING) || 500 // how frequent selenium searches for an element
3434
this.interactionDelay = parseInt(process.env.SELENIUM_INTERACTION_DELAY) || 0 // slow down interactions (when rabbit is behind a http proxy)
3535
}
36+
3637
async ensureSectionIsVisible(section) {
3738
let classes = await this.driver.findElement(section).getAttribute("class")
3839
if (classes.search('section-visible') < 0) {
39-
return this.click(section)
40+
return this.click(By.css(section.value + ' h2'))
41+
} else {
42+
return Promise.resolve(true)
43+
}
44+
}
45+
46+
async ensureSectionIsInvisible(section) {
47+
let classes = await this.driver.findElement(section).getAttribute("class")
48+
if (classes.search('section-invisible') < 0) {
49+
return this.click(By.css(section.value + ' h2'))
4050
} else {
4151
return Promise.resolve(true)
4252
}

selenium/test/pageobjects/OverviewPage.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const DOWNLOAD_DEFINITIONS_SECTION = By.css('div#download-definitions-section')
1212
const CHOOSE_BROKER_DOWNLOAD_FILE = By.css('input#download-filename')
1313
const DOWNLOAD_BROKER_FILE = By.css('button#upload-definitions')
1414

15+
const TOTALS_SECTION = By.css('div#main div#totals-section')
16+
1517
module.exports = class OverviewPage extends BasePage {
1618

1719
async uploadBrokerDefinitions(file) {
@@ -27,4 +29,12 @@ module.exports = class OverviewPage extends BasePage {
2729
async downloadBrokerDefinitions(filename) {
2830
return this.click(DOWNLOAD_DEFINITIONS_SECTION)
2931
}
32+
33+
async ensureTotalsSectionIsVisible() {
34+
return this.ensureSectionIsVisible(TOTALS_SECTION)
35+
}
36+
37+
async ensureTotalsSectionIsInvisible() {
38+
return this.ensureSectionIsInvisible(TOTALS_SECTION)
39+
}
3040
}

0 commit comments

Comments
 (0)