Skip to content

Commit 38b9999

Browse files
Always honor login timeout when setting cookie expiry
1 parent eb8d126 commit 38b9999

5 files changed

Lines changed: 66 additions & 5 deletions

File tree

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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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', function () {
10+
let driver
11+
let overview
12+
let captureScreen
13+
this.timeout(65000) // hard-coded to 25secs because this test requires 35sec to run
14+
15+
before(async function () {
16+
driver = buildDriver()
17+
await goToHome(driver)
18+
login = new LoginPage(driver)
19+
overview = new OverviewPage(driver)
20+
captureScreen = captureScreensFor(driver, __filename)
21+
await login.login('guest', 'guest')
22+
await overview.isLoaded()
23+
await overview.selectRefreshOption("Do not refresh")
24+
await overview.ensureTotalsSectionIsInvisible() // trigger a preference stored in cookie
25+
// which should honor login timeout
26+
})
27+
28+
it('it has to login after the session expires', async function () {
29+
30+
await delay(60000)
31+
await overview.clickOnConnectionsTab()
32+
await login.isLoaded()
33+
34+
})
35+
36+
after(async function () {
37+
await teardown(driver, this, captureScreen)
38+
})
39+
})

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ describe('Once user is logged in', function () {
1919
overview = new OverviewPage(driver)
2020
captureScreen = captureScreensFor(driver, __filename)
2121
await login.login('guest', 'guest')
22-
await overview.isLoaded()
23-
22+
await overview.isLoaded()
23+
await overview.ensureTotalsSectionIsInvisible() // trigger a preference stored in cookie
24+
// which should honor login timeout
25+
2426
})
2527

2628
it('it has to login after the session expires', async function () {
2729

2830
await delay(60000)
2931
await login.isLoaded()
3032
await login.login('guest', 'guest')
31-
await overview.isLoaded()
33+
await overview.isLoaded()
3234
await overview.clickOnConnectionsTab() // and we can still interact with the ui
3335
})
3436

selenium/test/pageobjects/BasePage.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,24 @@ 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'))
4041
} else {
4142
return Promise.resolve(true)
4243
}
4344
}
45+
async ensureSectionIsInvisible(section) {
46+
let classes = await this.driver.findElement(section).getAttribute("class")
47+
if (classes.search('section-invisible') < 0) {
48+
return this.click(By.css(section.value + ' h2'))
49+
} else {
50+
51+
return Promise.resolve(true)
52+
}
53+
}
4454
async goTo(path) {
4555
return driver.get(d.baseUrl + path)
4656
}

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+
async ensureTotalsSectionIsInvisible() {
37+
return this.ensureSectionIsInvisible(TOTALS_SECTION)
38+
}
39+
3040
}

0 commit comments

Comments
 (0)