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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
3.2 KiB
JavaScript
Raw Normal View History

2023-08-14 18:51:46 +08:00
const assert = require('assert')
const { 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')
var untilConnectionEstablished = new Promise((resolve, reject) => {
onAmqp('connection_open', function(context) {
resolve()
})
})
onceAmqp('sendable', function (context) {
context.sender.send({body:'first message'})
})
2023-08-14 18:51:46 +08:00
const profiles = process.env.PROFILES || ""
var backends = ""
for (const element of profiles.split(" ")) {
if ( element.startsWith("auth_backends-") ) {
backends = element.substring(element.indexOf("-")+1)
}
}
describe('Having AMQP 1.0 protocol enabled and the following auth_backends: ' + backends, function () {
let expectations = []
let username = process.env.RABBITMQ_AMQP_USERNAME
let password = process.env.RABBITMQ_AMQP_PASSWORD
let amqp;
2023-08-14 18:51:46 +08:00
before(function () {
if (backends.includes("http") && username.includes("http")) {
reset()
expectations.push(expectUser({ "username": username, "password": password}, "allow"))
expectations.push(expectVhost({ "username": username, "vhost": "/"}, "allow"))
expectations.push(expectResource({ "username": username, "vhost": "/", "resource": "queue", "name": "my-queue", "permission":"configure", "tags":""}, "allow"))
expectations.push(expectResource({ "username": username, "vhost": "/", "resource": "queue", "name": "my-queue", "permission":"read", "tags":""}, "allow"))
expectations.push(expectResource({ "username": username, "vhost": "/", "resource": "exchange", "name": "amq.default", "permission":"write", "tags":""}, "allow"))
}else if (backends.includes("oauth") && username.includes("oauth")) {
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)
let openIdConfig = openIdConfiguration(oauthProviderUrl)
console.log("Obtained token_endpoint : " + openIdConfig.token_endpoint)
password = tokenFor(oauthClientId, oauthClientSecret, openIdConfig.token_endpoint)
console.log("Obtained access token : " + password)
}
2023-08-14 18:51:46 +08:00
})
it('can open an AMQP 1.0 connection', async function () {
var untilFirstMessageReceived = new Promise((resolve, reject) => {
onAmqp('message', function(context) {
resolve()
})
})
amqp = openAmqp()
await untilConnectionEstablished
await untilFirstMessageReceived
var untilSecondMessageReceived = new Promise((resolve, reject) => {
onAmqp('message', function(context) {
resolve()
})
})
amqp.sender.send({body:'second message'})
await untilSecondMessageReceived
2023-08-14 18:51:46 +08:00
})
after(function () {
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);
}
2023-08-14 18:51:46 +08:00
})
})