diff --git a/selenium/Dockerfile b/selenium/Dockerfile index 8e34be523f..ce100de437 100644 --- a/selenium/Dockerfile +++ b/selenium/Dockerfile @@ -7,9 +7,6 @@ COPY package.json package.json FROM base as test RUN npm install -RUN mkdir -p /code/amqp10-roundtriptest -COPY amqp10-roundtriptest /code/amqp10-roundtriptest -RUN mvn -f /code/amqp10-roundtriptest package ENTRYPOINT [ "npm" ] CMD [ "" ] diff --git a/selenium/amqp10-roundtriptest/pom.xml b/selenium/amqp10-roundtriptest/pom.xml deleted file mode 100644 index f39425a50e..0000000000 --- a/selenium/amqp10-roundtriptest/pom.xml +++ /dev/null @@ -1,103 +0,0 @@ - - 4.0.0 - com.rabbitmq.amqp1_0 - amqp10-roundtriptest - jar - 1.0-SNAPSHOT - amqp10-roundtriptest - https://www.rabbitmq.com - - 5.9.3 - 2.3.0 - 1.2.13 - 2.24.0 - 1.17.0 - 3.11.0 - 3.1.2 - - - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - - - - - org.apache.qpid - qpid-jms-client - ${qpid-jms-client.version} - - - - - ch.qos.logback - logback-classic - ${logback.version} - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-assembly-plugin - - - package - - single - - - - - com.rabbitmq.amqp1_0.RoundTripTest - - - - jar-with-dependencies - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - com.rabbitmq.amqp1_0.RoundTripTest - - - - - - - com.diffplug.spotless - spotless-maven-plugin - ${spotless.version} - - - - ${google-java-format.version} - - - - - - - - - diff --git a/selenium/amqp10-roundtriptest/run b/selenium/amqp10-roundtriptest/run deleted file mode 100755 index b91f0becf7..0000000000 --- a/selenium/amqp10-roundtriptest/run +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -env | grep RABBITMQ - -if [[ -f "/code/amqp10-roundtriptest" ]]; then - echo "Running amqp10-roundtriptest inside mocha-test docker image ..." - java -jar /code/amqp10-roundtriptest-1.0-SNAPSHOT-jar-with-dependencies.jar $@ -else - if [[ ! -f "${SCRIPT}/target/amqp10-roundtriptest-1.0-SNAPSHOT-jar-with-dependencies.jar" ]]; then - echo "Building amqp10-roundtriptest jar ..." - mvn -f amqp10-roundtriptest package $@ - fi - echo "Running amqp10-roundtriptest jar ..." - java -jar ${SCRIPT}/target/amqp10-roundtriptest-1.0-SNAPSHOT-jar-with-dependencies.jar $@ -fi diff --git a/selenium/amqp10-roundtriptest/src/main/java/com/rabbitmq/amqp1_0/RoundTripTest.java b/selenium/amqp10-roundtriptest/src/main/java/com/rabbitmq/amqp1_0/RoundTripTest.java deleted file mode 100644 index 03c1733516..0000000000 --- a/selenium/amqp10-roundtriptest/src/main/java/com/rabbitmq/amqp1_0/RoundTripTest.java +++ /dev/null @@ -1,96 +0,0 @@ -// vim:sw=4:et: - -package com.rabbitmq.amqp1_0; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import jakarta.jms.*; -import java.util.*; -import javax.naming.Context; - -/** Unit test for simple App. */ -public class RoundTripTest { - - public static String getEnv(String property, String defaultValue) { - return System.getenv(property) == null ? defaultValue : System.getenv(property); - } - public static String getEnv(String property) { - String value = System.getenv(property); - if (value == null) { - throw new IllegalArgumentException("Missing env variable " + property); - } - return value; - } - public static void main(String args[]) throws Exception { - String hostname = getEnv("RABBITMQ_HOSTNAME", "localhost"); - String port = getEnv("RABBITMQ_AMQP_PORT", "5672"); - String scheme = getEnv("RABBITMQ_AMQP_SCHEME", "amqp"); - String uri = scheme + "://" + hostname + ":" + port; - String username = args.length > 0 ? args[0] : getEnv("RABBITMQ_AMQP_USERNAME", "guest"); - String password = args.length > 1 ? args[1] : getEnv("RABBITMQ_AMQP_PASSWORD", "guest"); - - boolean usemtls = Boolean.parseBoolean(getEnv("AMQP_USE_MTLS", "false")); - - if ("amqps".equals(scheme)) { - List connectionParams = new ArrayList(); - String certsLocation = getEnv("RABBITMQ_CERTS"); - - connectionParams.add("transport.trustStoreLocation=" + certsLocation + "/truststore.jks"); - connectionParams.add("transport.trustStorePassword=foobar"); - connectionParams.add("transport.verifyHost=true"); - connectionParams.add("transport.trustAll=true"); - - if (usemtls) { - connectionParams.add("amqp.saslMechanisms=EXTERNAL"); - connectionParams.add("transport.keyStoreLocation=" + certsLocation + "/client_rabbitmq.jks"); - connectionParams.add("transport.keyStorePassword=foobar"); - connectionParams.add("transport.keyAlias=client-rabbitmq-tls"); - } - if (!connectionParams.isEmpty()) { - uri = uri + "?" + String.join("&", connectionParams); - System.out.println("Using AMQP URI " + uri); - } - } - - assertNotNull(uri); - - Hashtable env = new Hashtable<>(); - env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory"); - env.put("connectionfactory.myFactoryLookup", uri); - env.put("queue.myQueueLookup", "my-queue"); - env.put("jms.sendTimeout", 5); - env.put("jms.requestTimeout", 5); - javax.naming.Context context = new javax.naming.InitialContext(env); - - ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup"); - Destination queue = (Destination) context.lookup("myQueueLookup"); - - try (Connection connection = - createConnection(factory, usemtls, username, password)) { - connection.start(); - - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - MessageProducer messageProducer = session.createProducer(queue); - MessageConsumer messageConsumer = session.createConsumer(queue); - - TextMessage message = session.createTextMessage("Hello world!"); - messageProducer.send( - message, - DeliveryMode.NON_PERSISTENT, - Message.DEFAULT_PRIORITY, - Message.DEFAULT_TIME_TO_LIVE); - TextMessage receivedMessage = (TextMessage) messageConsumer.receive(2000L); - - assertEquals(message.getText(), receivedMessage.getText()); - } - } - private static Connection createConnection(ConnectionFactory factory, - boolean usemtls, String username, String password) throws jakarta.jms.JMSException { - if (usemtls) { - return factory.createConnection(); - } - return factory.createConnection(username, password); - } -} diff --git a/selenium/package.json b/selenium/package.json index 0087e95d2f..251a751f09 100644 --- a/selenium/package.json +++ b/selenium/package.json @@ -6,7 +6,6 @@ "scripts": { "fakeportal": "node fakeportal/app.js", "fakeproxy": "node fakeportal/proxy.js", - "amqp10_roundtriptest": "eval $(cat $ENV_FILE ) && amqp10-roundtriptest/run", "test": " eval $(cat $ENV_FILE ) && mocha --recursive --trace-warnings --timeout 40000" }, "keywords": [], diff --git a/selenium/test/amqp.js b/selenium/test/amqp.js new file mode 100644 index 0000000000..715cd079da --- /dev/null +++ b/selenium/test/amqp.js @@ -0,0 +1,72 @@ +var container = require('rhea') // https://github.com/amqp/rhea +var fs = require('fs'); +var path = require('path'); + +function getAmqpConnectionOptions() { + return { + 'host': process.env.RABBITMQ_HOSTNAME || 'rabbitmq', + 'port': process.env.RABBITMQ_AMQP_PORT || 5672, + 'username' : process.env.RABBITMQ_AMQP_USERNAME || 'guest', + 'password' : process.env.RABBITMQ_AMQP_PASSWORD || 'guest', + 'id': "selenium-connection-id", + 'container_id': "selenium-container-id" + } +} +function getAmqpsConnectionOptions() { + let options = getAmqpConnectionOptions() + let useMtls = process.env.AMQP_USE_MTLS || false + if (useMtls) { + options['enable_sasl_external'] = true + } + options['transport'] = 'tls' + let certsLocation = getEnv("RABBITMQ_CERTS"); + options['key'] = fs.readFileSync(path.resolve(certsLocation,'client_rabbitmq_key.pem')) + options['cert'] = fs.readFileSync(path.resolve(certsLocation,'client_rabbitmq_certificate.pem')) + options['ca'] = fs.readFileSync(path.resolve(certsLocation,'ca_rabbitmq_certificate.pem')) +} +function getConnectionOptions() { + switch(process.env.RABBITMQ_AMQP_SCHEME || 'amqp'){ + case 'amqp': + return getAmqpConnectionOptions() + case 'amqps': + return getAmqpsConnectionOptions() + } +} +module.exports = { + + open: () => { + let promise = new Promise((resolve, reject) => { + container.on('connection_open', function(context) { + resolve() + }) + }) + let connection = container.connect(getConnectionOptions()) + let receiver = connection.open_receiver({ + source: 'examples', + target: 'receiver-target', + name: 'receiver-link' + }) + let sender = connection.open_sender({ + target: 'examples', + source: 'sender-source', + name: 'sender-link' + }) + return { + 'connection': connection, + 'promise' : promise, + 'receiver' : receiver, + 'sender' : sender + } + }, + close: (connection) => { + if (connection != null) { + connection.close() + } + }, + once: (event, callback) => { + container.once(event, callback) + }, + on: (event, callback) => { + container.on(event, callback) + } +} \ No newline at end of file diff --git a/selenium/test/authnz-msg-protocols/amqp10.js b/selenium/test/authnz-msg-protocols/amqp10.js index 98dedfdb42..163dec0020 100644 --- a/selenium/test/authnz-msg-protocols/amqp10.js +++ b/selenium/test/authnz-msg-protocols/amqp10.js @@ -1,7 +1,21 @@ const assert = require('assert') const { tokenFor, openIdConfiguration } = require('../utils') const { reset, expectUser, expectVhost, expectResource, allow, verifyAll } = require('../mock_http_backend') -const {execSync} = require('child_process') +const { open: openAmqp, once: onceAmqp, on: onAmqp, close: closeAmqp } = require('../amqp') + +var receivedAmqpMessageCount = 0 +var untilConnectionEstablished = new Promise((resolve, reject) => { + onAmqp('connection_open', function(context) { + resolve() + }) +}) + +onAmqp('message', function (context) { + receivedAmqpMessageCount++ +}) +onceAmqp('sendable', function (context) { + context.sender.send({body:'first message'}) +}) const profiles = process.env.PROFILES || "" var backends = "" @@ -15,10 +29,8 @@ describe('Having AMQP 1.0 protocol enabled and the following auth_backends: ' + let expectations = [] let username = process.env.RABBITMQ_AMQP_USERNAME let password = process.env.RABBITMQ_AMQP_PASSWORD - let usemtls = process.env.AMQP_USE_MTLS - let amqpClientCommand = "npm run amqp10_roundtriptest" + - (usemtls ? "" : " " + username + " " + password) - + let amqp; + before(function () { if (backends.includes("http") && username.includes("http")) { reset() @@ -39,13 +51,29 @@ describe('Having AMQP 1.0 protocol enabled and the following auth_backends: ' + } }) - it('can open an AMQP 1.0 connection', function () { - console.log(execSync(amqpClientCommand).toString()) + it('can open an AMQP 1.0 connection', async function () { + amqp = openAmqp() + await untilConnectionEstablished + var untilMessageReceived = new Promise((resolve, reject) => { + onAmqp('message', function(context) { + resolve() + }) + }) + amqp.sender.send({body:'second message'}) + await untilMessageReceived + assert.equal(2, receivedAmqpMessageCount) }) after(function () { - if ( backends.includes("http") ) { - verifyAll(expectations) + if ( backends.includes("http") ) { + verifyAll(expectations) + } + try { + if (amqp != null) { + closeAmqp(amqp.connection) } + } catch (error) { + console.error("Failed to close amqp10 connection due to " + error); + } }) }) diff --git a/selenium/test/connections/amqp10/sessions-for-monitoring-user.js b/selenium/test/connections/amqp10/sessions-for-monitoring-user.js index 9a2817c3cb..0cd98f6ea0 100644 --- a/selenium/test/connections/amqp10/sessions-for-monitoring-user.js +++ b/selenium/test/connections/amqp10/sessions-for-monitoring-user.js @@ -1,6 +1,7 @@ const { By, Key, until, Builder } = require('selenium-webdriver') require('chromedriver') const assert = require('assert') +const { open: openAmqp, once: onceAmqp, on: onAmqp, close: closeAmqp } = require('../../amqp') const { buildDriver, goToHome, captureScreensFor, teardown, delay } = require('../../utils') const LoginPage = require('../../pageobjects/LoginPage') @@ -8,18 +9,17 @@ const OverviewPage = require('../../pageobjects/OverviewPage') const ConnectionsPage = require('../../pageobjects/ConnectionsPage') const ConnectionPage = require('../../pageobjects/ConnectionPage') -var container = require('rhea') // https://github.com/amqp/rhea var receivedAmqpMessageCount = 0 var untilConnectionEstablished = new Promise((resolve, reject) => { - container.on('connection_open', function(context) { + onAmqp('connection_open', function(context) { resolve() }) }) -container.on('message', function (context) { +onAmqp('message', function (context) { receivedAmqpMessageCount++ }) -container.once('sendable', function (context) { +onceAmqp('sendable', function (context) { context.sender.send({body:'first message'}) }) @@ -28,7 +28,7 @@ describe('Given an amqp10 connection opened, listed and clicked on it', function let captureScreen let connectionsPage let connectionPage - let connection + let amqp before(async function () { driver = buildDriver() @@ -41,24 +41,8 @@ describe('Given an amqp10 connection opened, listed and clicked on it', function await login.login('monitoring-only', 'guest') await overview.isLoaded() - connection = container.connect( - {'host': process.env.RABBITMQ_HOSTNAME || 'rabbitmq', - 'port': process.env.RABBITMQ_AMQP_PORT || 5672, - 'username' : process.env.RABBITMQ_AMQP_USERNAME || 'guest', - 'password' : process.env.RABBITMQ_AMQP_PASSWORD || 'guest', - 'id': "selenium-connection-id", - 'container_id': "selenium-container-id" - }) - connection.open_receiver({ - source: 'examples', - target: 'receiver-target', - name: 'receiver-link' - }) - sender = connection.open_sender({ - target: 'examples', - source: 'sender-source', - name: 'sender-link' - }) + + amqp = openAmqp() await untilConnectionEstablished await overview.clickOnConnectionsTab() await connectionsPage.isLoaded() @@ -108,11 +92,11 @@ describe('Given an amqp10 connection opened, listed and clicked on it', function it('display live link information', async function () { var untilMessageReceived = new Promise((resolve, reject) => { - container.on('message', function(context) { + onAmqp('message', function(context) { resolve() }) }) - sender.send({body:'second message'}) + amqp.sender.send({body:'second message'}) await untilMessageReceived assert.equal(2, receivedAmqpMessageCount) @@ -121,16 +105,14 @@ describe('Given an amqp10 connection opened, listed and clicked on it', function let incomingLink = connectionPage.getIncomingLinkInfo(sessions.incoming_links, 0) assert.equal(2, incomingLink.deliveryCount) - //console.log("incomingLink: " + JSON.stringify(incomingLink)) - //console.log("outgoingLink: " + JSON.stringify(outgoingLink)) }) after(async function () { await teardown(driver, this, captureScreen) try { - if (connection != null) { - connection.close() + if (amqp != null) { + closeAmqp(amqp.connection) } } catch (error) { console.error("Failed to close amqp10 connection due to " + error);