From: Matt Caswell Date: Thu, 12 Sep 2024 14:15:46 +0000 (+0100) Subject: Add a test for early ticking X-Git-Tag: openssl-3.5.0-alpha1~354 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=034fa85ced5bef3e6291cb1027135a31ca9b8df8;p=thirdparty%2Fopenssl.git Add a test for early ticking 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 #25054, which was originally fixed by #25069 to ensure we haven't broken anything by the changes in the previous commit. Reviewed-by: Viktor Dukhovni Reviewed-by: Saša Nedvědický (Merged from https://github.com/openssl/openssl/pull/25452) --- diff --git a/test/quicapitest.c b/test/quicapitest.c index 6eff5598954..3146c4c1eda 100644 --- a/test/quicapitest.c +++ b/test/quicapitest.c @@ -2299,6 +2299,56 @@ err: 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") @@ -2393,7 +2443,7 @@ int setup_tests(void) ADD_ALL_TESTS(test_tparam, OSSL_NELEM(tparam_tests)); ADD_TEST(test_session_cb); ADD_TEST(test_domain_flags); - + ADD_TEST(test_early_ticks); return 1; err: cleanup_tests();