Skip to content

Commit

Permalink
quic_newcid_test: Add negative test case
Browse files Browse the repository at this point in the history
  • Loading branch information
t8m committed May 11, 2023
1 parent b69ceeb commit aa38794
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions test/quic_newcid_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
Expand All @@ -63,6 +63,7 @@ static int test_ncid_frame(void)
{0x33, 0x44, 0x55, 0x66, 0xde, 0xad, 0xbe, 0xef}
};

ncid_injected = 0;
if (!TEST_ptr(cctx))
goto err;

Expand Down Expand Up @@ -96,12 +97,15 @@ 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,
&byteswritten)))
goto err;

if (!TEST_true(ncid_injected))
goto err;

if (!TEST_size_t_eq(msglen, byteswritten))
goto err;

Expand All @@ -122,8 +126,13 @@ static int test_ncid_frame(void)
if (!TEST_true(ossl_quic_tserver_read(qtserv, 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:
Expand Down Expand Up @@ -156,7 +165,7 @@ int setup_tests(void)
if (privkey == NULL)
goto err;

ADD_TEST(test_ncid_frame);
ADD_ALL_TESTS(test_ncid_frame, 2);

return 1;

Expand Down

0 comments on commit aa38794

Please sign in to comment.