Skip to content

Add several functions to mgt-api.js for wsr testing with selenium #13848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
12 changes: 7 additions & 5 deletions selenium/bin/components/other-rabbitmq
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ start_other_rabbitmq() {
if [[ "$PROFILES_FOR_OTHER" == *"docker"* ]]; then
start_docker_other_rabbitmq
else
start_local_rabbitmq
start_local_other_rabbitmq
fi
}
stop_other_rabbitmq() {
if [[ "$PROFILES_FOR_OTHER" == *"docker"* ]]; then
kill_container_if_exist "$component"
kill_container_if_exist "${OTHER_RABBITMQ_HOSTNAME}"
else
stop_local_rabbitmq
stop_local_other_rabbitmq
fi
}

Expand All @@ -44,7 +44,7 @@ save_logs_other_rabbitmq() {
if [[ "$PROFILES_FOR_OTHER" == *"cluster"* ]]; then
docker compose -f $CONF_DIR/rabbitmq/other-compose.yml logs > $LOGS/other-rabbitmq.log
else
save_container_logs "other-rabbitmq"
save_container_logs "${OTHER_RABBITMQ_HOSTNAME}"
fi
fi
}
Expand Down Expand Up @@ -129,13 +129,15 @@ start_docker_other_rabbitmq() {
print "> RABBITMQ_TEST_DIR: /var/rabbitmq"

docker run \
--rm \
--detach \
--name ${OTHER_RABBITMQ_HOSTNAME} \
--net ${DOCKER_NETWORK} \
-p 5674:5672 \
-p 5673:5671 \
-p 15674:15672 \
-p 15673:15671 \
-p 15675:15675 \
-p 5552:5552 \
-v $CONF_DIR/other-rabbitmq/:/etc/rabbitmq \
-v $CONF_DIR/other-rabbitmq/imports:/var/rabbitmq/imports \
-v ${TEST_DIR}:/config \
Expand Down
1 change: 1 addition & 0 deletions selenium/bin/components/rabbitmq
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ start_docker_rabbitmq() {
-p 5671:5671 \
-p 15672:15672 \
-p 15671:15671 \
-p 5551:5551 \
-v $CONF_DIR/rabbitmq/:/etc/rabbitmq \
-v $CONF_DIR/rabbitmq/imports:/var/rabbitmq/imports \
-v ${TEST_DIR}:/config \
Expand Down
18 changes: 10 additions & 8 deletions selenium/bin/suite_template
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ _test() {
print "> FAKEPORTAL_URL: ${FAKEPORTAL_URL}"
mocha_test_tag=($(md5sum $SELENIUM_ROOT_FOLDER/package.json))

print "> OAUTH_NODE_EXTRA_CA_CERTS: ${OAUTH_NODE_EXTRA_CA_CERTS}"
MOUNT_NODE_EXTRA_CA_CERTS=${TEST_DIR}/${OAUTH_NODE_EXTRA_CA_CERTS}
generate_node_extra_ca_cert
MOUNT_NODE_EXTRA_CA_CERTS=${CONF_DIR}/node_ca_certs.pem
print "> MOUNT_NODE_EXTRA_CA_CERTS: ${MOUNT_NODE_EXTRA_CA_CERTS}"

docker run \
Expand Down Expand Up @@ -417,15 +417,15 @@ other_profiles_with_local_or_docker() {
fi
}
generate_env_file() {
begin "Generating env file from profiles ${PROFILES} ..."
begin "Generating env file from profiles: [${PROFILES}] ..."
mkdir -p $CONF_DIR
${BIN_DIR}/gen-env-file "${PROFILES}" $TEST_CONFIG_DIR ${ENV_FILE}.tmp
grep -v '^#' ${ENV_FILE}.tmp > $ENV_FILE
source $ENV_FILE
end "Finished generating env file."
}
generate_other_env_file() {
begin "Generating other env file from profiles ${PROFILES_FOR_OTHER} "
begin "Generating other env file from profiles: [${PROFILES_FOR_OTHER}] "
mkdir -p $CONF_DIR
${BIN_DIR}/gen-env-file "${PROFILES_FOR_OTHER}" $TEST_CONFIG_DIR ${OTHER_ENV_FILE}.tmp
grep -v '^#' ${OTHER_ENV_FILE}.tmp > $OTHER_ENV_FILE
Expand Down Expand Up @@ -674,7 +674,7 @@ test_local() {
export SELENIUM_POLLING=${SELENIUM_POLLING:-500}

generate_node_extra_ca_cert
MOUNT_NODE_EXTRA_CA_CERTS=${RABBITMQ_CERTS}/node_ca_certs.pem
MOUNT_NODE_EXTRA_CA_CERTS=${CONF_DIR}/node_ca_certs.pem

print "> SELENIUM_TIMEOUT: ${SELENIUM_TIMEOUT}"
print "> SELENIUM_POLLING: ${SELENIUM_POLLING}"
Expand Down Expand Up @@ -738,14 +738,16 @@ save_components_logs() {
end "Finished saving logs"
}
generate_node_extra_ca_cert() {
echo "Generating $RABBITMQ_CERTS/node_ca_certs.pem ..."
rm -f $RABBITMQ_CERTS/node_ca_certs.pem
echo "Generating ${CONF_DIR}/node_ca_certs.pem ..."
rm -f ${CONF_DIR}/node_ca_certs.pem
env | while IFS= read -r line; do
value=${line#*=}
name=${line%%=*}

if [[ $name == *NODE_EXTRA_CA_CERTS ]]
then
cat ${TEST_DIR}/${value} >> $RABBITMQ_CERTS/node_ca_certs.pem
echo "Adding ${TEST_DIR}/${value} to ${CONF_DIR}/node_ca_certs.pem ..."
cat ${TEST_DIR}/${value} >> ${CONF_DIR}/node_ca_certs.pem
fi
done
}
12 changes: 7 additions & 5 deletions selenium/fakeportal/proxy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var http = require('http'),
httpProxy = require('http-proxy');
const {log, error} = require('./utils.js')
const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest

const rabbitmq_url = process.env.RABBITMQ_URL || 'http://0.0.0.0:15672/';
Expand All @@ -14,7 +15,7 @@ const port = process.env.PORT;
var proxy = httpProxy.createProxyServer({});

proxy.on('proxyReq', function(proxyReq, req, res, options) {
console.log("proxing " + req.url)
log("proxing " + req.url)
if (req.url.endsWith("bootstrap.js")) {
proxyReq.setHeader('Authorization', 'Bearer ' + access_token(client_id, client_secret));
}
Expand All @@ -30,7 +31,7 @@ var server = http.createServer(function(req, res) {
target: rabbitmq_url
});
});
console.log("fakeproxy listening on port " + port + ". RABBITMQ_URL=" + rabbitmq_url)
log("fakeproxy listening on port " + port + ". RABBITMQ_URL=" + rabbitmq_url)
server.listen(port);


Expand All @@ -51,18 +52,19 @@ function access_token(id, secret) {
'&token_format=jwt' +
'&response_type=token';

console.debug("Sending " + url + " with params "+ params);
log("Sending " + url + " with params "+ params);

req.open('POST', url, false);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.setRequestHeader('Accept', 'application/json');
req.send(params);
console.log("Ret " + req.status)
log("Ret " + req.status)
if (req.status == 200) {
const token = JSON.parse(req.responseText).access_token;
console.log("Token => " + token)
log("Token => " + token)
return token;
} else {
error("Failed to get access token due to " + req.responseText)
throw new Error(req.status + " : " + req.responseText);
}
}
4 changes: 3 additions & 1 deletion selenium/test/amqp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var container = require('rhea') // https://github.com/amqp/rhea
var fs = require('fs');
var path = require('path');
const {log, error} = require('./utils.js')

var connectionOptions = getConnectionOptions()

function getAmqpConnectionOptions() {
Expand Down Expand Up @@ -28,7 +30,7 @@ function getAmqpsConnectionOptions() {
}
function getConnectionOptions() {
let scheme = process.env.RABBITMQ_AMQP_SCHEME || 'amqp'
console.log("Using AMQP protocol: " + scheme)
log("Using AMQP protocol: " + scheme)
switch(scheme){
case "amqp":
return getAmqpConnectionOptions()
Expand Down
10 changes: 5 additions & 5 deletions selenium/test/authnz-msg-protocols/amqp10.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert')
const { tokenFor, openIdConfiguration } = require('../utils')
const { log, tokenFor, openIdConfiguration } = require('../utils')
const { reset, expectUser, expectVhost, expectResource, allow, verifyAll } = require('../mock_http_backend')
const { open: openAmqp, once: onceAmqp, on: onAmqp, close: closeAmqp } = require('../amqp')

Expand Down Expand Up @@ -48,11 +48,11 @@ describe('Having AMQP 1.0 protocol enabled and the following auth_backends: ' +
let oauthProviderUrl = process.env.OAUTH_PROVIDER_URL
let oauthClientId = process.env.OAUTH_CLIENT_ID
let oauthClientSecret = process.env.OAUTH_CLIENT_SECRET
console.log("oauthProviderUrl : " + oauthProviderUrl)
log("oauthProviderUrl : " + oauthProviderUrl)
let openIdConfig = openIdConfiguration(oauthProviderUrl)
console.log("Obtained token_endpoint : " + openIdConfig.token_endpoint)
log("Obtained token_endpoint : " + openIdConfig.token_endpoint)
password = tokenFor(oauthClientId, oauthClientSecret, openIdConfig.token_endpoint)
console.log("Obtained access token : " + password)
log("Obtained access token : " + password)
}
})

Expand All @@ -78,7 +78,7 @@ describe('Having AMQP 1.0 protocol enabled and the following auth_backends: ' +
closeAmqp(amqp.connection)
}
} catch (error) {
console.error("Failed to close amqp10 connection due to " + error);
error("Failed to close amqp10 connection due to " + error);
}
})
})
6 changes: 3 additions & 3 deletions selenium/test/authnz-msg-protocols/mqtt.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs')
const assert = require('assert')
const { tokenFor, openIdConfiguration } = require('../utils')
const { tokenFor, openIdConfiguration, log } = require('../utils')
const { reset, expectUser, expectVhost, expectResource, allow, verifyAll } = require('../mock_http_backend')
const mqtt = require('mqtt');

Expand Down Expand Up @@ -45,9 +45,9 @@ describe('Having MQTT protocol enbled and the following auth_backends: ' + backe
let oauthClientId = process.env.OAUTH_CLIENT_ID
let oauthClientSecret = process.env.OAUTH_CLIENT_SECRET
let openIdConfig = openIdConfiguration(oauthProviderUrl)
console.log("Obtained token_endpoint : " + openIdConfig.token_endpoint)
log("Obtained token_endpoint : " + openIdConfig.token_endpoint)
password = tokenFor(oauthClientId, oauthClientSecret, openIdConfig.token_endpoint)
console.log("Obtained access token : " + password)
log("Obtained access token : " + password)
}
mqttOptions = {
clientId: client_id,
Expand Down
3 changes: 1 addition & 2 deletions selenium/test/exchanges/management.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { By, Key, until, Builder } = require('selenium-webdriver')
require('chromedriver')
const assert = require('assert')
const { buildDriver, goToHome, captureScreensFor, teardown, doWhile } = require('../utils')
const { buildDriver, goToHome, captureScreensFor, teardown, doWhile, log } = require('../utils')

const LoginPage = require('../pageobjects/LoginPage')
const OverviewPage = require('../pageobjects/OverviewPage')
Expand Down Expand Up @@ -56,7 +56,6 @@ describe('Exchange management', function () {
["other", "amq.topic", "topic"]
]

console.log("e :" + actual_table)
assert.deepEqual(actual_table, expected_table)
})

Expand Down
Loading
Loading