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/28 21:06:44 UTC
[qpid-protonj2] branch main updated: PROTON-2698 Add extra test scripting APIs for SASL connects
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 b3f467df PROTON-2698 Add extra test scripting APIs for SASL connects
b3f467df is described below
commit b3f467df30dca72e4215df7bbb8b1eeb3efadeec
Author: Timothy Bish <ta...@gmail.com>
AuthorDate: Tue Mar 28 17:06:30 2023 -0400
PROTON-2698 Add extra test scripting APIs for SASL connects
Adds scripting for SASL connects that allows lists of mechanisms to be
provided.
---
.../qpid/protonj2/client/impl/ConnectionTest.java | 2 +-
.../qpid/protonj2/test/driver/ScriptWriter.java | 54 +++++++++++++++++++++-
2 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ConnectionTest.java b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ConnectionTest.java
index a506cd74..38973302 100644
--- a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ConnectionTest.java
+++ b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ConnectionTest.java
@@ -358,7 +358,7 @@ public class ConnectionTest extends ImperativeClientTestCase {
@Test
public void testCreateConnectionWithCredentialsChoosesSASLPlainIfOffered() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer(testServerOptions())) {
- peer.expectSASLPlainConnect("user", "pass");
+ peer.expectSASLPlainConnect("user", "pass", "PLAIN", "ANONYMOUS");
peer.expectOpen().respond();
peer.expectClose().respond();
peer.start();
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 38d3a019..b620100f 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
@@ -330,6 +330,30 @@ public abstract class ScriptWriter {
* header to arrive and a header response will be sent.
*/
public void expectSASLAnonymousConnect() {
+ expectSASLAnonymousConnect("ANONYMOUS");
+ }
+
+ /**
+ * Creates all the scripted elements needed for a successful SASL Anonymous
+ * connection. The provided set of mechanisms must contain the anonymous SASL
+ * mechanism or an exception is thrown as otherwise the premise of this test
+ * method could not be met.
+ * <p>
+ * For this exchange the SASL header is expected which is responded to with the
+ * corresponding SASL header and an immediate SASL mechanisms frame that only
+ * advertises anonymous as the mechanism. It is expected that the remote will
+ * send a SASL init with the anonymous mechanism selected and the outcome is
+ * predefined as success. Once done the expectation is added for the AMQP
+ * header to arrive and a header response will be sent.
+ *
+ * @param mechanisms
+ * The set of offered SASL mechanisms which must contain "ANONYMOUS"
+ */
+ public void expectSASLAnonymousConnect(String...mechanisms) {
+ if (!Arrays.asList(mechanisms).contains("ANONYMOUS")) {
+ throw new AssertionError("The list of mechanisms must contain ANONYMOUS for this expectation to be valid.");
+ }
+
expectSASLHeader().respondWithSASLHeader();
remoteSaslMechanisms().withMechanisms("ANONYMOUS").queue();
expectSaslInit().withMechanism("ANONYMOUS");
@@ -354,6 +378,34 @@ public abstract class ScriptWriter {
* The password that is expected in the SASL Plain initial response.
*/
public void expectSASLPlainConnect(String username, String password) {
+ expectSASLPlainConnect(username, password, "PLAIN");
+ }
+
+ /**
+ * Creates all the scripted elements needed for a successful SASL Plain
+ * connection. The provided set of mechanisms must contain the plain SASL
+ * mechanism or an exception is thrown as otherwise the premise of this test
+ * method could not be met.
+ * <p>
+ * For this exchange the SASL header is expected which is responded to with the
+ * corresponding SASL header and an immediate SASL mechanisms frame that only
+ * advertises plain as the mechanism. It is expected that the remote will
+ * send a SASL init with the plain mechanism selected and the outcome is
+ * predefined as success. Once done the expectation is added for the AMQP
+ * header to arrive and a header response will be sent.
+ *
+ * @param username
+ * The user name that is expected in the SASL Plain initial response.
+ * @param password
+ * The password that is expected in the SASL Plain initial response.
+ * @param mechanisms
+ * The set of offered SASL mechanisms which must contain "PLAIN"
+ */
+ public void expectSASLPlainConnect(String username, String password, String...mechanisms) {
+ if (!Arrays.asList(mechanisms).contains("PLAIN")) {
+ throw new AssertionError("The list of mechanisms must contain PLAIN for this expectation to be valid.");
+ }
+
expectSASLHeader().respondWithSASLHeader();
remoteSaslMechanisms().withMechanisms("PLAIN").queue();
expectSaslInit().withMechanism("PLAIN").withInitialResponse(saslPlainInitialResponse(username, password));
@@ -417,7 +469,7 @@ public abstract class ScriptWriter {
* @param offeredMechanisms
* The set of mechanisms that the server should offer in the SASL Mechanisms frame
*/
- public void expectFailingSASLPlainConnect(byte saslCode, String... offeredMechanisms) {
+ public void expectFailingSASLPlainConnect(byte saslCode, String...offeredMechanisms) {
if (!Arrays.asList(offeredMechanisms).contains("PLAIN")) {
throw new AssertionError("Expected offered mechanisms that contains the PLAIN mechanism");
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org