You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2023/03/31 19:04:48 UTC

[qpid-protonj2] branch main updated: PROTON-2698 Fix a cut and paste and clean up some docs add a test

This is an automated email from the ASF dual-hosted git repository.

tabish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git


The following commit(s) were added to refs/heads/main by this push:
     new cc10df14 PROTON-2698 Fix a cut and paste and clean up some docs add a test
cc10df14 is described below

commit cc10df140771b2d2b91e2de0ffb9a8a8dcdae151
Author: Timothy Bish <ta...@gmail.com>
AuthorDate: Fri Mar 31 15:04:36 2023 -0400

    PROTON-2698 Fix a cut and paste and clean up some docs add a test
    
    Fixed an issue in the previous commit and add a test for it, also adds
    some additional API docs for the test script API.
---
 .../qpid/protonj2/test/driver/ScriptWriter.java    | 15 ++++++++++--
 .../protonj2/test/driver/ProtonTestServerTest.java | 27 ++++++++++++++++++++++
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/ScriptWriter.java b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/ScriptWriter.java
index b620100f..bfb593a0 100644
--- a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/ScriptWriter.java
+++ b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/ScriptWriter.java
@@ -355,7 +355,7 @@ public abstract class ScriptWriter {
         }
 
         expectSASLHeader().respondWithSASLHeader();
-        remoteSaslMechanisms().withMechanisms("ANONYMOUS").queue();
+        remoteSaslMechanisms().withMechanisms(mechanisms).queue();
         expectSaslInit().withMechanism("ANONYMOUS");
         remoteSaslOutcome().withCode(SaslCode.OK).queue();
         expectAMQPHeader().respondWithAMQPHeader();
@@ -407,7 +407,7 @@ public abstract class ScriptWriter {
         }
 
         expectSASLHeader().respondWithSASLHeader();
-        remoteSaslMechanisms().withMechanisms("PLAIN").queue();
+        remoteSaslMechanisms().withMechanisms(mechanisms).queue();
         expectSaslInit().withMechanism("PLAIN").withInitialResponse(saslPlainInitialResponse(username, password));
         remoteSaslOutcome().withCode(SaslCode.OK).queue();
         expectAMQPHeader().respondWithAMQPHeader();
@@ -644,6 +644,17 @@ public abstract class ScriptWriter {
 
     //----- Out of band script actions for user code
 
+    /**
+     * Allows for a user defined bit of code to be executed during the test script
+     * in response to some incoming frame or as scripted after a given delay etc.
+     * The action will be performed on the event thread of the peer outside the
+     * thread that the tests run in.
+     *
+     * @param action
+     * 		The {@link Runnable} action to be performed.
+     *
+     * @return the action instance which can either be queued or triggered immediately.
+     */
     public ExecuteUserCodeAction execute(Runnable action) {
         return new ExecuteUserCodeAction(getDriver(), action);
     }
diff --git a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/ProtonTestServerTest.java b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/ProtonTestServerTest.java
index 13e90717..21f2c812 100644
--- a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/ProtonTestServerTest.java
+++ b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/ProtonTestServerTest.java
@@ -24,6 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 import java.net.URI;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.qpid.protonj2.test.driver.codec.security.SaslCode;
 import org.apache.qpid.protonj2.test.driver.codec.transport.AMQPHeader;
 import org.apache.qpid.protonj2.test.driver.utils.TestPeerTestsBase;
 import org.junit.jupiter.api.Test;
@@ -94,4 +95,30 @@ public class ProtonTestServerTest extends TestPeerTestsBase {
             client.close();
         }
     }
+
+    @Test
+    public void testServerExpectsSaslPlainConnectOffersMoreThanPlain() throws Exception {
+        try (ProtonTestServer peer = new ProtonTestServer()) {
+            peer.expectSASLPlainConnect("user", "pass", "EXTERNAL", "PLAIN", "ANONYMOUS");
+            peer.start();
+
+            URI remoteURI = peer.getServerURI();
+
+            try (ProtonTestClient client = new ProtonTestClient()) {
+                client.connect(remoteURI.getHost(), remoteURI.getPort());
+                client.expectSASLHeader();
+                client.expectSaslMechanisms().withSaslServerMechanisms("EXTERNAL", "PLAIN", "ANONYMOUS");
+                client.remoteSaslInit().withMechanism("PLAIN").withInitialResponse(peer.saslPlainInitialResponse("user", "pass")).queue();
+                client.expectSaslOutcome().withCode(SaslCode.OK);
+                client.remoteHeader(AMQPHeader.getAMQPHeader()).queue();
+
+                // Start the exchange with the client SASL header
+                client.remoteHeader(AMQPHeader.getSASLHeader()).now();
+
+                client.waitForScriptToComplete(5, TimeUnit.SECONDS);
+            }
+
+            peer.waitForScriptToComplete();
+        }
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org