summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Mraz <tomas@openssl.org>2023-05-11 14:08:25 +0200
committerHugo Landau <hlandau@openssl.org>2023-05-17 14:04:22 +0100
commit219db5e43c4f030a1c9c4a2f28249fd89b05ea0d (patch)
tree39a8c0b421027078688c6532227484a4c0af16d9
parent80b9eca279772185c32bb8d639af874b00217d6f (diff)
downloadopenssl-new-master.tar.gz
quic_newcid_test: Add negative test caseHEADmaster
Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/20892)
-rw-r--r--test/quic_newcid_test.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/test/quic_newcid_test.c b/test/quic_newcid_test.c
index 69f39bc833..2044209ebb 100644
--- a/test/quic_newcid_test.c
+++ b/test/quic_newcid_test.c
@@ -19,10 +19,10 @@ static char *privkey = NULL;
/*
* Inject NEW_CONNECTION_ID frame
*/
+static size_t ncid_injected;
static int add_ncid_frame_cb(QTEST_FAULT *fault, QUIC_PKT_HDR *hdr,
unsigned char *buf, size_t len, void *cbarg)
{
- static size_t done = 0;
/*
* We inject NEW_CONNECTION_ID frame to trigger change of the DCID.
* The connection id length must be 8, otherwise the tserver won't be
@@ -39,14 +39,14 @@ static int add_ncid_frame_cb(QTEST_FAULT *fault, QUIC_PKT_HDR *hdr,
};
/* We only ever add the unknown frame to one packet */
- if (done++)
+ if (ncid_injected++)
return 1;
return qtest_fault_prepend_frame(fault, new_conn_id_frame,
sizeof(new_conn_id_frame));
}
-static int test_ncid_frame(void)
+static int test_ncid_frame(int fail)
{
int testresult = 0;
SSL_CTX *cctx = SSL_CTX_new(OSSL_QUIC_client_method());
@@ -63,10 +63,11 @@ static int test_ncid_frame(void)
{0x33, 0x44, 0x55, 0x66, 0xde, 0xad, 0xbe, 0xef}
};
+ ncid_injected = 0;
if (!TEST_ptr(cctx))
goto err;
- if (!TEST_true(qtest_create_quic_objects(NULL, cctx, cert, privkey, 1,
+ if (!TEST_true(qtest_create_quic_objects(NULL, cctx, cert, privkey, 0,
&qtserv, &cssl, &fault)))
goto err;
@@ -77,7 +78,8 @@ static int test_ncid_frame(void)
goto err;
ossl_quic_tserver_tick(qtserv);
- if (!TEST_true(ossl_quic_tserver_read(qtserv, buf, sizeof(buf), &bytesread)))
+ if (!TEST_true(ossl_quic_tserver_read(qtserv, 0, buf, sizeof(buf),
+ &bytesread)))
goto err;
/*
@@ -96,12 +98,16 @@ static int test_ncid_frame(void)
add_ncid_frame_cb,
NULL)))
goto err;
- if (!TEST_true(ossl_quic_tserver_set_new_local_cid(qtserv, &conn_id)))
+ if (!fail && !TEST_true(ossl_quic_tserver_set_new_local_cid(qtserv, &conn_id)))
goto err;
- if (!TEST_true(ossl_quic_tserver_write(qtserv, (unsigned char *)msg, msglen,
+ if (!TEST_true(ossl_quic_tserver_write(qtserv, 0,
+ (unsigned char *)msg, msglen,
&byteswritten)))
goto err;
+ if (!TEST_true(ncid_injected))
+ goto err;
+
if (!TEST_size_t_eq(msglen, byteswritten))
goto err;
@@ -119,11 +125,17 @@ static int test_ncid_frame(void)
goto err;
ossl_quic_tserver_tick(qtserv);
- if (!TEST_true(ossl_quic_tserver_read(qtserv, buf, sizeof(buf), &bytesread)))
+ if (!TEST_true(ossl_quic_tserver_read(qtserv, 0, buf, sizeof(buf),
+ &bytesread)))
goto err;
- if (!TEST_mem_eq(msg, msglen, buf, bytesread))
- goto err;
+ if (fail) {
+ if (!TEST_size_t_eq(bytesread, 0))
+ goto err;
+ } else {
+ if (!TEST_mem_eq(msg, msglen, buf, bytesread))
+ goto err;
+ }
testresult = 1;
err:
@@ -156,7 +168,7 @@ int setup_tests(void)
if (privkey == NULL)
goto err;
- ADD_TEST(test_ncid_frame);
+ ADD_ALL_TESTS(test_ncid_frame, 2);
return 1;