diff --git a/test/quicapitest.c b/test/quicapitest.c index 2e1e8900bed757..cc201fdb6f2284 100644 --- a/test/quicapitest.c +++ b/test/quicapitest.c @@ -933,6 +933,64 @@ static int test_back_pressure(void) return testresult; } + +static int conn_close_ctr = 0; + +static void conn_close_cb(int write_p, int version, int content_type, + const void *buf, size_t msglen, SSL *ssl, void *arg) +{ + PACKET pkt; + uint64_t frame_type; + + if (!write_p) + return; + + if (content_type != SSL3_RT_QUIC_FRAME_FULL + && content_type != SSL3_RT_QUIC_FRAME_HEADER) + return; + + if (!PACKET_buf_init(&pkt, buf, msglen)) + return; + + if (!ossl_quic_wire_peek_frame_header(&pkt, &frame_type, NULL)) + return; + + if (frame_type == OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_TRANSPORT) + conn_close_ctr++; +} + +/* Test that we only get one CONNECTION_CLOSE when we only expect one */ +static int test_conn_close(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) + || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert, + privkey, 0, &qtserv, + &clientquic, NULL)) + || !TEST_true(qtest_create_quic_connection(qtserv, clientquic))) + goto err; + + conn_close_ctr = 0; + SSL_set_msg_callback(clientquic, conn_close_cb); + SSL_shutdown(clientquic); + SSL_handle_events(clientquic); + if (!TEST_int_eq(conn_close_ctr, 1)) + goto err; + + testresult = 1; + err: + SSL_free(clientquic); + ossl_quic_tserver_free(qtserv); + SSL_CTX_free(cctx); + + return testresult; +} + + OPT_TEST_DECLARE_USAGE("provider config certsdir datadir\n") int setup_tests(void) @@ -1001,6 +1059,7 @@ int setup_tests(void) ADD_ALL_TESTS(test_quic_set_fd, 3); ADD_TEST(test_bio_ssl); ADD_TEST(test_back_pressure); + ADD_TEST(test_conn_close); return 1; err: cleanup_tests();