Skip to content

Commit 1468489

Browse files
Merge pull request #12832 from rabbitmq/mergify/bp/v4.0.x/pr-12786
Selenium suites: replace Java AMQP 1.0 client with a JavaScript one (backport #12786)
2 parents 06c34c7 + 55d9abf commit 1468489

File tree

8 files changed

+233
-189
lines changed

8 files changed

+233
-189
lines changed

selenium/Dockerfile

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ COPY package.json package.json
77

88
FROM base as test
99
RUN npm install
10-
RUN mkdir -p /code/amqp10-roundtriptest
11-
COPY amqp10-roundtriptest /code/amqp10-roundtriptest
12-
RUN mvn -f /code/amqp10-roundtriptest package
1310

1411
ENTRYPOINT [ "npm" ]
1512
CMD [ "" ]

selenium/amqp10-roundtriptest/pom.xml

-103
This file was deleted.

selenium/amqp10-roundtriptest/run

-16
This file was deleted.

selenium/amqp10-roundtriptest/src/main/java/com/rabbitmq/amqp1_0/RoundTripTest.java

-60
This file was deleted.

selenium/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"scripts": {
77
"fakeportal": "node fakeportal/app.js",
88
"fakeproxy": "node fakeportal/proxy.js",
9-
"amqp10_roundtriptest": "eval $(cat $ENV_FILE ) && amqp10-roundtriptest/run",
109
"test": " eval $(cat $ENV_FILE ) && mocha --recursive --trace-warnings --timeout 40000"
1110
},
1211
"keywords": [],

selenium/test/amqp.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
var container = require('rhea') // https://github.com/amqp/rhea
2+
var fs = require('fs');
3+
var path = require('path');
4+
5+
function getAmqpConnectionOptions() {
6+
return {
7+
'host': process.env.RABBITMQ_HOSTNAME || 'rabbitmq',
8+
'port': process.env.RABBITMQ_AMQP_PORT || 5672,
9+
'username' : process.env.RABBITMQ_AMQP_USERNAME || 'guest',
10+
'password' : process.env.RABBITMQ_AMQP_PASSWORD || 'guest',
11+
'id': "selenium-connection-id",
12+
'container_id': "selenium-container-id"
13+
}
14+
}
15+
function getAmqpsConnectionOptions() {
16+
let options = getAmqpConnectionOptions()
17+
let useMtls = process.env.AMQP_USE_MTLS || false
18+
if (useMtls) {
19+
options['enable_sasl_external'] = true
20+
}
21+
options['transport'] = 'tls'
22+
let certsLocation = getEnv("RABBITMQ_CERTS");
23+
options['key'] = fs.readFileSync(path.resolve(certsLocation,'client_rabbitmq_key.pem'))
24+
options['cert'] = fs.readFileSync(path.resolve(certsLocation,'client_rabbitmq_certificate.pem'))
25+
options['ca'] = fs.readFileSync(path.resolve(certsLocation,'ca_rabbitmq_certificate.pem'))
26+
}
27+
function getConnectionOptions() {
28+
switch(process.env.RABBITMQ_AMQP_SCHEME || 'amqp'){
29+
case 'amqp':
30+
return getAmqpConnectionOptions()
31+
case 'amqps':
32+
return getAmqpsConnectionOptions()
33+
}
34+
}
35+
module.exports = {
36+
37+
open: () => {
38+
let promise = new Promise((resolve, reject) => {
39+
container.on('connection_open', function(context) {
40+
resolve()
41+
})
42+
})
43+
let connection = container.connect(getConnectionOptions())
44+
let receiver = connection.open_receiver({
45+
source: 'examples',
46+
target: 'receiver-target',
47+
name: 'receiver-link'
48+
})
49+
let sender = connection.open_sender({
50+
target: 'examples',
51+
source: 'sender-source',
52+
name: 'sender-link'
53+
})
54+
return {
55+
'connection': connection,
56+
'promise' : promise,
57+
'receiver' : receiver,
58+
'sender' : sender
59+
}
60+
},
61+
close: (connection) => {
62+
if (connection != null) {
63+
connection.close()
64+
}
65+
},
66+
once: (event, callback) => {
67+
container.once(event, callback)
68+
},
69+
on: (event, callback) => {
70+
container.on(event, callback)
71+
}
72+
}

selenium/test/authnz-msg-protocols/amqp10.js

+39-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
const assert = require('assert')
22
const { tokenFor, openIdConfiguration } = require('../utils')
33
const { reset, expectUser, expectVhost, expectResource, allow, verifyAll } = require('../mock_http_backend')
4-
const {execSync} = require('child_process')
4+
const { open: openAmqp, once: onceAmqp, on: onAmqp, close: closeAmqp } = require('../amqp')
5+
6+
var receivedAmqpMessageCount = 0
7+
var untilConnectionEstablished = new Promise((resolve, reject) => {
8+
onAmqp('connection_open', function(context) {
9+
resolve()
10+
})
11+
})
12+
13+
onAmqp('message', function (context) {
14+
receivedAmqpMessageCount++
15+
})
16+
onceAmqp('sendable', function (context) {
17+
context.sender.send({body:'first message'})
18+
})
519

620
const profiles = process.env.PROFILES || ""
721
var backends = ""
@@ -15,6 +29,10 @@ describe('Having AMQP 1.0 protocol enabled and the following auth_backends: ' +
1529
let expectations = []
1630
let username = process.env.RABBITMQ_AMQP_USERNAME
1731
let password = process.env.RABBITMQ_AMQP_PASSWORD
32+
<<<<<<< HEAD
33+
=======
34+
let amqp;
35+
>>>>>>> 0ba194ae53 (Replace java amqp10 with javascript one)
1836

1937
before(function () {
2038
if (backends.includes("http") && username.includes("http")) {
@@ -36,14 +54,29 @@ describe('Having AMQP 1.0 protocol enabled and the following auth_backends: ' +
3654
}
3755
})
3856

39-
it('can open an AMQP 1.0 connection', function () {
40-
execSync("npm run amqp10_roundtriptest -- " + username + " " + password)
41-
57+
it('can open an AMQP 1.0 connection', async function () {
58+
amqp = openAmqp()
59+
await untilConnectionEstablished
60+
var untilMessageReceived = new Promise((resolve, reject) => {
61+
onAmqp('message', function(context) {
62+
resolve()
63+
})
64+
})
65+
amqp.sender.send({body:'second message'})
66+
await untilMessageReceived
67+
assert.equal(2, receivedAmqpMessageCount)
4268
})
4369

4470
after(function () {
45-
if ( backends.includes("http") ) {
46-
verifyAll(expectations)
71+
if ( backends.includes("http") ) {
72+
verifyAll(expectations)
73+
}
74+
try {
75+
if (amqp != null) {
76+
closeAmqp(amqp.connection)
4777
}
78+
} catch (error) {
79+
console.error("Failed to close amqp10 connection due to " + error);
80+
}
4881
})
4982
})

0 commit comments

Comments
 (0)