-
Notifications
You must be signed in to change notification settings - Fork 912
/
AMQPFederationConnectTest.java
521 lines (443 loc) · 25.1 KB
/
AMQPFederationConnectTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.tests.integration.amqp.connect;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.ADDRESS_AUTO_DELETE;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.ADDRESS_AUTO_DELETE_DELAY;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.ADDRESS_AUTO_DELETE_MSG_COUNT;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.ADDRESS_ENABLE_DIVERT_BINDINGS;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.ADDRESS_EXCLUDES;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.ADDRESS_INCLUDES;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.ADDRESS_MAX_HOPS;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.ADD_ADDRESS_POLICY;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.ADD_QUEUE_POLICY;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.FEDERATION_CONFIGURATION;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.FEDERATION_CONTROL_LINK;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.FEDERATION_CONTROL_LINK_VALIDATION_ADDRESS;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.LARGE_MESSAGE_THRESHOLD;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.LINK_ATTACH_TIMEOUT;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.OPERATION_TYPE;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.POLICY_NAME;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.QUEUE_EXCLUDES;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.QUEUE_INCLUDES;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.QUEUE_INCLUDE_FEDERATED;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.QUEUE_PRIORITY_ADJUSTMENT;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.RECEIVER_CREDITS;
import static org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants.RECEIVER_CREDITS_LOW;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.allOf;
import java.lang.invoke.MethodHandles;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPBrokerConnectConfiguration;
import org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPFederatedBrokerConnectionElement;
import org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPFederationAddressPolicyElement;
import org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPFederationQueuePolicyElement;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConstants;
import org.apache.activemq.artemis.tests.integration.amqp.AmqpClientTestSupport;
import org.apache.activemq.artemis.utils.Wait;
import org.apache.qpid.protonj2.test.driver.ProtonTestClient;
import org.apache.qpid.protonj2.test.driver.ProtonTestServer;
import org.apache.qpid.protonj2.test.driver.matchers.messaging.MessageAnnotationsMatcher;
import org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher;
import org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpValueMatcher;
import org.hamcrest.Matchers;
import org.jgroups.util.UUID;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Tests basic connect handling of the AMQP federation feature.
*/
public class AMQPFederationConnectTest extends AmqpClientTestSupport {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@Override
protected ActiveMQServer createServer() throws Exception {
// Creates the broker used to make the outgoing connection. The port passed is for
// that brokers acceptor. The test server connected to by the broker binds to a random port.
return createServer(AMQP_PORT, false);
}
@Test(timeout = 20000)
public void testBrokerConnectsWithAnonymous() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect("PLAIN", "ANONYMOUS");
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.start();
final URI remoteURI = peer.getServerURI();
logger.info("Connect test started, peer listening on: {}", remoteURI);
// No user or pass given, it will have to select ANONYMOUS even though PLAIN also offered
AMQPBrokerConnectConfiguration amqpConnection =
new AMQPBrokerConnectConfiguration("testSimpleConnect", "tcp://" + remoteURI.getHost() + ":" + remoteURI.getPort());
amqpConnection.setReconnectAttempts(0);// No reconnects
server.getConfiguration().addAMQPConnection(amqpConnection);
server.start();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
@Test(timeout = 20000)
public void testFederatedBrokerConnectsWithPlain() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLPlainConnect("user", "pass", "PLAIN", "ANONYMOUS");
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.start();
final URI remoteURI = peer.getServerURI();
logger.info("Connect test started, peer listening on: {}", remoteURI);
AMQPBrokerConnectConfiguration amqpConnection =
new AMQPBrokerConnectConfiguration("testSimpleConnect", "tcp://" + remoteURI.getHost() + ":" + remoteURI.getPort());
amqpConnection.setReconnectAttempts(0);// No reconnects
server.getConfiguration().addAMQPConnection(amqpConnection);
amqpConnection.setUser("user");
amqpConnection.setPassword("pass");
server.start();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
@Test(timeout = 20000)
public void testFederationConfiguredCreatesControlLink() throws Exception {
final int AMQP_MIN_LARGE_MESSAGE_SIZE = 10_000;
final int AMQP_CREDITS = 100;
final int AMQP_CREDITS_LOW = 50;
final int AMQP_LINK_ATTACH_TIMEOUT = 60;
final Map<String, Object> federationConfiguration = new HashMap<>();
federationConfiguration.put(RECEIVER_CREDITS, AMQP_CREDITS);
federationConfiguration.put(RECEIVER_CREDITS_LOW, AMQP_CREDITS_LOW);
federationConfiguration.put(LARGE_MESSAGE_THRESHOLD, AMQP_MIN_LARGE_MESSAGE_SIZE);
federationConfiguration.put(LINK_ATTACH_TIMEOUT, AMQP_LINK_ATTACH_TIMEOUT);
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect("PLAIN", "ANONYMOUS");
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender()
.withDesiredCapability(AMQPFederationConstants.FEDERATION_CONTROL_LINK.toString())
.withName(allOf(containsString("Federation"), containsString("myFederation")))
.withProperty(FEDERATION_CONFIGURATION.toString(), federationConfiguration)
.withTarget().withDynamic(true)
.withCapabilities("temporary-topic")
.and()
.respond()
.withTarget().withAddress("test-control-address")
.and()
.withOfferedCapabilities(AMQPFederationConstants.FEDERATION_CONTROL_LINK.toString());
peer.start();
final URI remoteURI = peer.getServerURI();
logger.info("Connect test started, peer listening on: {}", remoteURI);
final AMQPBrokerConnectConfiguration amqpConnection = new AMQPBrokerConnectConfiguration(
"testSimpleConnect", "tcp://" + remoteURI.getHost() + ":" + remoteURI.getPort() +
"?amqpCredits=" + AMQP_CREDITS + "&amqpLowCredits=" + AMQP_CREDITS_LOW +
"&amqpMinLargeMessageSize=" + AMQP_MIN_LARGE_MESSAGE_SIZE);
amqpConnection.setReconnectAttempts(0);// No reconnects
final AMQPFederatedBrokerConnectionElement federation = new AMQPFederatedBrokerConnectionElement("myFederation");
federation.addProperty(LINK_ATTACH_TIMEOUT, AMQP_LINK_ATTACH_TIMEOUT);
amqpConnection.addElement(federation);
server.getConfiguration().addAMQPConnection(amqpConnection);
server.start();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
Wait.assertTrue(() -> server.locateQueue("test-control-address") != null);
}
}
@Test(timeout = 20000)
public void testFederationCreatesControlLinkAndClosesConnectionIfCapabilityIsAbsent() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect("PLAIN", "ANONYMOUS");
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().withDesiredCapability(AMQPFederationConstants.FEDERATION_CONTROL_LINK.toString()).respond();
peer.expectConnectionToDrop();
peer.start();
final URI remoteURI = peer.getServerURI();
logger.info("Connect test started, peer listening on: {}", remoteURI);
AMQPBrokerConnectConfiguration amqpConnection =
new AMQPBrokerConnectConfiguration("testSimpleConnect", "tcp://" + remoteURI.getHost() + ":" + remoteURI.getPort());
amqpConnection.setReconnectAttempts(0);// No reconnects
amqpConnection.addElement(new AMQPFederatedBrokerConnectionElement("test"));
server.getConfiguration().addAMQPConnection(amqpConnection);
server.start();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
@Test(timeout = 20000)
public void testFederationCreatesControlLinkAndClosesConnectionDetachIndicatesNotAuthorized() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect("PLAIN", "ANONYMOUS");
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().withDesiredCapability(FEDERATION_CONTROL_LINK.toString())
.respond()
.withOfferedCapabilities(FEDERATION_CONTROL_LINK.toString())
.withSource()
.also()
.withNullTarget();
peer.remoteDetach().withErrorCondition("amqp:unauthorized-access", "Not authroized").queue();
peer.expectDetach().optional();
peer.expectClose().optional();
// Broker reconnect and allow it to attach this time.
peer.expectSASLAnonymousConnect("PLAIN", "ANONYMOUS");
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender()
.withTarget().withDynamic(true).and()
.withDesiredCapability(FEDERATION_CONTROL_LINK.toString())
.respondInKind()
.withTarget().withAddress("dynamic-name");
peer.start();
final URI remoteURI = peer.getServerURI();
logger.info("Connect test started, peer listening on: {}", remoteURI);
AMQPBrokerConnectConfiguration amqpConnection =
new AMQPBrokerConnectConfiguration("testSimpleConnect", "tcp://" + remoteURI.getHost() + ":" + remoteURI.getPort());
amqpConnection.setReconnectAttempts(1);// One reconnects
amqpConnection.setRetryInterval(200);
amqpConnection.addElement(new AMQPFederatedBrokerConnectionElement("test"));
server.getConfiguration().addAMQPConnection(amqpConnection);
server.start();
peer.waitForScriptToComplete(10, TimeUnit.SECONDS);
server.stop();
}
}
@Test(timeout = 20000)
public void testFederationSendsReceiveFromQueuePolicyToRemoteWhenSendToIsConfigured() throws Exception {
final MessageAnnotationsMatcher maMatcher = new MessageAnnotationsMatcher(true);
maMatcher.withEntry(OPERATION_TYPE.toString(), Matchers.is(ADD_QUEUE_POLICY));
final Map<String, Object> policyMap = new LinkedHashMap<>();
final List<String> includes = new ArrayList<>();
includes.add("a");
includes.add("b");
includes.add("c");
includes.add("d");
final List<String> excludes = new ArrayList<>();
excludes.add("e");
excludes.add("f");
excludes.add("g");
excludes.add("h");
policyMap.put(POLICY_NAME, "test-policy");
policyMap.put(QUEUE_INCLUDE_FEDERATED, true);
policyMap.put(QUEUE_PRIORITY_ADJUSTMENT, 42);
policyMap.put(QUEUE_INCLUDES, includes);
policyMap.put(QUEUE_EXCLUDES, excludes);
final EncodedAmqpValueMatcher bodyMatcher = new EncodedAmqpValueMatcher(policyMap);
final TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.setMessageAnnotationsMatcher(maMatcher);
payloadMatcher.addMessageContentMatcher(bodyMatcher);
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender()
.withTarget().withDynamic(true).and()
.withDesiredCapability(FEDERATION_CONTROL_LINK.toString())
.respondInKind().withTarget().withAddress("test-dynamic");
peer.remoteFlow().withLinkCredit(10).queue();
peer.expectTransfer().withPayload(payloadMatcher);
peer.start();
final URI remoteURI = peer.getServerURI();
logger.info("Connect test started, peer listening on: {}", remoteURI);
final AMQPFederationQueuePolicyElement sendToQueue = new AMQPFederationQueuePolicyElement();
sendToQueue.setName("test-policy");
sendToQueue.setIncludeFederated(true);
sendToQueue.setPriorityAdjustment(42);
sendToQueue.addToIncludes("a", "b");
sendToQueue.addToIncludes("c", "d");
sendToQueue.addToExcludes("e", "f");
sendToQueue.addToExcludes("g", "h");
final AMQPFederatedBrokerConnectionElement element = new AMQPFederatedBrokerConnectionElement();
element.setName("test");
element.addRemoteQueuePolicy(sendToQueue);
final AMQPBrokerConnectConfiguration amqpConnection =
new AMQPBrokerConnectConfiguration("testSimpleConnect", "tcp://" + remoteURI.getHost() + ":" + remoteURI.getPort());
amqpConnection.setReconnectAttempts(0);// No reconnects
amqpConnection.addElement(element);
server.getConfiguration().addAMQPConnection(amqpConnection);
server.start();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.close();
}
}
@Test(timeout = 20000)
public void testFederationSendsReceiveFromAddressPolicyToRemoteWhenSendToIsConfigured() throws Exception {
final MessageAnnotationsMatcher maMatcher = new MessageAnnotationsMatcher(true);
maMatcher.withEntry(OPERATION_TYPE.toString(), Matchers.is(ADD_ADDRESS_POLICY));
final Map<String, Object> policyMap = new LinkedHashMap<>();
final List<String> includes = new ArrayList<>();
includes.add("include");
final List<String> excludes = new ArrayList<>();
excludes.add("exclude");
policyMap.put(POLICY_NAME, "test-policy");
policyMap.put(ADDRESS_AUTO_DELETE, true);
policyMap.put(ADDRESS_AUTO_DELETE_DELAY, 42L);
policyMap.put(ADDRESS_AUTO_DELETE_MSG_COUNT, 314L);
policyMap.put(ADDRESS_MAX_HOPS, 5);
policyMap.put(ADDRESS_ENABLE_DIVERT_BINDINGS, false);
policyMap.put(ADDRESS_INCLUDES, includes);
policyMap.put(ADDRESS_EXCLUDES, excludes);
final EncodedAmqpValueMatcher bodyMatcher = new EncodedAmqpValueMatcher(policyMap);
final TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.setMessageAnnotationsMatcher(maMatcher);
payloadMatcher.addMessageContentMatcher(bodyMatcher);
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender()
.withTarget().withDynamic(true).and()
.withDesiredCapability(FEDERATION_CONTROL_LINK.toString())
.respondInKind().withTarget().withAddress("test-dynamic");
peer.remoteFlow().withLinkCredit(10).queue();
peer.expectTransfer().withPayload(payloadMatcher);
peer.start();
final URI remoteURI = peer.getServerURI();
logger.info("Connect test started, peer listening on: {}", remoteURI);
final AMQPFederationAddressPolicyElement sendToAddress = new AMQPFederationAddressPolicyElement();
sendToAddress.setName("test-policy");
sendToAddress.setAutoDelete(true);
sendToAddress.setAutoDeleteDelay(42L);
sendToAddress.setAutoDeleteMessageCount(314L);
sendToAddress.setMaxHops(5);
sendToAddress.setEnableDivertBindings(false);
sendToAddress.addToIncludes("include");
sendToAddress.addToExcludes("exclude");
final AMQPFederatedBrokerConnectionElement element = new AMQPFederatedBrokerConnectionElement();
element.setName("test");
element.addRemoteAddressPolicy(sendToAddress);
final AMQPBrokerConnectConfiguration amqpConnection =
new AMQPBrokerConnectConfiguration("test-send-policy", "tcp://" + remoteURI.getHost() + ":" + remoteURI.getPort());
amqpConnection.setReconnectAttempts(0);// No reconnects
amqpConnection.addElement(element);
server.getConfiguration().addAMQPConnection(amqpConnection);
server.start();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.close();
}
}
@Test(timeout = 20000)
public void testConnectToBrokerFromRemoteAsFederatedSourceAndCreateControlLink() throws Exception {
server.start();
try (ProtonTestClient peer = new ProtonTestClient()) {
scriptFederationConnectToRemote(peer, "test");
peer.connect("localhost", AMQP_PORT);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectClose();
peer.remoteClose().now();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.close();
server.stop();
logger.info("Test stopped");
}
}
@Test(timeout = 20000)
public void testControlLinkPassesConnectAttemptWhenUserHasPrivledges() throws Exception {
enableSecurity(server, FEDERATION_CONTROL_LINK_VALIDATION_ADDRESS);
server.start();
try (ProtonTestClient peer = new ProtonTestClient()) {
scriptFederationConnectToRemote(peer, "test", fullUser, fullPass);
peer.connect("localhost", AMQP_PORT);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectClose();
peer.remoteClose().now();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.close();
server.stop();
logger.info("Test stopped");
}
}
@Test(timeout = 20000)
public void testControlLinkRefusesConnectAttemptWhenUseDoesNotHavePrivledgesForControlAddress() throws Exception {
enableSecurity(server, FEDERATION_CONTROL_LINK_VALIDATION_ADDRESS);
server.start();
try (ProtonTestClient peer = new ProtonTestClient()) {
scriptFederationConnectToRemoteNotAuthorizedForControlAddress(peer, "test", guestUser, guestPass);
peer.connect("localhost", AMQP_PORT);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.close();
server.stop();
logger.info("Test stopped");
}
}
// Use these methods to script the initial handshake that a broker that is establishing
// a federation connection with a remote broker instance would perform.
private void scriptFederationConnectToRemote(ProtonTestClient peer, String federationName) {
scriptFederationConnectToRemote(peer, federationName, false, null, null);
}
private void scriptFederationConnectToRemote(ProtonTestClient peer, String federationName, String username, String password) {
scriptFederationConnectToRemote(peer, federationName, true, username, password);
}
private void scriptFederationConnectToRemote(ProtonTestClient peer, String federationName, boolean auth, String username, String password) {
final String federationControlLinkName = "Federation:test:" + UUID.randomUUID().toString();
if (auth) {
peer.queueClientSaslPlainConnect(username, password);
} else {
peer.queueClientSaslAnonymousConnect();
}
peer.remoteOpen().queue();
peer.expectOpen();
peer.remoteBegin().queue();
peer.expectBegin();
peer.remoteAttach().ofSender()
.withName(federationControlLinkName)
.withDesiredCapabilities(FEDERATION_CONTROL_LINK.toString())
.withSenderSettleModeUnsettled()
.withReceivervSettlesFirst()
.withSource().also()
.withTarget().withDynamic(true)
.withDurabilityOfNone()
.withExpiryPolicyOnLinkDetach()
.withLifetimePolicyOfDeleteOnClose()
.withCapabilities("temporary-topic")
.also()
.queue();
peer.expectAttach().ofReceiver()
.withTarget()
.withAddress(notNullValue())
.also()
.withOfferedCapability(FEDERATION_CONTROL_LINK.toString());
peer.expectFlow();
}
private void scriptFederationConnectToRemoteNotAuthorizedForControlAddress(ProtonTestClient peer, String federationName, String username, String password) {
final String federationControlLinkName = "Federation:test:" + UUID.randomUUID().toString();
peer.queueClientSaslPlainConnect(username, password);
peer.remoteOpen().queue();
peer.expectOpen();
peer.remoteBegin().queue();
peer.expectBegin();
peer.remoteAttach().ofSender()
.withName(federationControlLinkName)
.withDesiredCapabilities(FEDERATION_CONTROL_LINK.toString())
.withSenderSettleModeUnsettled()
.withReceivervSettlesFirst()
.withSource().also()
.withTarget().withDynamic(true)
.withDurabilityOfNone()
.withExpiryPolicyOnLinkDetach()
.withLifetimePolicyOfDeleteOnClose()
.withCapabilities("temporary-topic")
.also()
.queue();
peer.expectAttach().ofReceiver()
.withTarget(nullValue());
peer.expectDetach().withError("amqp:unauthorized-access",
"User does not have permission to attach to the federation control address").respond();
peer.remoteClose().queue();
peer.expectClose();
}
}