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

zhangyonglun 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 83942fd  Add a case with empty data packet (#7017) (#7048)
83942fd is described below

commit 83942fd2e7b86014aaf6986bbb205bd7af2b800e
Author: tony.li <[email protected]>
AuthorDate: Tue Aug 25 10:51:38 2020 +0700

    Add a case with empty data packet (#7017) (#7048)
---
 .../db/protocol/mysql/codec/MySQLPacketCodecEngine.java       |  2 +-
 .../db/protocol/mysql/codec/MySQLPacketCodecEngineTest.java   | 11 ++++++++++-
 .../frontend/mysql/auth/MySQLAuthenticationHandlerTest.java   |  2 +-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/codec/MySQLPacketCodecEngine.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/codec/MySQLPacketCodecEngine.java
index ac7bf82..c119c96 100644
--- 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/codec/MySQLPacketCodecEngine.java
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/codec/MySQLPacketCodecEngine.java
@@ -32,7 +32,7 @@ public final class MySQLPacketCodecEngine implements 
DatabasePacketCodecEngine<M
     
     @Override
     public boolean isValidHeader(final int readableBytes) {
-        return readableBytes > MySQLPacket.PAYLOAD_LENGTH + 
MySQLPacket.SEQUENCE_LENGTH;
+        return readableBytes >= MySQLPacket.PAYLOAD_LENGTH + 
MySQLPacket.SEQUENCE_LENGTH;
     }
     
     @Override
diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/codec/MySQLPacketCodecEngineTest.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/codec/MySQLPacketCodecEngineTest.java
index ecfb2bb..19c33ea 100644
--- 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/codec/MySQLPacketCodecEngineTest.java
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/codec/MySQLPacketCodecEngineTest.java
@@ -66,7 +66,16 @@ public final class MySQLPacketCodecEngineTest {
         new MySQLPacketCodecEngine().decode(context, byteBuf, out, 54);
         assertThat(out.size(), is(1));
     }
-    
+
+    @Test
+    public void assertDecodeWithEmptyPacket() {
+        when(byteBuf.markReaderIndex()).thenReturn(byteBuf);
+        when(byteBuf.readMediumLE()).thenReturn(0);
+        List<Object> out = new LinkedList<>();
+        new MySQLPacketCodecEngine().decode(context, byteBuf, out, 4);
+        assertThat(out.size(), is(1));
+    }
+
     @Test
     public void assertDecodeWithStickyPacket() {
         when(byteBuf.markReaderIndex()).thenReturn(byteBuf);
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
index 7adb6c7..70afb3e 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
@@ -90,7 +90,7 @@ public final class MySQLAuthenticationHandlerTest {
     @Test
     public void assertLoginWithoutPassword() {
         setAuthentication(new ProxyUser(null, null));
-        byte[] authResponse = {-27, 89, -20, -27, 65, -120, -64, -101, 86, 
-100, -108, -100, 6, -125, -37, 117, 14, -43, 95, -113};
+        byte[] authResponse = {};
         assertFalse(authenticationHandler.login("root", authResponse, 
"db1").isPresent());
     }
     

Reply via email to