Skip to content

Selenium suites: replace Java AMQP 1.0 client with a JavaScript one (backport #12786) #12832

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 2 commits into from
Nov 27, 2024
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
3 changes: 0 additions & 3 deletions selenium/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 [ "" ]
103 changes: 0 additions & 103 deletions selenium/amqp10-roundtriptest/pom.xml

This file was deleted.

16 changes: 0 additions & 16 deletions selenium/amqp10-roundtriptest/run

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion selenium/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
72 changes: 72 additions & 0 deletions selenium/test/amqp.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
45 changes: 39 additions & 6 deletions selenium/test/authnz-msg-protocols/amqp10.js
Original file line number Diff line number Diff line change
@@ -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 = ""
Expand All @@ -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")) {
Expand All @@ -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);
}
})
})
Loading
Loading