NO-JIRA: consolidate the SASL handling prior to rejecting a connection
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/a91170e2 Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/a91170e2 Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/a91170e2 Branch: refs/heads/master Commit: a91170e29270193619abff3a96a13577a5c62d42 Parents: a5e049a Author: Robert Gemmell <[email protected]> Authored: Tue Jun 16 12:18:47 2015 +0100 Committer: Robert Gemmell <[email protected]> Committed: Tue Jun 16 12:18:47 2015 +0100 ---------------------------------------------------------------------- .../qpid/jms/test/testpeer/TestAmqpPeer.java | 48 +++++--------------- 1 file changed, 12 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/a91170e2/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java index b1aad6d..164d2ee 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java @@ -482,7 +482,12 @@ public class TestAmqpPeer implements AutoCloseable public void expectSaslAnonymousConnect(Matcher<?> idleTimeoutMatcher, Matcher<?> hostnameMatcher) { - expectSaslConnect(ANONYMOUS, equalTo(new Binary(new byte[0])), new Symbol[] { AmqpSupport.SOLE_CONNECTION_CAPABILITY }, null, null, idleTimeoutMatcher, hostnameMatcher); + expectSaslAnonymousConnect(idleTimeoutMatcher, hostnameMatcher, null); + } + + public void expectSaslAnonymousConnect(Matcher<?> idleTimeoutMatcher, Matcher<?> hostnameMatcher, Map<Symbol, Object> serverProperties) + { + expectSaslConnect(ANONYMOUS, equalTo(new Binary(new byte[0])), new Symbol[] { AmqpSupport.SOLE_CONNECTION_CAPABILITY }, null, serverProperties, idleTimeoutMatcher, hostnameMatcher); } public void expectFailingSaslConnect(Symbol[] serverMechs, Symbol clientSelectedMech) @@ -531,44 +536,14 @@ public class TestAmqpPeer implements AutoCloseable addHandler(openMatcher); } - // TODO - Reject any incoming connection using the supplied information public void rejectConnect(Symbol errorType, String errorMessage, Map<Symbol, Object> errorInfo) { - SaslMechanismsFrame saslMechanismsFrame = new SaslMechanismsFrame().setSaslServerMechanisms(ANONYMOUS); - addHandler(new HeaderHandlerImpl(AmqpHeader.SASL_HEADER, AmqpHeader.SASL_HEADER, - new FrameSender( - this, FrameType.SASL, 0, - saslMechanismsFrame, null))); - - addHandler(new SaslInitMatcher() - .withMechanism(equalTo(ANONYMOUS)) - .withInitialResponse(equalTo(new Binary(new byte[0]))) - .onSuccess(new AmqpPeerRunnable() - { - @Override - public void run() - { - TestAmqpPeer.this.sendFrame( - FrameType.SASL, 0, - new SaslOutcomeFrame().setCode(SASL_OK), - null, - false); - _driverRunnable.expectHeader(); - } - })); + // Expect a connection, establish through the SASL negotiation and sending of the Open frame + Map<Symbol, Object> serverProperties = new HashMap<Symbol, Object>(); + serverProperties.put(AmqpSupport.CONNECTION_OPEN_FAILED, true); - addHandler(new HeaderHandlerImpl(AmqpHeader.HEADER, AmqpHeader.HEADER)); - - Map<Symbol, Object> properties = new HashMap<Symbol, Object>(); - properties.put(Symbol.valueOf("amqp:connection-establishment-failed"), true); - - OpenFrame open = createOpenFrame(); - open.setProperties(properties); - - addHandler(new OpenMatcher() - .withContainerId(notNullValue(String.class)) - .onSuccess(new FrameSender(this, FrameType.AMQP, CONNECTION_CHANNEL, open, null))); + expectSaslAnonymousConnect(null, null, serverProperties); - // Now generate the Close with the supplied error + // Now generate the Close frame with the supplied error final CloseFrame closeFrame = new CloseFrame(); if (errorType != null) { org.apache.qpid.jms.test.testpeer.describedtypes.Error detachError = new org.apache.qpid.jms.test.testpeer.describedtypes.Error(); @@ -578,6 +553,7 @@ public class TestAmqpPeer implements AutoCloseable closeFrame.setError(detachError); } + // Update the handler to send the Close frame after the Open frame. CompositeAmqpPeerRunnable comp = insertCompsiteActionForLastHandler(); final FrameSender closeSender = new FrameSender(this, FrameType.AMQP, CONNECTION_CHANNEL, closeFrame, null); comp.add(closeSender); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
