Skip to content

Commit cd02518

Browse files
Test amqp+oauth+opaque tokens
1 parent aaa6b34 commit cd02518

File tree

7 files changed

+94
-15
lines changed

7 files changed

+94
-15
lines changed

selenium/suites/authnz-messaging/auth-oauth-backend-with-opaque-tokens.sh

100644100755
File mode changed.

selenium/test/amqp.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ module.exports = {
4646
connectionOptions.username + ":" + connectionOptions.password + "@" +
4747
connectionOptions.host + ":" + connectionOptions.port
4848
},
49-
open: (queueName = "my-queue") => {
49+
open: (queueName = "my-queue", connOptions = connectionOptions) => {
5050
let promise = new Promise((resolve, reject) => {
5151
container.on('connection_open', function(context) {
5252
resolve()
5353
})
5454
})
55-
console.log("Opening amqp connection using " + JSON.stringify(connectionOptions))
55+
console.log("Opening amqp connection using " + JSON.stringify(connOptions))
5656

57-
let connection = container.connect(connectionOptions)
57+
let connection = container.connect(connOptions)
5858
let receiver = connection.open_receiver({
5959
source: queueName,
6060
target: 'receiver-target',

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const assert = require('assert')
22
const { log, tokenFor, openIdConfiguration } = require('../utils')
33
const { reset, expectUser, expectVhost, expectResource, allow, verifyAll } = require('../mock_http_backend')
4-
const { open: openAmqp, once: onceAmqp, on: onAmqp, close: closeAmqp } = require('../amqp')
4+
const { getAmqpConnectionOptions: amqpOptions, open: openAmqp, once: onceAmqp, on: onAmqp, close: closeAmqp } = require('../amqp')
55

66
var receivedAmqpMessageCount = 0
77
var untilConnectionEstablished = new Promise((resolve, reject) => {
@@ -31,6 +31,7 @@ describe('Having AMQP 1.0 protocol enabled and the following auth_backends: ' +
3131
let password = process.env.RABBITMQ_AMQP_PASSWORD
3232
let usemtls = process.env.AMQP_USE_MTLS
3333
let amqp;
34+
let amqpSettings = amqpOptions()
3435

3536
before(function () {
3637
if (backends.includes("http") && (username.includes("http") || usemtls)) {
@@ -48,16 +49,20 @@ describe('Having AMQP 1.0 protocol enabled and the following auth_backends: ' +
4849
let oauthProviderUrl = process.env.OAUTH_PROVIDER_URL
4950
let oauthClientId = process.env.OAUTH_CLIENT_ID
5051
let oauthClientSecret = process.env.OAUTH_CLIENT_SECRET
52+
let tokenFormat = process.env.OAUTH_TOKEN_FORMAT || 'jwt'
5153
log("oauthProviderUrl : " + oauthProviderUrl)
54+
log("oauthClientId : " + oauthClientId)
55+
log("oauthClientSecret : " + oauthClientSecret)
5256
let openIdConfig = openIdConfiguration(oauthProviderUrl)
5357
log("Obtained token_endpoint : " + openIdConfig.token_endpoint)
54-
password = tokenFor(oauthClientId, oauthClientSecret, openIdConfig.token_endpoint)
58+
password = tokenFor(oauthClientId, oauthClientSecret, openIdConfig.token_endpoint, tokenFormat)
5559
log("Obtained access token : " + password)
60+
amqpSettings.password = password
5661
}
5762
})
5863

5964
it('can open an AMQP 1.0 connection', async function () {
60-
amqp = openAmqp()
65+
amqp = openAmqp("mq-queue", amqpSettings)
6166
await untilConnectionEstablished
6267
var untilMessageReceived = new Promise((resolve, reject) => {
6368
onAmqp('message', function(context) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OAUTH_TOKEN_FORMAT=opaque

selenium/test/authnz-msg-protocols/rabbitmq.auth_backends-opaque-oauth.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ auth_oauth2.https.cacertfile = ${SPRING_CA_CERT}
1313
auth_oauth2.https.verify = verify_peer
1414
auth_oauth2.https.hostname_verification = wildcard
1515

16+
auth_oauth2.introspection_client_auth_method = basic
17+
auth_oauth2.introspection_client_id = introspection_client
18+
auth_oauth2.introspection_client_secret = introspection_client
19+
20+
auth_oauth2.opaque_token_signing_key.id = rabbit_opaque_key
21+
auth_oauth2.opaque_token_signing_key.type = hs256
22+
auth_oauth2.opaque_token_signing_key.key = symmetrical-signing-key
23+
24+
auth_oauth2.verify_aud = false

selenium/test/authnz-msg-protocols/spring/application.yml

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ spring:
2828
- rabbitmq
2929
authorizationserver:
3030
client:
31+
introspection_client:
32+
registration:
33+
provider: spring
34+
client-id: introspection_client
35+
client-secret: "{noop}introspection_client"
36+
authorization-grant-types:
37+
- client_credentials
38+
client-authentication-methods:
39+
- client_secret_basic
40+
client-name: introspection_client
3141
producer:
3242
registration:
3343
provider: spring
@@ -36,17 +46,70 @@ spring:
3646
authorization-grant-types:
3747
- client_credentials
3848
client-authentication-methods:
39-
- client_secret_post
40-
# token-settings:
41-
# access-token-format: reference
42-
scopes:
49+
- client_secret_basic
50+
scope:
4351
- openid
4452
- profile
4553
- rabbitmq.tag:management
46-
- rabbitmq.configure:*/*
47-
- rabbitmq.read:*/*
48-
- rabbitmq.write:*/*
54+
- rabbitmq.configure:*/*
55+
- rabbitmq.read:*/*
56+
- rabbitmq.write:*/*
4957
client-name: producer
58+
token:
59+
access-token-format: reference
60+
mgt_api_client_opaque:
61+
registration:
62+
provider: spring
63+
client-id: mgt_api_client_opaque
64+
client-secret: "{noop}mgt_api_client_opaque"
65+
authorization-grant-types:
66+
- client_credentials
67+
client-authentication-methods:
68+
- client_secret_basic
69+
scope:
70+
- openid
71+
- profile
72+
- rabbitmq.tag:management
73+
client-name: mgt_api_client_opaque
74+
token:
75+
access-token-format: reference
76+
mgt_api_client:
77+
registration:
78+
provider: spring
79+
client-id: mgt_api_client
80+
client-secret: "{noop}mgt_api_client"
81+
authorization-grant-types:
82+
- client_credentials
83+
client-authentication-methods:
84+
- client_secret_basic
85+
scope:
86+
- openid
87+
- profile
88+
- rabbitmq.tag:management
89+
- rabbitmq.tag:administrator
90+
client-name: mgt_api_client
91+
rabbitmq_client_code_opaque:
92+
registration:
93+
provider: spring
94+
client-id: rabbitmq_client_code_opaque
95+
client-secret: "{noop}rabbitmq_client_code_opaque"
96+
require-proof-key: true
97+
authorization-grant-types:
98+
- authorization_code
99+
client-authentication-methods:
100+
- none
101+
redirect-uris:
102+
- "${RABBITMQ_SCHEME}://${RABBITMQ_HOST}${RABBITMQ_PATH}/js/oidc-oauth/login-callback.html"
103+
post-logout-redirect-uris:
104+
- "${RABBITMQ_SCHEME}://${RABBITMQ_HOST}${RABBITMQ_PATH}/"
105+
scopes:
106+
- openid
107+
- profile
108+
- rabbitmq.tag:administrator
109+
- rabbitmq.tag:management
110+
client-name: rabbitmq_client_code_opaque
111+
token:
112+
access-token-format: reference
50113
rabbitmq_client_code:
51114
registration:
52115
provider: spring

selenium/test/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,17 +236,18 @@ module.exports = {
236236
}
237237
},
238238

239-
tokenFor: (client_id, client_secret, url = uaaUrl) => {
239+
tokenFor: (client_id, client_secret, url = uaaUrl, token_format = "jwt") => {
240240
const req = new XMLHttpRequest()
241241
const params = 'client_id=' + client_id +
242242
'&client_secret=' + client_secret +
243243
'&grant_type=client_credentials' +
244-
'&token_format=jwt' +
244+
'&token_format=' + token_format +
245245
'&response_type=token'
246246

247247
req.open('POST', url, false)
248248
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
249249
req.setRequestHeader('Accept', 'application/json')
250+
req.setRequestHeader("Authorization", "Basic " + btoa(client_id+":"+client_secret));
250251
req.send(params)
251252
if (req.status == 200) return JSON.parse(req.responseText).access_token
252253
else {

0 commit comments

Comments
 (0)