Skip to content

Commit e308af1

Browse files
MarcialRosalesmergify[bot]
authored andcommitted
Test adding vhost
(cherry picked from commit 01ca72e)
1 parent a043f00 commit e308af1

File tree

6 files changed

+194
-10
lines changed

6 files changed

+194
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<h1>Virtual Hosts</h1>
22

3-
<div class="section">
3+
<div class="section" id="vhosts">
44
<h2>All virtual hosts</h2>
55
<div class="hider">
66
<%= filter_ui(vhosts) %>
77
<div class="updatable">
88
<% if (vhosts.length > 0) { %>
9-
<table class="list">
9+
<table class="list" >
1010
<thead>
1111
<tr>
1212
<%= group_heading('vhosts', 'Overview', [true, true, true]) %>

selenium/.node-xmlhttprequest-sync-88011

Whitespace-only changes.

selenium/test/mgt-api.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest
2+
const {log, error} = require('./utils.js')
3+
4+
const baseUrl = randomly_pick_baseurl(process.env.RABBITMQ_URL || 'http://localhost:15672/')
5+
const otherBaseUrl = randomly_pick_baseurl(process.env.OTHER_RABBITMQ_URL || 'http://localhost:15675/')
6+
const hostname = process.env.RABBITMQ_HOSTNAME || 'localhost'
7+
const otherHostname = process.env.OTHER_RABBITMQ_HOSTNAME || 'localhost'
8+
9+
function randomly_pick_baseurl (baseUrl) {
10+
urls = baseUrl.split(",")
11+
return urls[getRandomInt(urls.length)]
12+
}
13+
function getRandomInt(max) {
14+
return Math.floor(Math.random() * max)
15+
}
16+
17+
module.exports = {
18+
19+
getManagementUrl: () => {
20+
return baseUrl
21+
},
22+
23+
geOtherManagementUrl: () => {
24+
return otherBaseUrl
25+
},
26+
27+
setPolicy: (url, vhost, name, pattern, definition, appliedTo = "queues") => {
28+
let policy = {
29+
"pattern": pattern,
30+
"apply-to": appliedTo,
31+
"definition": definition
32+
}
33+
log("Setting policy " + JSON.stringify(policy)
34+
+ " with name " + name + " for vhost " + vhost + " on "+ url)
35+
const req = new XMLHttpRequest()
36+
let base64Credentials = btoa('administrator-only' + ":" + 'guest')
37+
let finalUrl = url + "/api/policies/" + encodeURIComponent(vhost) + "/" +
38+
encodeURIComponent(name)
39+
req.open('PUT', finalUrl, false)
40+
req.setRequestHeader("Authorization", "Basic " + base64Credentials)
41+
req.setRequestHeader('Content-Type', 'application/json')
42+
43+
req.send(JSON.stringify(policy))
44+
if (req.status == 200 || req.status == 204 || req.status == 201) {
45+
log("Succesfully set policy " + name)
46+
return
47+
}else {
48+
error("status:" + req.status + " : " + req.responseText)
49+
throw new Error(req.responseText)
50+
}
51+
},
52+
deletePolicy: (url, vhost, name) => {
53+
log("Deleting policy " + name + " on vhost " + vhost)
54+
const req = new XMLHttpRequest()
55+
let base64Credentials = btoa('administrator-only' + ":" + 'guest')
56+
let finalUrl = url + "/api/policies/" + encodeURIComponent(vhost) + "/" +
57+
encodeURIComponent(name)
58+
req.open('DELETE', finalUrl, false)
59+
req.setRequestHeader("Authorization", "Basic " + base64Credentials)
60+
61+
req.send()
62+
if (req.status == 200 || req.status == 204) {
63+
log("Succesfully deleted policy " + name)
64+
return
65+
}else {
66+
error("status:" + req.status + " : " + req.responseText)
67+
throw new Error(req.responseText)
68+
}
69+
},
70+
createVhost: (url, name, description = "", tags = []) => {
71+
let vhost = {
72+
"description": description,
73+
"tags": tags
74+
}
75+
log("Create vhost " + JSON.stringify(vhost)
76+
+ " with name " + name + " on " + url)
77+
const req = new XMLHttpRequest()
78+
let base64Credentials = btoa('administrator-only' + ":" + 'guest')
79+
let finalUrl = url + "/api/vhosts/" + encodeURIComponent(name)
80+
req.open('PUT', finalUrl, false)
81+
req.setRequestHeader("Authorization", "Basic " + base64Credentials)
82+
req.setRequestHeader('Content-Type', 'application/json')
83+
84+
req.send(JSON.stringify(vhost))
85+
if (req.status == 200 || req.status == 204 || req.status == 201) {
86+
log("Succesfully created vhost " + name)
87+
return
88+
}else {
89+
error("status:" + req.status + " : " + req.responseText)
90+
throw new Error(req.responseText)
91+
}
92+
},
93+
deleteVhost: (url, vhost) => {
94+
log("Deleting vhost " + vhost)
95+
const req = new XMLHttpRequest()
96+
let base64Credentials = btoa('administrator-only' + ":" + 'guest')
97+
let finalUrl = url + "/api/vhosts/" + encodeURIComponent(vhost)
98+
req.open('DELETE', finalUrl, false)
99+
req.setRequestHeader("Authorization", "Basic " + base64Credentials)
100+
101+
req.send()
102+
if (req.status == 200 || req.status == 204) {
103+
log("Succesfully deleted vhost " + vhost)
104+
return
105+
}else {
106+
error("status:" + req.status + " : " + req.responseText)
107+
throw new Error(req.responseText)
108+
}
109+
}
110+
111+
112+
}

selenium/test/pageobjects/VhostsAdminTab.js

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

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

5+
const MAIN_SECTION = By.css('div#main div#vhosts.section')
6+
57
const SELECTED_VHOSTS_ON_RHM = By.css('div#rhs ul li a[href="#/vhosts"]')
68
const FILTER_VHOST = By.css('div#main div.filter input#filter')
79
const CHECKBOX_REGEX = By.css('div#main div.filter input#filter-regex-mode')
810

911
const VHOSTS_TABLE_ROWS = By.css('div#main table.list tbody tr')
12+
const TABLE_SECTION = By.css('div#main table.list')
1013

1114
module.exports = class VhostsAdminTab extends AdminTab {
1215
async isLoaded () {
13-
await this.waitForDisplayed(SELECTED_VHOSTS_ON_RHM)
16+
await this.waitForDisplayed(MAIN_SECTION)
1417
}
1518
async searchForVhosts(vhost, regex = false) {
1619
await this.sendKeys(FILTER_VHOST, vhost)
@@ -32,5 +35,7 @@ module.exports = class VhostsAdminTab extends AdminTab {
3235
}
3336
throw "Vhost " + vhost + " not found"
3437
}
35-
38+
async getVhostsTable(firstNColumns) {
39+
return this.getTable(TABLE_SECTION, firstNColumns)
40+
}
3641
}

selenium/test/utils.js

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const path = require('path')
55
const { By, Key, until, Builder, logging, Capabilities } = require('selenium-webdriver')
66
const proxy = require('selenium-webdriver/proxy')
77
require('chromedriver')
8+
var chrome = require("selenium-webdriver/chrome");
89
const UAALoginPage = require('./pageobjects/UAALoginPage')
910
const KeycloakLoginPage = require('./pageobjects/KeycloakLoginPage')
1011
const assert = require('assert')
@@ -47,7 +48,9 @@ module.exports = {
4748
log: (message) => {
4849
console.log(new Date() + " " + message)
4950
},
50-
51+
error: (message) => {
52+
console.error(new Date() + " " + message)
53+
},
5154
hasProfile: (profile) => {
5255
return profiles.includes(profile)
5356
},
@@ -58,19 +61,33 @@ module.exports = {
5861
builder = builder.usingServer(seleniumUrl)
5962
}
6063
let chromeCapabilities = Capabilities.chrome();
61-
chromeCapabilities.setAcceptInsecureCerts(true);
64+
const options = new chrome.Options()
65+
chromeCapabilities.setAcceptInsecureCerts(true);
6266
chromeCapabilities.set('goog:chromeOptions', {
67+
excludeSwitches: [ // disable info bar
68+
'enable-automation',
69+
],
70+
prefs: {
71+
'profile.managed_default_content_settings.popups' : 2,
72+
'profile.managed_default_content_settings.notifications' : 2,
73+
},
6374
args: [
75+
"disable-infobars",
76+
"--disable-notifications",
6477
"--lang=en",
6578
"--disable-search-engine-choice-screen",
66-
"--disable-popup-blocking",
79+
"disable-popup-blocking",
6780
"--credentials_enable_service=false",
68-
"--profile.password_manager_enabled=false",
69-
"--profile.password_manager_leak_detection=false"
81+
"profile.password_manager_enabled=false",
82+
"profile.reduce-security-for-testing",
83+
"profile.managed_default_content_settings.popups=1",
84+
"profile.managed_default_content_settings.notifications.popups=1",
85+
"profile.password_manager_leak_detection=false"
7086
]
7187
});
7288
driver = builder
7389
.forBrowser('chrome')
90+
.setChromeOptions(options.excludeSwitches('enable-automation'))
7491
.withCapabilities(chromeCapabilities)
7592
.build()
7693
driver.manage().setTimeouts( { pageLoad: 35000 } )
@@ -111,6 +128,34 @@ module.exports = {
111128
return new CaptureScreenshot(driver, require('path').basename(test))
112129
},
113130

131+
doWhile: async (doCallback, booleanCallback, delayMs = 1000, message = "doWhile failed") => {
132+
let done = false
133+
let attempts = 10
134+
let ret
135+
do {
136+
try {
137+
console.log("Calling doCallback (attempts:" + attempts + ") ... ")
138+
ret = await doCallback()
139+
console.log("Calling booleanCallback (attempts:" + attempts + ") with arg " + ret + " ... ")
140+
done = booleanCallback(ret)
141+
}catch(error) {
142+
console.log("Caught " + error + " on doWhile callback...")
143+
144+
}finally {
145+
if (!done) {
146+
console.log("Waiting until next attempt")
147+
await module.exports.delay(delayMs)
148+
}
149+
}
150+
attempts--
151+
} while (attempts > 0 && !done)
152+
if (!done) {
153+
throw new Error(message)
154+
}else {
155+
return ret
156+
}
157+
},
158+
114159
idpLoginPage: (driver, preferredIdp) => {
115160
if (!preferredIdp) {
116161
if (process.env.PROFILES.includes("uaa")) {

selenium/test/vhosts/admin-vhosts.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const { By, Key, until, Builder } = require('selenium-webdriver')
22
require('chromedriver')
33
const assert = require('assert')
4-
const { buildDriver, goToHome, captureScreensFor, teardown, delay } = require('../utils')
4+
const { buildDriver, goToHome, captureScreensFor, teardown, doWhile, log } = require('../utils')
5+
const { getManagementUrl, createVhost, deleteVhost } = require('../mgt-api')
56

67
const LoginPage = require('../pageobjects/LoginPage')
78
const OverviewPage = require('../pageobjects/OverviewPage')
@@ -46,6 +47,27 @@ describe('Virtual Hosts in Admin tab', function () {
4647
assert.equal("/", await vhostTab.getName())
4748
})
4849

50+
describe('given there is a new virtualhost with a tag', async function() {
51+
let vhost = "test_" + Math.floor(Math.random() * 1000)
52+
before(async function() {
53+
createVhost(getManagementUrl(), vhost, "selenium", "selenium-tag")
54+
await overview.clickOnAdminTab()
55+
await adminTab.clickOnVhosts()
56+
})
57+
it('vhost is listed', async function () {
58+
await vhostsTab.searchForVhosts(vhost)
59+
let vhostTable = await doWhile(async function() {
60+
return vhostsTab.getVhostsTable()
61+
}, function(table) {
62+
return table.length > 0 && vhost.localeCompare(table[0][0])
63+
})
64+
log("vhostTable: " + vhostTable)
65+
})
66+
after(async function () {
67+
deleteVhost(getManagementUrl(), vhost)
68+
})
69+
70+
})
4971

5072
after(async function () {
5173
await teardown(driver, this, captureScreen)

0 commit comments

Comments
 (0)