summaryrefslogtreecommitdiffstats
path: root/test/quic_tserver_test.c
diff options
context:
space:
mode:
authorHugo Landau <hlandau@openssl.org>2023-03-07 19:07:50 +0000
committerPauli <pauli@openssl.org>2023-03-22 10:14:25 +1100
commit3cc376c91e0e9d55fd3903f203dc38d0a5788380 (patch)
tree6ac1b12219a510b1dfcb6a84b6ae88012b059004 /test/quic_tserver_test.c
parent553a4e00aab3e2cc04f47678cba3cd8345e7b0e3 (diff)
QUIC: Add tests for datagram injection API
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/20451)
Diffstat (limited to 'test/quic_tserver_test.c')
-rw-r--r--test/quic_tserver_test.c65
1 files changed, 57 insertions, 8 deletions
diff --git a/test/quic_tserver_test.c b/test/quic_tserver_test.c
index e743adbeab..393b11172f 100644
--- a/test/quic_tserver_test.c
+++ b/test/quic_tserver_test.c
@@ -27,12 +27,19 @@ static int is_want(SSL *s, int ret)
return ec == SSL_ERROR_WANT_READ || ec == SSL_ERROR_WANT_WRITE;
}
-static int test_tserver(void)
+#define TEST_KIND_SIMPLE 0
+#define TEST_KIND_INJECT 1
+#define TEST_KIND_COUNT 2
+
+static unsigned char scratch_buf[2048];
+
+static int test_tserver(int test_kind)
{
int testresult = 0, ret;
int s_fd = -1, c_fd = -1;
BIO *s_net_bio = NULL, *s_net_bio_own = NULL;
BIO *c_net_bio = NULL, *c_net_bio_own = NULL;
+ BIO *c_pair_own = NULL, *s_pair_own = NULL;
QUIC_TSERVER_ARGS tserver_args = {0};
QUIC_TSERVER *tserver = NULL;
BIO_ADDR *s_addr_ = NULL;
@@ -92,6 +99,18 @@ static int test_tserver(void)
s_net_bio_own = NULL;
+ if (test_kind == TEST_KIND_INJECT) {
+ /*
+ * In inject mode we create a dgram pair to feed to the QUIC client on
+ * the read side. We don't feed anything to this, it is just a
+ * placeholder to give the client something which never returns any
+ * datagrams..
+ */
+ if (!TEST_true(BIO_new_bio_dgram_pair(&c_pair_own, 5000,
+ &s_pair_own, 5000)))
+ goto err;
+ }
+
/* Setup test client. */
c_fd = BIO_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0);
if (!TEST_int_ge(c_fd, 0))
@@ -117,12 +136,17 @@ static int test_tserver(void)
goto err;
/* Takes ownership of our reference to the BIO. */
- SSL_set0_rbio(c_ssl, c_net_bio);
-
- /* Get another reference to be transferred in the SSL_set0_wbio call. */
- if (!TEST_true(BIO_up_ref(c_net_bio))) {
- c_net_bio_own = NULL; /* SSL_free will free the first reference. */
- goto err;
+ if (test_kind == TEST_KIND_INJECT) {
+ SSL_set0_rbio(c_ssl, c_pair_own);
+ c_pair_own = NULL;
+ } else {
+ SSL_set0_rbio(c_ssl, c_net_bio);
+
+ /* Get another reference to be transferred in the SSL_set0_wbio call. */
+ if (!TEST_true(BIO_up_ref(c_net_bio))) {
+ c_net_bio_own = NULL; /* SSL_free will free the first reference. */
+ goto err;
+ }
}
SSL_set0_wbio(c_ssl, c_net_bio);
@@ -234,6 +258,29 @@ static int test_tserver(void)
*/
SSL_tick(c_ssl);
ossl_quic_tserver_tick(tserver);
+
+ if (test_kind == TEST_KIND_INJECT) {
+ BIO_MSG rmsg = {0};
+ size_t msgs_processed = 0;
+
+ for (;;) {
+ /*
+ * Manually spoonfeed received datagrams from the real BIO_dgram
+ * into QUIC via the injection interface, thereby testing the
+ * injection interface.
+ */
+ rmsg.data = scratch_buf;
+ rmsg.data_len = sizeof(scratch_buf);
+
+ if (!BIO_recvmmsg(c_net_bio, &rmsg, sizeof(rmsg), 1, 0, &msgs_processed)
+ || msgs_processed == 0 || rmsg.data_len == 0)
+ break;
+
+ if (!TEST_true(SSL_inject_net_dgram(c_ssl, rmsg.data, rmsg.data_len,
+ NULL, NULL)))
+ goto err;
+ }
+ }
}
testresult = 1;
@@ -244,6 +291,8 @@ err:
BIO_ADDR_free(s_addr_);
BIO_free(s_net_bio_own);
BIO_free(c_net_bio_own);
+ BIO_free(c_pair_own);
+ BIO_free(s_pair_own);
if (s_fd >= 0)
BIO_closesocket(s_fd);
if (c_fd >= 0)
@@ -264,6 +313,6 @@ int setup_tests(void)
|| !TEST_ptr(keyfile = test_get_argument(1)))
return 0;
- ADD_TEST(test_tserver);
+ ADD_ALL_TESTS(test_tserver, TEST_KIND_COUNT);
return 1;
}