Skip to content

Commit

Permalink
Add a test for early ticking
Browse files Browse the repository at this point in the history
Ensure that we don't inadvertently start the connection if we call
SSL_handle_events(), or SSL_get_event_timeout() early.

This adds a test for openssl#25054, which was originally fixed by openssl#25069 to
ensure we haven't broken anything by the changes in the previous commit.
  • Loading branch information
mattcaswell committed Sep 12, 2024
1 parent 7701ecc commit c1dec14
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion test/quicapitest.c
Original file line number Diff line number Diff line change
Expand Up @@ -2218,6 +2218,56 @@ static int test_domain_flags(void)
return testresult;
}

/*
* Test that calling SSL_handle_events() early behaves as expected
*/
static int test_early_ticks(void)
{
SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
SSL *clientquic = NULL;
QUIC_TSERVER *qtserv = NULL;
int testresult = 0;
struct timeval tv;
int inf = 0;

if (!TEST_ptr(cctx)
|| !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
privkey, QTEST_FLAG_FAKE_TIME,
&qtserv,
&clientquic, NULL, NULL)))
goto err;

if (!TEST_true(SSL_in_before(clientquic)))
goto err;

if (!TEST_true(SSL_handle_events(clientquic)))
goto err;

if (!TEST_true(SSL_get_event_timeout(clientquic, &tv, &inf))
|| !TEST_true(inf))
goto err;

if (!TEST_false(SSL_has_pending(clientquic))
|| !TEST_int_eq(SSL_pending(clientquic), 0))
goto err;

if (!TEST_true(SSL_in_before(clientquic)))
goto err;

if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
goto err;

if (!TEST_false(SSL_in_before(clientquic)))
goto err;

testresult = 1;
err:
SSL_free(clientquic);
SSL_CTX_free(cctx);
ossl_quic_tserver_free(qtserv);
return testresult;
}

/***********************************************************************************/

OPT_TEST_DECLARE_USAGE("provider config certsdir datadir\n")
Expand Down Expand Up @@ -2311,7 +2361,7 @@ int setup_tests(void)
ADD_TEST(test_get_shutdown);
ADD_ALL_TESTS(test_tparam, OSSL_NELEM(tparam_tests));
ADD_TEST(test_domain_flags);

ADD_TEST(test_early_ticks);
return 1;
err:
cleanup_tests();
Expand Down

0 comments on commit c1dec14

Please sign in to comment.