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

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 1d6b19dbdda Add more test cases for FirebirdSRPAuthenticationDataTest 
(#38164)
1d6b19dbdda is described below

commit 1d6b19dbdda4d42eb862d57fcd5f7a3b238d9d1e
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Feb 23 20:55:17 2026 +0800

    Add more test cases for FirebirdSRPAuthenticationDataTest (#38164)
---
 .../handshake/FirebirdSRPAuthenticationData.java   |  2 -
 .../FirebirdSRPAuthenticationDataTest.java         | 77 ++++++++++++++++++----
 2 files changed, 66 insertions(+), 13 deletions(-)

diff --git 
a/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdSRPAuthenticationData.java
 
b/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdSRPAuthenticationData.java
index 8e55f24f252..2156ade0c88 100644
--- 
a/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdSRPAuthenticationData.java
+++ 
b/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdSRPAuthenticationData.java
@@ -44,8 +44,6 @@ public final class FirebirdSRPAuthenticationData {
     
     private static final int SRP_SALT_SIZE = 32;
     
-    private static final int EXPECTED_AUTH_DATA_LENGTH = (SRP_SALT_SIZE + 
SRP_KEY_SIZE + 2) * 2;
-    
     private static final BigInteger N = new 
BigInteger("E67D2E994B2F900C3F41F08F5BB2627ED0D49EE1FE767A52EFCD565CD6E768812C3E1E9CE8F0A8BEA6CB13CD29DDEBF7A96D4A93B55D488DF"
             + 
"099A15C89DCB0640738EB2CBDD9A8F7BAB561AB1B0DC1C6CDABF303264A08D1BCA932D1F1EE428B619D970F342ABA9A65793B8B2F041AE5364350C16F735F56ECBCA87BD57B29E7",
 16);
     
diff --git 
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdSRPAuthenticationDataTest.java
 
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdSRPAuthenticationDataTest.java
index 44c0c8661e7..99af0808f4f 100644
--- 
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdSRPAuthenticationDataTest.java
+++ 
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdSRPAuthenticationDataTest.java
@@ -17,31 +17,86 @@
 
 package org.apache.shardingsphere.database.protocol.firebird.packet.handshake;
 
+import 
org.apache.shardingsphere.database.protocol.firebird.exception.FirebirdProtocolException;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.math.BigInteger;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
 
-import static org.hamcrest.Matchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 class FirebirdSRPAuthenticationDataTest {
     
-    @Test
-    void assertNormalizeLoginUppercase() {
-        assertThat(FirebirdSRPAuthenticationData.normalizeLogin("abc"), 
is("ABC"));
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("normalizeLoginArguments")
+    void assertNormalizeLogin(final String name, final String login, final 
String expectedLogin) {
+        assertThat(FirebirdSRPAuthenticationData.normalizeLogin(login), 
is(expectedLogin));
     }
     
     @Test
-    void assertNormalizeLoginQuoted() {
-        
assertThat(FirebirdSRPAuthenticationData.normalizeLogin("\"Ab\"\"c\""), 
is("Ab\"c"));
+    void assertFirebirdSRPAuthenticationData() {
+        FirebirdSRPAuthenticationData actual = new 
FirebirdSRPAuthenticationData("SHA-1", "alice", "password", "4");
+        assertThat(actual.getClientPublicKey(), is(new BigInteger("4")));
+        assertThat(actual.getClientProofHashAlgorithm(), is("SHA-1"));
+        assertNotNull(actual.getPrivateKey());
+        assertNotNull(actual.getPublicKey());
+        assertNotNull(actual.getSalt());
+        assertThat(actual.getSalt().length, is(32));
+        assertNotNull(actual.getVerifier());
+    }
+    
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("serverProofArguments")
+    void assertServerProof(final String name, final String userPublicKey, 
final String user) {
+        FirebirdSRPAuthenticationData actual = new 
FirebirdSRPAuthenticationData("SHA-1", "alice", "password", userPublicKey);
+        byte[] actualServerProof = actual.serverProof(user);
+        assertThat(actualServerProof.length, is(20));
+        assertNotNull(actual.getSessionKey());
+        assertThat(actual.getSessionKey().length, is(20));
     }
     
     @Test
-    void assertNormalizeLoginNull() {
-        assertNull(FirebirdSRPAuthenticationData.normalizeLogin(null));
+    void assertServerProofWithUnknownHashAlgorithm() {
+        FirebirdSRPAuthenticationData actual = new 
FirebirdSRPAuthenticationData("SHA-0", "alice", "password", "04");
+        assertThat(assertThrows(FirebirdProtocolException.class, () -> 
actual.serverProof("alice")).getMessage(), is("Unrecognised hash algorithm 
`SHA-0`."));
     }
     
     @Test
-    void assertNormalizeLoginEmpty() {
-        assertThat(FirebirdSRPAuthenticationData.normalizeLogin(""), is(""));
+    void assertGetPublicKeyHex() {
+        FirebirdSRPAuthenticationData actual = new 
FirebirdSRPAuthenticationData("SHA-1", "alice", "password", "04");
+        String actualPublicKeyHex = actual.getPublicKeyHex();
+        assertFalse(actualPublicKeyHex.isEmpty());
+        assertTrue(actualPublicKeyHex.matches("[0-9A-F]+"));
+        assertThat(actualPublicKeyHex.length() % 2, is(0));
+        assertTrue(actualPublicKeyHex.length() <= 256);
+    }
+    
+    private static Stream<Arguments> normalizeLoginArguments() {
+        return Stream.of(
+                Arguments.of("null", null, null),
+                Arguments.of("uppercase_unquoted", "abc", "ABC"),
+                Arguments.of("leading_quote_only", "\"Abc", "\"ABC"),
+                Arguments.of("quoted_escaped_quote", "\"Ab\"\"c\"", "Ab\"c"),
+                Arguments.of("quoted_trailing_quote", "\"Abc\"\"", "Abc"),
+                Arguments.of("quoted_unpaired_quote", "\"Ab\"c\"", "Ab"),
+                Arguments.of("empty", "", ""),
+                Arguments.of("quote_only", "\"\"", "\"\""));
+    }
+    
+    private static Stream<Arguments> serverProofArguments() {
+        return Stream.of(
+                Arguments.of("long_client_public_key", IntStream.range(0, 
130).mapToObj(i -> "AB").collect(Collectors.joining()), "CSNB"),
+                Arguments.of("zero_client_public_key", "0", "alice"),
+                Arguments.of("regular_client_public_key", "04", "alice"));
     }
 }

Reply via email to