From: Matt Caswell Date: Thu, 19 Apr 2018 15:44:17 +0000 (+0100) Subject: Add a test for SSL_pending() X-Git-Tag: OpenSSL_1_1_0i~172 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d2118367add0840df472f48e48be19f075a3dec0;p=openssl Add a test for SSL_pending() Reviewed-by: Rich Salz (Merged from https://github.com/openssl/openssl/pull/6021) --- diff --git a/test/sslapitest.c b/test/sslapitest.c index 77e8f2e9ad..8badd284e3 100644 --- a/test/sslapitest.c +++ b/test/sslapitest.c @@ -1208,6 +1208,61 @@ end: return testresult; } +static int test_ssl_pending(int tst) +{ + SSL_CTX *cctx = NULL, *sctx = NULL; + SSL *clientssl = NULL, *serverssl = NULL; + int testresult = 0; + char msg[] = "A test message"; + char buf[5]; + size_t written; + + if (tst == 0) { + if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(), + TLS1_VERSION, TLS_MAX_VERSION, + &sctx, &cctx, cert, privkey)) { + printf("Failed creating SSL_CTX pair\n"); + goto end; + } + } else { +#ifndef OPENSSL_NO_DTLS + if (!create_ssl_ctx_pair(DTLS_server_method(), DTLS_client_method(), + DTLS1_VERSION, DTLS_MAX_VERSION, + &sctx, &cctx, cert, privkey)) { + printf("Failed creating SSL_CTX pair\n"); + goto end; + } +#else + return 1; +#endif + } + + if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL) + || !create_ssl_connection(serverssl, clientssl)) { + printf("Failed creating connection\n"); + goto end; + } + + written = SSL_write(serverssl, msg, sizeof(msg)); + if (written != sizeof(msg) + || SSL_read(clientssl, buf, sizeof(buf)) != sizeof(buf) + || SSL_pending(clientssl) != (int)(written - sizeof(buf))) { + printf("Failed checking SSL_pending\n"); + goto end; + } + + testresult = 1; + + end: + SSL_free(serverssl); + SSL_free(clientssl); + SSL_CTX_free(sctx); + SSL_CTX_free(cctx); + + return testresult; +} + + int main(int argc, char *argv[]) { BIO *err = NULL; @@ -1244,6 +1299,7 @@ int main(int argc, char *argv[]) ADD_TEST(test_ssl_bio_change_wbio); ADD_ALL_TESTS(test_set_sigalgs, OSSL_NELEM(testsigalgs) * 2); ADD_ALL_TESTS(test_custom_exts, 2); + ADD_ALL_TESTS(test_ssl_pending, 2); testresult = run_tests(argv[0]);