]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[(no branch, rebasing 1798-remove-tls-stream-clear-operation)] [#1798] Added same...
authorFrancis Dupont <fdupont@isc.org>
Wed, 14 Apr 2021 15:52:54 +0000 (17:52 +0200)
committerFrancis Dupont <fdupont@isc.org>
Tue, 11 May 2021 16:02:34 +0000 (18:02 +0200)
src/lib/http/tests/server_client_unittests.cc
src/lib/http/tests/tls_client_unittests.cc

index b6af68e24ab092ca4923a47203c68f9e80590729..4b466a0e3f719e2fb744f41038c6e0678307d18f 100644 (file)
@@ -1055,7 +1055,8 @@ public:
     }
 
     /// @brief Test that two consecutive requests can be sent over the same
-    /// connection.
+    /// connection (if persistent, if not persistent two connections will
+    /// be used).
     ///
     /// @param version HTTP version to be used.
     void testConsecutiveRequests(const HttpVersion& version) {
@@ -1171,6 +1172,66 @@ public:
         EXPECT_NE(sequence1->intValue(), sequence2->intValue());
     }
 
+    /// @brief Test that the client can communicate with the same destination
+    /// address and port but with different TLS contexts so
+    void testMultipleTlsContexts() {
+        // Start only one server.
+        ASSERT_NO_THROW(listener_.start());
+
+        // Create the client.
+        HttpClient client(io_service_);
+
+        // Specify the URL on which the server is available.
+        Url url("http://127.0.0.1:18123");
+
+        // Create a request to the first server.
+        PostHttpRequestJsonPtr request1 = createRequest("sequence", 1);
+        HttpResponseJsonPtr response1(new HttpResponseJson());
+        unsigned resp_num = 0;
+        ASSERT_NO_THROW(client.asyncSendRequest(url, TlsContextPtr(),
+                                                request1, response1,
+            [this, &resp_num](const boost::system::error_code& ec,
+                              const HttpResponsePtr&,
+                              const std::string&) {
+            if (++resp_num > 1) {
+                io_service_.stop();
+            }
+            if (ec) {
+                ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
+            }
+        }));
+
+        // Create a request with the second TLS context.
+        PostHttpRequestJsonPtr request2 = createRequest("sequence", 2);
+        HttpResponseJsonPtr response2(new HttpResponseJson());
+        ASSERT_NO_THROW(client.asyncSendRequest(url, TlsContextPtr(),
+                                                request2, response2,
+            [this, &resp_num](const boost::system::error_code& ec,
+                              const HttpResponsePtr&,
+                              const std::string&) {
+            if (++resp_num > 1) {
+                io_service_.stop();
+            }
+            if (ec) {
+                ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
+            }
+        }));
+
+        // Actually trigger the requests.
+        ASSERT_NO_THROW(runIOService());
+
+        // Make sure we have received two different responses.
+        ASSERT_TRUE(response1);
+        ConstElementPtr sequence1 = response1->getJsonElement("sequence");
+        ASSERT_TRUE(sequence1);
+
+        ASSERT_TRUE(response2);
+        ConstElementPtr sequence2 = response2->getJsonElement("sequence");
+        ASSERT_TRUE(sequence2);
+
+        EXPECT_NE(sequence1->intValue(), sequence2->intValue());
+    }
+
     /// @brief Test that idle connection can be resumed for second request.
     void testIdleConnection() {
         // Start the server that has short idle timeout. It closes the idle
@@ -1851,6 +1912,19 @@ TEST_F(HttpClientTest, multipleDestinationsMultiThreading) {
     ASSERT_NO_FATAL_FAILURE(testMultipleDestinations());
 }
 
+// Test that the client can use two different TLS contexts to the same
+// destination address and port simultaneously.
+TEST_F(HttpClientTest, multipleTlsContexts) {
+    ASSERT_NO_FATAL_FAILURE(testMultipleTlsContexts());
+}
+
+// Test that the client can use two different TLS contexts to the same
+// destination address and port simultaneously.
+TEST_F(HttpClientTest, multipleTlsContextsMultiThreading) {
+    MultiThreadingMgr::instance().setMode(true);
+    ASSERT_NO_FATAL_FAILURE(testMultipleTlsContexts());
+}
+
 // Test that idle connection can be resumed for second request.
 TEST_F(HttpClientTest, idleConnection) {
     ASSERT_NO_FATAL_FAILURE(testIdleConnection());
index ab21dd1ba84d8685fbbd387e106e17d9e61f5df9..4a64898bfd5d6a863a24da5a33377ea9d78545ae 100644 (file)
@@ -339,7 +339,8 @@ public:
     }
 
     /// @brief Test that two consecutive requests can be sent over the same
-    /// connection.
+    /// connection (if persistent, if not persistent two connections will
+    /// be used).
     ///
     /// @param version HTTP version to be used.
     void testConsecutiveRequests(const HttpVersion& version) {
@@ -463,6 +464,70 @@ public:
         EXPECT_NE(sequence1->intValue(), sequence2->intValue());
     }
 
+    /// @brief Test that the client can communicate with the same destination
+    /// address and port but with different TLS contexts so
+    void testMultipleTlsContexts() {
+        // Start only one server.
+        ASSERT_NO_THROW(listener_->start());
+
+        // Create the client.
+        HttpClient client(io_service_);
+
+        // Create a second client context.
+        TlsContextPtr client_context2;
+        configClient(client_context2);
+
+        // Specify the URL on which the server is available.
+        Url url("http://127.0.0.1:18123");
+
+        // Create a request to the first server.
+        PostHttpRequestJsonPtr request1 = createRequest("sequence", 1);
+        HttpResponseJsonPtr response1(new HttpResponseJson());
+        unsigned resp_num = 0;
+        ASSERT_NO_THROW(client.asyncSendRequest(url, client_context_,
+                                                request1, response1,
+            [this, &resp_num](const boost::system::error_code& ec,
+                              const HttpResponsePtr&,
+                              const std::string&) {
+            if (++resp_num > 1) {
+                io_service_.stop();
+            }
+            if (ec) {
+                ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
+            }
+        }));
+
+        // Create a request with the second TLS context.
+        PostHttpRequestJsonPtr request2 = createRequest("sequence", 2);
+        HttpResponseJsonPtr response2(new HttpResponseJson());
+        ASSERT_NO_THROW(client.asyncSendRequest(url, client_context2,
+                                                request2, response2,
+            [this, &resp_num](const boost::system::error_code& ec,
+                              const HttpResponsePtr&,
+                              const std::string&) {
+            if (++resp_num > 1) {
+                io_service_.stop();
+            }
+            if (ec) {
+                ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
+            }
+        }));
+
+        // Actually trigger the requests.
+        ASSERT_NO_THROW(runIOService());
+
+        // Make sure we have received two different responses.
+        ASSERT_TRUE(response1);
+        ConstElementPtr sequence1 = response1->getJsonElement("sequence");
+        ASSERT_TRUE(sequence1);
+
+        ASSERT_TRUE(response2);
+        ConstElementPtr sequence2 = response2->getJsonElement("sequence");
+        ASSERT_TRUE(sequence2);
+
+        EXPECT_NE(sequence1->intValue(), sequence2->intValue());
+    }
+
     /// @brief Test that idle connection can be resumed for second request.
     void testIdleConnection() {
         // Start the server that has short idle timeout. It closes the idle
@@ -1184,6 +1249,19 @@ TEST_F(HttpsClientTest, multipleDestinationsMultiThreading) {
     ASSERT_NO_FATAL_FAILURE(testMultipleDestinations());
 }
 
+// Test that the client can use two different TLS contexts to the same
+// destination address and port simultaneously.
+TEST_F(HttpsClientTest, multipleTlsContexts) {
+    ASSERT_NO_FATAL_FAILURE(testMultipleTlsContexts());
+}
+
+// Test that the client can use two different TLS contexts to the same
+// destination address and port simultaneously.
+TEST_F(HttpsClientTest, multipleTlsContextsMultiThreading) {
+    MultiThreadingMgr::instance().setMode(true);
+    ASSERT_NO_FATAL_FAILURE(testMultipleTlsContexts());
+}
+
 // Test that idle connection can be resumed for second request.
 TEST_F(HttpsClientTest, idleConnection) {
     ASSERT_NO_FATAL_FAILURE(testIdleConnection());