Test adding vhost
This commit is contained in:
parent
467601a62d
commit
01ca72edc0
|
@ -1,12 +1,12 @@
|
|||
<h1>Virtual Hosts</h1>
|
||||
|
||||
<div class="section">
|
||||
<div class="section" id="vhosts">
|
||||
<h2>All virtual hosts</h2>
|
||||
<div class="hider">
|
||||
<%= filter_ui(vhosts) %>
|
||||
<div class="updatable">
|
||||
<% if (vhosts.length > 0) { %>
|
||||
<table class="list">
|
||||
<table class="list" >
|
||||
<thead>
|
||||
<tr>
|
||||
<%= group_heading('vhosts', 'Overview', [true, true, true]) %>
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest
|
||||
const {log, error} = require('./utils.js')
|
||||
|
||||
const baseUrl = randomly_pick_baseurl(process.env.RABBITMQ_URL || 'http://localhost:15672/')
|
||||
const otherBaseUrl = randomly_pick_baseurl(process.env.OTHER_RABBITMQ_URL || 'http://localhost:15675/')
|
||||
const hostname = process.env.RABBITMQ_HOSTNAME || 'localhost'
|
||||
const otherHostname = process.env.OTHER_RABBITMQ_HOSTNAME || 'localhost'
|
||||
|
||||
function randomly_pick_baseurl (baseUrl) {
|
||||
urls = baseUrl.split(",")
|
||||
return urls[getRandomInt(urls.length)]
|
||||
}
|
||||
function getRandomInt(max) {
|
||||
return Math.floor(Math.random() * max)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
getManagementUrl: () => {
|
||||
return baseUrl
|
||||
},
|
||||
|
||||
geOtherManagementUrl: () => {
|
||||
return otherBaseUrl
|
||||
},
|
||||
|
||||
setPolicy: (url, vhost, name, pattern, definition, appliedTo = "queues") => {
|
||||
let policy = {
|
||||
"pattern": pattern,
|
||||
"apply-to": appliedTo,
|
||||
"definition": definition
|
||||
}
|
||||
log("Setting policy " + JSON.stringify(policy)
|
||||
+ " with name " + name + " for vhost " + vhost + " on "+ url)
|
||||
const req = new XMLHttpRequest()
|
||||
let base64Credentials = btoa('administrator-only' + ":" + 'guest')
|
||||
let finalUrl = url + "/api/policies/" + encodeURIComponent(vhost) + "/" +
|
||||
encodeURIComponent(name)
|
||||
req.open('PUT', finalUrl, false)
|
||||
req.setRequestHeader("Authorization", "Basic " + base64Credentials)
|
||||
req.setRequestHeader('Content-Type', 'application/json')
|
||||
|
||||
req.send(JSON.stringify(policy))
|
||||
if (req.status == 200 || req.status == 204 || req.status == 201) {
|
||||
log("Succesfully set policy " + name)
|
||||
return
|
||||
}else {
|
||||
error("status:" + req.status + " : " + req.responseText)
|
||||
throw new Error(req.responseText)
|
||||
}
|
||||
},
|
||||
deletePolicy: (url, vhost, name) => {
|
||||
log("Deleting policy " + name + " on vhost " + vhost)
|
||||
const req = new XMLHttpRequest()
|
||||
let base64Credentials = btoa('administrator-only' + ":" + 'guest')
|
||||
let finalUrl = url + "/api/policies/" + encodeURIComponent(vhost) + "/" +
|
||||
encodeURIComponent(name)
|
||||
req.open('DELETE', finalUrl, false)
|
||||
req.setRequestHeader("Authorization", "Basic " + base64Credentials)
|
||||
|
||||
req.send()
|
||||
if (req.status == 200 || req.status == 204) {
|
||||
log("Succesfully deleted policy " + name)
|
||||
return
|
||||
}else {
|
||||
error("status:" + req.status + " : " + req.responseText)
|
||||
throw new Error(req.responseText)
|
||||
}
|
||||
},
|
||||
createVhost: (url, name, description = "", tags = []) => {
|
||||
let vhost = {
|
||||
"description": description,
|
||||
"tags": tags
|
||||
}
|
||||
log("Create vhost " + JSON.stringify(vhost)
|
||||
+ " with name " + name + " on " + url)
|
||||
const req = new XMLHttpRequest()
|
||||
let base64Credentials = btoa('administrator-only' + ":" + 'guest')
|
||||
let finalUrl = url + "/api/vhosts/" + encodeURIComponent(name)
|
||||
req.open('PUT', finalUrl, false)
|
||||
req.setRequestHeader("Authorization", "Basic " + base64Credentials)
|
||||
req.setRequestHeader('Content-Type', 'application/json')
|
||||
|
||||
req.send(JSON.stringify(vhost))
|
||||
if (req.status == 200 || req.status == 204 || req.status == 201) {
|
||||
log("Succesfully created vhost " + name)
|
||||
return
|
||||
}else {
|
||||
error("status:" + req.status + " : " + req.responseText)
|
||||
throw new Error(req.responseText)
|
||||
}
|
||||
},
|
||||
deleteVhost: (url, vhost) => {
|
||||
log("Deleting vhost " + vhost)
|
||||
const req = new XMLHttpRequest()
|
||||
let base64Credentials = btoa('administrator-only' + ":" + 'guest')
|
||||
let finalUrl = url + "/api/vhosts/" + encodeURIComponent(vhost)
|
||||
req.open('DELETE', finalUrl, false)
|
||||
req.setRequestHeader("Authorization", "Basic " + base64Credentials)
|
||||
|
||||
req.send()
|
||||
if (req.status == 200 || req.status == 204) {
|
||||
log("Succesfully deleted vhost " + vhost)
|
||||
return
|
||||
}else {
|
||||
error("status:" + req.status + " : " + req.responseText)
|
||||
throw new Error(req.responseText)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -2,15 +2,18 @@ const { By, Key, until, Builder } = require('selenium-webdriver')
|
|||
|
||||
const AdminTab = require('./AdminTab')
|
||||
|
||||
const MAIN_SECTION = By.css('div#main div#vhosts.section')
|
||||
|
||||
const SELECTED_VHOSTS_ON_RHM = By.css('div#rhs ul li a[href="#/vhosts"]')
|
||||
const FILTER_VHOST = By.css('div#main div.filter input#filter')
|
||||
const CHECKBOX_REGEX = By.css('div#main div.filter input#filter-regex-mode')
|
||||
|
||||
const VHOSTS_TABLE_ROWS = By.css('div#main table.list tbody tr')
|
||||
const TABLE_SECTION = By.css('div#main table.list')
|
||||
|
||||
module.exports = class VhostsAdminTab extends AdminTab {
|
||||
async isLoaded () {
|
||||
await this.waitForDisplayed(SELECTED_VHOSTS_ON_RHM)
|
||||
await this.waitForDisplayed(MAIN_SECTION)
|
||||
}
|
||||
async searchForVhosts(vhost, regex = false) {
|
||||
await this.sendKeys(FILTER_VHOST, vhost)
|
||||
|
@ -32,5 +35,7 @@ module.exports = class VhostsAdminTab extends AdminTab {
|
|||
}
|
||||
throw "Vhost " + vhost + " not found"
|
||||
}
|
||||
|
||||
async getVhostsTable(firstNColumns) {
|
||||
return this.getTable(TABLE_SECTION, firstNColumns)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ const path = require('path')
|
|||
const { By, Key, until, Builder, logging, Capabilities } = require('selenium-webdriver')
|
||||
const proxy = require('selenium-webdriver/proxy')
|
||||
require('chromedriver')
|
||||
var chrome = require("selenium-webdriver/chrome");
|
||||
const UAALoginPage = require('./pageobjects/UAALoginPage')
|
||||
const KeycloakLoginPage = require('./pageobjects/KeycloakLoginPage')
|
||||
const assert = require('assert')
|
||||
|
@ -47,7 +48,9 @@ module.exports = {
|
|||
log: (message) => {
|
||||
console.log(new Date() + " " + message)
|
||||
},
|
||||
|
||||
error: (message) => {
|
||||
console.error(new Date() + " " + message)
|
||||
},
|
||||
hasProfile: (profile) => {
|
||||
return profiles.includes(profile)
|
||||
},
|
||||
|
@ -58,19 +61,33 @@ module.exports = {
|
|||
builder = builder.usingServer(seleniumUrl)
|
||||
}
|
||||
let chromeCapabilities = Capabilities.chrome();
|
||||
chromeCapabilities.setAcceptInsecureCerts(true);
|
||||
const options = new chrome.Options()
|
||||
chromeCapabilities.setAcceptInsecureCerts(true);
|
||||
chromeCapabilities.set('goog:chromeOptions', {
|
||||
excludeSwitches: [ // disable info bar
|
||||
'enable-automation',
|
||||
],
|
||||
prefs: {
|
||||
'profile.managed_default_content_settings.popups' : 2,
|
||||
'profile.managed_default_content_settings.notifications' : 2,
|
||||
},
|
||||
args: [
|
||||
"disable-infobars",
|
||||
"--disable-notifications",
|
||||
"--lang=en",
|
||||
"--disable-search-engine-choice-screen",
|
||||
"--disable-popup-blocking",
|
||||
"disable-popup-blocking",
|
||||
"--credentials_enable_service=false",
|
||||
"--profile.password_manager_enabled=false",
|
||||
"--profile.password_manager_leak_detection=false"
|
||||
"profile.password_manager_enabled=false",
|
||||
"profile.reduce-security-for-testing",
|
||||
"profile.managed_default_content_settings.popups=1",
|
||||
"profile.managed_default_content_settings.notifications.popups=1",
|
||||
"profile.password_manager_leak_detection=false"
|
||||
]
|
||||
});
|
||||
driver = builder
|
||||
.forBrowser('chrome')
|
||||
.setChromeOptions(options.excludeSwitches('enable-automation'))
|
||||
.withCapabilities(chromeCapabilities)
|
||||
.build()
|
||||
driver.manage().setTimeouts( { pageLoad: 35000 } )
|
||||
|
@ -111,6 +128,34 @@ module.exports = {
|
|||
return new CaptureScreenshot(driver, require('path').basename(test))
|
||||
},
|
||||
|
||||
doWhile: async (doCallback, booleanCallback, delayMs = 1000, message = "doWhile failed") => {
|
||||
let done = false
|
||||
let attempts = 10
|
||||
let ret
|
||||
do {
|
||||
try {
|
||||
console.log("Calling doCallback (attempts:" + attempts + ") ... ")
|
||||
ret = await doCallback()
|
||||
console.log("Calling booleanCallback (attempts:" + attempts + ") with arg " + ret + " ... ")
|
||||
done = booleanCallback(ret)
|
||||
}catch(error) {
|
||||
console.log("Caught " + error + " on doWhile callback...")
|
||||
|
||||
}finally {
|
||||
if (!done) {
|
||||
console.log("Waiting until next attempt")
|
||||
await module.exports.delay(delayMs)
|
||||
}
|
||||
}
|
||||
attempts--
|
||||
} while (attempts > 0 && !done)
|
||||
if (!done) {
|
||||
throw new Error(message)
|
||||
}else {
|
||||
return ret
|
||||
}
|
||||
},
|
||||
|
||||
idpLoginPage: (driver, preferredIdp) => {
|
||||
if (!preferredIdp) {
|
||||
if (process.env.PROFILES.includes("uaa")) {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
const { By, Key, until, Builder } = require('selenium-webdriver')
|
||||
require('chromedriver')
|
||||
const assert = require('assert')
|
||||
const { buildDriver, goToHome, captureScreensFor, teardown, delay } = require('../utils')
|
||||
const { buildDriver, goToHome, captureScreensFor, teardown, doWhile, log } = require('../utils')
|
||||
const { getManagementUrl, createVhost, deleteVhost } = require('../mgt-api')
|
||||
|
||||
const LoginPage = require('../pageobjects/LoginPage')
|
||||
const OverviewPage = require('../pageobjects/OverviewPage')
|
||||
|
@ -46,6 +47,27 @@ describe('Virtual Hosts in Admin tab', function () {
|
|||
assert.equal("/", await vhostTab.getName())
|
||||
})
|
||||
|
||||
describe('given there is a new virtualhost with a tag', async function() {
|
||||
let vhost = "test_" + Math.floor(Math.random() * 1000)
|
||||
before(async function() {
|
||||
createVhost(getManagementUrl(), vhost, "selenium", "selenium-tag")
|
||||
await overview.clickOnAdminTab()
|
||||
await adminTab.clickOnVhosts()
|
||||
})
|
||||
it('vhost is listed', async function () {
|
||||
await vhostsTab.searchForVhosts(vhost)
|
||||
let vhostTable = await doWhile(async function() {
|
||||
return vhostsTab.getVhostsTable()
|
||||
}, function(table) {
|
||||
return table.length > 0 && vhost.localeCompare(table[0][0])
|
||||
})
|
||||
log("vhostTable: " + vhostTable)
|
||||
})
|
||||
after(async function () {
|
||||
deleteVhost(getManagementUrl(), vhost)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
await teardown(driver, this, captureScreen)
|
||||
|
|
Loading…
Reference in New Issue