Add a qtest_check_server_transport_err helper function
authorMatt Caswell <matt@openssl.org>
Wed, 11 Jan 2023 16:04:25 +0000 (16:04 +0000)
committerHugo Landau <hlandau@openssl.org>
Wed, 22 Feb 2023 05:34:05 +0000 (05:34 +0000)
Allows tests to check that a given transport error was received by the
server.

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20030)

test/helpers/quictestlib.c
test/helpers/quictestlib.h

index 423e50f29f16f49502e1c0c3ad2c537625482d8f..ca3719c267553ed2b6780a71799cd2c876e0b529 100644 (file)
@@ -203,24 +203,31 @@ int qtest_create_quic_connection(QUIC_TSERVER *qtserv, SSL *clientssl)
     return ret;
 }
 
-int qtest_check_server_protocol_err(QUIC_TSERVER *qtserv)
+int qtest_check_server_transport_err(QUIC_TSERVER *qtserv, uint64_t code)
 {
     QUIC_TERMINATE_CAUSE cause;
 
     ossl_quic_tserver_tick(qtserv);
 
     /*
-     * Check that the server has received the protocol violation error
-     * connection close from the client
+     * Check that the server has closed with the specified code from the client
      */
-    if (!TEST_true(ossl_quic_tserver_is_term_any(qtserv, &cause))
-            || !TEST_true(cause.remote)
-            || !TEST_uint64_t_eq(cause.error_code, QUIC_ERR_PROTOCOL_VIOLATION))
+    if (!TEST_true(ossl_quic_tserver_is_term_any(qtserv)))
+        return 0;
+
+    cause = ossl_quic_tserver_get_terminate_cause(qtserv);
+    if  (!TEST_true(cause.remote)
+            || !TEST_uint64_t_eq(cause.error_code, code))
         return 0;
 
     return 1;
 }
 
+int qtest_check_server_protocol_err(QUIC_TSERVER *qtserv)
+{
+    return qtest_check_server_transport_err(qtserv, QUIC_ERR_PROTOCOL_VIOLATION);
+}
+
 void ossl_quic_fault_free(OSSL_QUIC_FAULT *fault)
 {
     if (fault == NULL)
index 7cfbb6ce95f8bf5a564d667cc0d3a89a056135a2..2737e5857275bd3872ab16225c8efd10d62975c6 100644 (file)
@@ -45,7 +45,13 @@ void ossl_quic_fault_free(OSSL_QUIC_FAULT *fault);
 int qtest_create_quic_connection(QUIC_TSERVER *qtserv, SSL *clientssl);
 
 /*
- * Confirm the server has received a protocol error
+ * Confirm that the server has received the given transport error code.
+ */
+int qtest_check_server_transport_err(QUIC_TSERVER *qtserv, uint64_t code);
+
+/*
+ * Confirm the server has received a protocol error. Equivalent to calling
+ * qtest_check_server_transport_err with a code of QUIC_ERR_PROTOCOL_VIOLATION
  */
 int qtest_check_server_protocol_err(QUIC_TSERVER *qtserv);