Skip to content

Commit

Permalink
Add a test for the new_session_cb from a QUIC object
Browse files Browse the repository at this point in the history
Setting a new_session_cb should work for a QUIC object just as it does
with a normal TLS object.

Reviewed-by: Viktor Dukhovni <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#25874)
  • Loading branch information
mattcaswell authored and t8m committed Nov 7, 2024
1 parent dc84829 commit e545264
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions test/quicapitest.c
Original file line number Diff line number Diff line change
Expand Up @@ -2175,6 +2175,77 @@ static int test_tparam(int idx)
qtest_fault_free(qtf);
return testresult;
}

static int new_called = 0;
static SSL *cbssl = NULL;

static int new_session_cb(SSL *ssl, SSL_SESSION *sess)
{
new_called++;
/*
* Remember the SSL ref we were called with. No need to up-ref this. It
* should remain valid for the duration of the test.
*/
cbssl = ssl;
/*
* sess has been up-refed for us, but we don't actually need it so free it
* immediately.
*/
SSL_SESSION_free(sess);
return 1;
}

/* Test using a new_session_cb with a QUIC SSL object works as expected */
static int test_session_cb(void)
{
SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
SSL *clientquic = NULL;
QUIC_TSERVER *qtserv = NULL;
int testresult = 0;

if (!TEST_ptr(cctx))
goto err;

new_called = 0;
cbssl = NULL;
SSL_CTX_sess_set_new_cb(cctx, new_session_cb);
SSL_CTX_set_session_cache_mode(cctx, SSL_SESS_CACHE_CLIENT);

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

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

/* Process the pending NewSessionTickets */
if (!TEST_true(SSL_handle_events(clientquic)))
goto err;

if (!TEST_int_eq(SSL_shutdown(clientquic), 0))
goto err;

/*
* Check the callback was called twice (we expect 2 tickets), and with the
* correct SSL reference
*/
if (!TEST_int_eq(new_called, 2)
|| !TEST_ptr_eq(clientquic, cbssl))
goto err;

testresult = 1;
err:
cbssl = NULL;
ossl_quic_tserver_free(qtserv);
SSL_free(clientquic);
SSL_CTX_free(cctx);

return testresult;
}

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

OPT_TEST_DECLARE_USAGE("provider config certsdir datadir\n")
Expand Down Expand Up @@ -2267,6 +2338,7 @@ int setup_tests(void)
ADD_TEST(test_bw_limit);
ADD_TEST(test_get_shutdown);
ADD_ALL_TESTS(test_tparam, OSSL_NELEM(tparam_tests));
ADD_TEST(test_session_cb);

return 1;
err:
Expand Down

0 comments on commit e545264

Please sign in to comment.