diff --git a/selenium/Dockerfile b/selenium/Dockerfile index 8e34be523f28..ce100de43725 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 f39425a50ee4..000000000000 --- 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 b91f0becf7a7..000000000000 --- 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 d683e23d8bce..000000000000 --- a/selenium/amqp10-roundtriptest/src/main/java/com/rabbitmq/amqp1_0/RoundTripTest.java +++ /dev/null @@ -1,60 +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 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 username = args.length > 0 ? args[0] : getEnv("RABBITMQ_AMQP_USERNAME", "guest"); - String password = args.length > 1 ? args[1] : getEnv("RABBITMQ_AMQP_PASSWORD", "guest"); - String uri = scheme + "://" + hostname + ":" + port; - - System.out.println("AMQPS Roundrip using uri " + 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); - - assertNotNull(uri); - - ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup"); - Destination queue = (Destination) context.lookup("myQueueLookup"); - - try (Connection connection = factory.createConnection(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()); - } - } -} diff --git a/selenium/package.json b/selenium/package.json index 5021dc3ef122..a113534b77b5 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 000000000000..715cd079da89 --- /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 0901ae039ce3..9148c00b89b2 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,6 +29,10 @@ 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 +<<<<<<< HEAD +======= + let amqp; +>>>>>>> 0ba194ae53 (Replace java amqp10 with javascript one) before(function () { if (backends.includes("http") && username.includes("http")) { @@ -36,14 +54,29 @@ describe('Having AMQP 1.0 protocol enabled and the following auth_backends: ' + } }) - it('can open an AMQP 1.0 connection', function () { - execSync("npm run amqp10_roundtriptest -- " + username + " " + password) - + 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 new file mode 100644 index 000000000000..0cd98f6ea08c --- /dev/null +++ b/selenium/test/connections/amqp10/sessions-for-monitoring-user.js @@ -0,0 +1,122 @@ +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') +const OverviewPage = require('../../pageobjects/OverviewPage') +const ConnectionsPage = require('../../pageobjects/ConnectionsPage') +const ConnectionPage = require('../../pageobjects/ConnectionPage') + +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'}) +}) + + +describe('Given an amqp10 connection opened, listed and clicked on it', function () { + let captureScreen + let connectionsPage + let connectionPage + let amqp + + before(async function () { + driver = buildDriver() + await goToHome(driver) + login = new LoginPage(driver) + overview = new OverviewPage(driver) + connectionsPage = new ConnectionsPage(driver) + connectionPage = new ConnectionPage(driver) + captureScreen = captureScreensFor(driver, __filename) + await login.login('monitoring-only', 'guest') + await overview.isLoaded() + + + amqp = openAmqp() + await untilConnectionEstablished + await overview.clickOnConnectionsTab() + await connectionsPage.isLoaded() + + connections_table = await connectionsPage.getConnectionsTable(20) + assert.equal(1, connections_table.length) + await connectionsPage.clickOnConnection(2) + await connectionPage.isLoaded() + }) + + + it('can list session information', async function () { + let sessions = await connectionPage.getSessions() + assert.equal(1, sessions.sessions.length) + let session = connectionPage.getSessionInfo(sessions.sessions, 0) + //console.log("session: " + JSON.stringify(session)) + assert.equal(0, session.channelNumber) + assert.equal(1, session.nextIncomingId) + assert.equal(0, session.outgoingUnsettledDeliveries) + }) + + it('can list link information', async function () { + let sessions = await connectionPage.getSessions() + assert.equal(1, sessions.incoming_links.length) + assert.equal(1, sessions.outgoing_links.length) + + let incomingLink = connectionPage.getIncomingLinkInfo(sessions.incoming_links, 0) + //console.log("incomingLink: " + JSON.stringify(incomingLink)) + assert.equal(1, incomingLink.handle) + assert.equal("sender-link", incomingLink.name) + assert.equal("examples", incomingLink.targetAddress) + assert.equal("mixed", incomingLink.sndSettleMode) + assert.equal("0", incomingLink.unconfirmedMessages) + assert.equal(1, incomingLink.deliveryCount) + + let outgoingLink = connectionPage.getOutgoingLinkInfo(sessions.outgoing_links, 0) + //console.log("outgoingLink: " + JSON.stringify(outgoingLink)) + assert.equal(0, outgoingLink.handle) + assert.equal("receiver-link", outgoingLink.name) + assert.equal("examples", outgoingLink.sourceAddress) + assert.equal("examples", outgoingLink.queueName) + + assert.equal(false, outgoingLink.sendSettled) + assert.equal("unlimited", outgoingLink.maxMessageSize) + + }) + + it('display live link information', async function () { + var untilMessageReceived = new Promise((resolve, reject) => { + onAmqp('message', function(context) { + resolve() + }) + }) + amqp.sender.send({body:'second message'}) + await untilMessageReceived + assert.equal(2, receivedAmqpMessageCount) + + await delay(5*1000) // wait until page refreshes + let sessions = await connectionPage.getSessions() + let incomingLink = connectionPage.getIncomingLinkInfo(sessions.incoming_links, 0) + assert.equal(2, incomingLink.deliveryCount) + + }) + + + after(async function () { + await teardown(driver, this, captureScreen) + try { + if (amqp != null) { + closeAmqp(amqp.connection) + } + } catch (error) { + console.error("Failed to close amqp10 connection due to " + error); + } + }) + +})