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

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


The following commit(s) were added to refs/heads/master by this push:
     new 1b79242e65 more tests for checking rule enforcement (#9936)
1b79242e65 is described below

commit 1b79242e65b048751d515b05422c56b37e19765a
Author: Fei Deng <[email protected]>
AuthorDate: Wed Jul 5 15:33:27 2023 -0500

    more tests for checking rule enforcement (#9936)
---
 proxy/http3/test/test_Http3FrameDispatcher.cc | 102 +++++++++++++++++++++++++-
 1 file changed, 101 insertions(+), 1 deletion(-)

diff --git a/proxy/http3/test/test_Http3FrameDispatcher.cc 
b/proxy/http3/test/test_Http3FrameDispatcher.cc
index dd796cd9ad..8ba980e202 100644
--- a/proxy/http3/test/test_Http3FrameDispatcher.cc
+++ b/proxy/http3/test/test_Http3FrameDispatcher.cc
@@ -57,7 +57,7 @@ TEST_CASE("Http3FrameHandler dispatch", "[http3]")
   CHECK(nread == 12);
 }
 
-TEST_CASE("dispatch SETTINGS frame", "[http3]")
+TEST_CASE("control stream tests", "[http3]")
 {
   SECTION("Only one SETTINGS frame is allowed per the control stream")
   {
@@ -143,4 +143,104 @@ TEST_CASE("dispatch SETTINGS frame", "[http3]")
     CHECK(handler.total_frame_received == 0);
     CHECK(nread == 3);
   }
+
+  SECTION("DATA frame is not allowed on control stream")
+  {
+    uint8_t input[] = {0x04,       // Type
+                       0x08,       // Length
+                       0x06,       // Identifier
+                       0x44, 0x00, // Value
+                       0x09,       // Identifier
+                       0x0f,       // Value
+                       0x4a, 0x0a, // Identifier
+                       0x00,       // Value
+                       0x00,       // Type
+                       0x04,       // Length
+                       0x11, 0x22, 0x33, 0x44};
+
+    Http3FrameDispatcher http3FrameDispatcher;
+    Http3ProtocolEnforcer enforcer;
+    Http3MockFrameHandler handler;
+
+    http3FrameDispatcher.add_handler(&enforcer);
+    http3FrameDispatcher.add_handler(&handler);
+
+    MIOBuffer *buf         = new_MIOBuffer(BUFFER_SIZE_INDEX_512);
+    IOBufferReader *reader = buf->alloc_reader();
+    uint64_t nread         = 0;
+    Http3ErrorUPtr error   = Http3ErrorUPtr(new Http3NoError());
+
+    buf->write(input, sizeof(input));
+
+    // Initial state
+    CHECK(handler.total_frame_received == 0);
+    CHECK(nread == 0);
+
+    error = http3FrameDispatcher.on_read_ready(0, Http3StreamType::CONTROL, 
*reader, nread);
+    CHECK(error->app_error_code == Http3ErrorCode::H3_FRAME_UNEXPECTED);
+    CHECK(handler.total_frame_received == 1);
+    CHECK(nread == sizeof(input));
+  }
+
+  SECTION("HEADERS frame is not allowed on control stream")
+  {
+    uint8_t input[] = {0x04,       // Type
+                       0x08,       // Length
+                       0x06,       // Identifier
+                       0x44, 0x00, // Value
+                       0x09,       // Identifier
+                       0x0f,       // Value
+                       0x4a, 0x0a, // Identifier
+                       0x00,       // Value
+                       0x01,       // Type
+                       0x04,       // Length
+                       0x11, 0x22, 0x33, 0x44};
+
+    Http3FrameDispatcher http3FrameDispatcher;
+    Http3ProtocolEnforcer enforcer;
+    Http3MockFrameHandler handler;
+
+    http3FrameDispatcher.add_handler(&enforcer);
+    http3FrameDispatcher.add_handler(&handler);
+
+    MIOBuffer *buf         = new_MIOBuffer(BUFFER_SIZE_INDEX_512);
+    IOBufferReader *reader = buf->alloc_reader();
+    uint64_t nread         = 0;
+    Http3ErrorUPtr error   = Http3ErrorUPtr(new Http3NoError());
+
+    buf->write(input, sizeof(input));
+
+    // Initial state
+    CHECK(handler.total_frame_received == 0);
+    CHECK(nread == 0);
+
+    error = http3FrameDispatcher.on_read_ready(0, Http3StreamType::CONTROL, 
*reader, nread);
+    CHECK(error->app_error_code == Http3ErrorCode::H3_FRAME_UNEXPECTED);
+    CHECK(handler.total_frame_received == 1);
+    CHECK(nread == sizeof(input));
+  }
+}
+
+TEST_CASE("ignore unknown frames", "[http3]")
+{
+  SECTION("ignore unkown frame")
+  {
+    uint8_t input[] = {
+      0x0f // Type
+    };
+
+    Http3FrameDispatcher http3FrameDispatcher;
+
+    MIOBuffer *buf         = new_MIOBuffer(BUFFER_SIZE_INDEX_512);
+    IOBufferReader *reader = buf->alloc_reader();
+    uint64_t nread         = 0;
+    Http3ErrorUPtr error   = Http3ErrorUPtr(new Http3NoError());
+
+    buf->write(input, sizeof(input));
+
+    CHECK(nread == 0);
+    error = http3FrameDispatcher.on_read_ready(0, Http3StreamType::UNKNOWN, 
*reader, nread);
+    CHECK(error->app_error_code == Http3ErrorCode::H3_NO_ERROR);
+    CHECK(nread == 0);
+  }
 }

Reply via email to