Skip to content

Commit a864cfe

Browse files
Merge pull request #7144 from rabbitmq/fix-7142
Fix issue #7142
2 parents caa65ec + 166faa3 commit a864cfe

File tree

8 files changed

+195
-8
lines changed

8 files changed

+195
-8
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1>Limits</h1>
22

3-
<div class="section">
3+
<div class="section" id="virtual-host-limits">
44
<h2>Virtual host Limits</h2>
55
<div class="hider">
66
<div class="updatable">
@@ -49,7 +49,7 @@
4949
</div>
5050
</div>
5151

52-
<div class="section administrator-only">
52+
<div class="section administrator-only" id="set-virtual-host-limits">
5353
<h2>Set / update a virtual host limit</h2>
5454
<div class="hider">
5555
<form action="#/limits" method="put">
@@ -88,7 +88,7 @@
8888
</div>
8989
</div>
9090

91-
<div class="section">
91+
<div class="section" id="user-limits">
9292
<h2>User Limits</h2>
9393
<div class="hider">
9494
<div class="updatable">
@@ -137,7 +137,7 @@
137137
</div>
138138
</div>
139139

140-
<div class="section administrator-only">
140+
<div class="section administrator-only" id="set-user-limits">
141141
<h2>Set / update a user limit</h2>
142142
<div class="hider">
143143
<form action="#/user-limits" method="put">
@@ -146,9 +146,9 @@
146146
<th><label>User:</label></th>
147147
<td>
148148
<select name="user">
149-
<% for (var i = 0; i < users.items.length; i++) { %>
150-
<option value="<%= fmt_string(users.items[i].name) %>">
151-
<%= fmt_string(users.items[i].name) %>
149+
<% for (var i = 0; i < users.length; i++) { %>
150+
<option value="<%= fmt_string(users[i].name) %>">
151+
<%= fmt_string(users[i].name) %>
152152
</option>
153153
<% } %>
154154
</select>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
# Name of the suite used to generate log and screen folders
6+
SUITE=$( basename "${BASH_SOURCE[0]}" .sh)
7+
8+
# Path to the test cases this suite should run. It is relative to the selenium/test folder
9+
TEST_CASES_PATH=/limits
10+
# Path to the folder where all configuration file reside. It is relative to the selenim/test folder
11+
TEST_CONFIG_PATH=/basic-auth
12+
13+
source $SCRIPT/suite_template
14+
15+
_setup () {
16+
start_rabbitmq
17+
}
18+
_save_logs() {
19+
save_container_logs rabbitmq
20+
}
21+
_teardown() {
22+
kill_container_if_exist rabbitmq
23+
}
24+
run

deps/rabbitmq_management/selenium/test/definitions/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@ RABBITMQ_SERVER_ROOT = ../../../../../
1010
help:
1111
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
1212

13+
start-rabbitmq: ## Start RabbitMQ
14+
@(docker kill rabbitmq >/dev/null 2>&1 && docker rm rabbitmq)
15+
@(gmake --directory=${RABBITMQ_SERVER_ROOT} run-broker \
16+
RABBITMQ_ENABLED_PLUGINS="rabbitmq_management" \
17+
RABBITMQ_CONFIG_FILE=deps/rabbitmq_management/selenium/test/basic-auth/rabbitmq.config)
18+
1319
test: ## Run tests interactively e.g. make test [TEST=landing.js]
1420
@(RABBITMQ_URL=http://localhost:15672 RUN_LOCAL=true SCREENSHOTS_DIR=${PWD}/../../screens npm test $(PWD)/$(TEST))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.ONESHELL:# single shell invocation for all lines in the recipe
2+
SHELL = bash# we depend on bash expansion for e.g. queue patterns
3+
4+
.DEFAULT_GOAL = help
5+
RABBITMQ_SERVER_ROOT = ../../../../../
6+
7+
8+
### TARGETS ###
9+
10+
help:
11+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
12+
13+
start-rabbitmq: ## Start RabbitMQ
14+
@(docker kill rabbitmq >/dev/null 2>&1 && docker rm rabbitmq)
15+
@(gmake --directory=${RABBITMQ_SERVER_ROOT} run-broker \
16+
RABBITMQ_ENABLED_PLUGINS="rabbitmq_management" \
17+
RABBITMQ_CONFIG_FILE=deps/rabbitmq_management/selenium/test/basic-auth/rabbitmq.config)
18+
19+
test: ## Run tests interactively e.g. make test [TEST=landing.js]
20+
@(RABBITMQ_URL=http://localhost:15672 RUN_LOCAL=true SCREENSHOTS_DIR=${PWD}/../../screens npm test $(PWD)/$(TEST))
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
const AdminTab = require('../pageobjects/AdminTab')
9+
const LimitsAdminTab = require('../pageobjects/LimitsAdminTab')
10+
11+
describe('user_limits', function () {
12+
let login
13+
let overview
14+
let captureScreen
15+
16+
before(async function () {
17+
driver = buildDriver()
18+
await goToHome(driver)
19+
login = new LoginPage(driver)
20+
overview = new OverviewPage(driver)
21+
adminTab = new AdminTab(driver)
22+
limitsSection = new LimitsAdminTab(driver)
23+
captureScreen = captureScreensFor(driver, __filename)
24+
25+
await login.login('guest', 'guest')
26+
if (!await overview.isLoaded()) {
27+
throw new Error('Failed to login')
28+
}
29+
30+
})
31+
32+
it('when there are no limits', async function () {
33+
await overview.clickOnAdminTab()
34+
await adminTab.clickOnLimits()
35+
assert.equal(0, (await limitsSection.list_user_limits()).length)
36+
})
37+
38+
39+
after(async function () {
40+
await teardown(driver, this, captureScreen)
41+
})
42+
})
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, goToHome, captureScreensFor, teardown, delay } = require('../utils')
5+
6+
const LoginPage = require('../pageobjects/LoginPage')
7+
const OverviewPage = require('../pageobjects/OverviewPage')
8+
const AdminTab = require('../pageobjects/AdminTab')
9+
const LimitsAdminTab = require('../pageobjects/LimitsAdminTab')
10+
11+
describe('virtual_host_limits', function () {
12+
let login
13+
let overview
14+
let captureScreen
15+
16+
before(async function () {
17+
driver = buildDriver()
18+
await goToHome(driver)
19+
login = new LoginPage(driver)
20+
overview = new OverviewPage(driver)
21+
adminTab = new AdminTab(driver)
22+
limitsSection = new LimitsAdminTab(driver)
23+
captureScreen = captureScreensFor(driver, __filename)
24+
25+
await login.login('guest', 'guest')
26+
if (!await overview.isLoaded()) {
27+
throw new Error('Failed to login')
28+
}
29+
30+
})
31+
32+
it('when there are no limits', async function () {
33+
await overview.clickOnAdminTab()
34+
await adminTab.clickOnLimits()
35+
assert.equal(0, (await limitsSection.list_virtual_host_limits()).length)
36+
37+
})
38+
39+
40+
after(async function () {
41+
await teardown(driver, this, captureScreen)
42+
})
43+
})

deps/rabbitmq_management/selenium/test/pageobjects/AdminTab.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,28 @@ const { By, Key, until, Builder } = require('selenium-webdriver')
22

33
const OverviewPage = require('./OverviewPage')
44

5+
const SELECTED_ADMIN_TAB = By.css('div#menu ul#tabs li a.selected[href="#/users"]')
6+
57
const ALL_USERS_SECTION = By.css('div#users-section')
68
const USER_LINK = By.css('div#menu ul#tabs li a[href="#/connections"]')
9+
710
const FILTER_USER = By.css('input#users-name')
811
const CHECKBOX_REGEX = By.css('input#filter-regex-mode')
912
const FILTERED_USER = By.css('span.filter-highlight')
1013

14+
// RHM : RIGHT HAND MENU
15+
const USERS_ON_RHM = By.css('div#rhs ul li a[href="#/users"]')
16+
const LIMITS_ON_RHM = By.css('div#rhs ul li a[href="#/limits"]')
17+
1118
module.exports = class AdminTab extends OverviewPage {
1219
async isLoaded () {
13-
await this.waitForDisplayed(ADMIN_TAB)
20+
await this.waitForDisplayed(SELECTED_ADMIN_TAB)
21+
}
22+
async clickOnUsers() {
23+
await this.click(USERS_ON_RHM)
24+
}
25+
async clickOnLimits() {
26+
await this.click(LIMITS_ON_RHM)
1427
}
1528

1629
async searchForUser(user, regex = false) {
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+
3+
const AdminTab = require('./AdminTab')
4+
5+
const SELECTED_LIMITS_ON_RHM = By.css('div#rhs ul li a[href="#/limits"]')
6+
7+
const VIRTUAL_HOST_LIMITS_SECTION = By.css('div#main div#virtual-host-limits')
8+
const USER_LIMITS_SECTION = By.css('div#main div#user-limits')
9+
10+
const VIRTUAL_HOST_LIMITS_TABLE_ROWS = By.css('div#main div#virtual-host-limits table.list tbody tr')
11+
const USER_LIMITS_TABLE_ROWS = By.css('div#main div#user-limits table.list tbody tr')
12+
13+
module.exports = class LimitsAdminTab extends AdminTab {
14+
async isLoaded () {
15+
await this.waitForDisplayed(SELECTED_LIMITS_ON_RHM)
16+
}
17+
18+
async list_virtual_host_limits() {
19+
await this.click(VIRTUAL_HOST_LIMITS_SECTION)
20+
try
21+
{
22+
rows = driver.findElements(VIRTUAL_HOST_LIMITS_TABLE_ROWS)
23+
return rows
24+
} catch (NoSuchElement) {
25+
return Promise.resolve([])
26+
}
27+
}
28+
async list_user_limits() {
29+
await this.click(USER_LIMITS_SECTION)
30+
try
31+
{
32+
rows = driver.findElements(VIRTUAL_HOST_LIMITS_TABLE_ROWS)
33+
return rows
34+
} catch (NoSuchElement) {
35+
return Promise.resolve([])
36+
}
37+
}
38+
39+
}

0 commit comments

Comments
 (0)