forked from wolfSSL/wolfssl
Merge pull request #4460 from dgarske/test_init
Refactor API unit test named initializer code for `callback_functions`
This commit is contained in:
226
tests/api.c
226
tests/api.c
@ -6355,69 +6355,68 @@ static void verify_FATAL_ERROR_on_client(WOLFSSL* ssl)
|
|||||||
}
|
}
|
||||||
/* END of connection tests callbacks */
|
/* END of connection tests callbacks */
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void test_wolfSSL_UseSNI_connection(void)
|
static void test_wolfSSL_UseSNI_connection(void)
|
||||||
{
|
{
|
||||||
unsigned long i;
|
callback_functions client_cb;
|
||||||
callback_functions callbacks[] = {
|
callback_functions server_cb;
|
||||||
/* success case at ctx */
|
|
||||||
{.ctx_ready = use_SNI_at_ctx},
|
XMEMSET(&client_cb, 0, sizeof(callback_functions));
|
||||||
{.ctx_ready = use_SNI_at_ctx, .on_result = verify_SNI_real_matching},
|
XMEMSET(&server_cb, 0, sizeof(callback_functions));
|
||||||
|
client_cb.method = wolfSSLv23_client_method;
|
||||||
|
server_cb.method = wolfSSLv23_server_method;
|
||||||
|
server_cb.devId = devId;
|
||||||
|
server_cb.devId = devId;
|
||||||
|
|
||||||
/* success case at ssl */
|
/* success case at ctx */
|
||||||
{.ssl_ready = use_SNI_at_ssl, .on_result = verify_SNI_real_matching},
|
client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
|
||||||
{.ssl_ready = use_SNI_at_ssl, .on_result = verify_SNI_real_matching},
|
server_cb.ctx_ready = use_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching;
|
||||||
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
|
|
||||||
/* default mismatch behavior */
|
/* success case at ssl */
|
||||||
{.ssl_ready = different_SNI_at_ssl, .on_result = verify_FATAL_ERROR_on_client},
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_SNI_at_ssl; client_cb.on_result = verify_SNI_real_matching;
|
||||||
{.ssl_ready = use_SNI_at_ssl, .on_result = verify_UNKNOWN_SNI_on_server},
|
server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_SNI_real_matching;
|
||||||
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
|
|
||||||
/* continue on mismatch */
|
/* default mismatch behavior */
|
||||||
{.ssl_ready = different_SNI_at_ssl},
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = verify_FATAL_ERROR_on_client;
|
||||||
{.ssl_ready = use_SNI_WITH_CONTINUE_at_ssl, .on_result = verify_SNI_no_matching},
|
server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_UNKNOWN_SNI_on_server;
|
||||||
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
|
|
||||||
/* fake answer on mismatch */
|
/* continue on mismatch */
|
||||||
{.ssl_ready = different_SNI_at_ssl},
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
|
||||||
{.ssl_ready = use_SNI_WITH_FAKE_ANSWER_at_ssl, .on_result = verify_SNI_fake_matching},
|
server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_CONTINUE_at_ssl; server_cb.on_result = verify_SNI_no_matching;
|
||||||
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
|
|
||||||
/* sni abort - success */
|
/* fake answer on mismatch */
|
||||||
{.ctx_ready = use_SNI_at_ctx},
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
|
||||||
{.ctx_ready = use_MANDATORY_SNI_at_ctx, .on_result = verify_SNI_real_matching},
|
server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_FAKE_ANSWER_at_ssl; server_cb.on_result = verify_SNI_fake_matching;
|
||||||
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
|
|
||||||
/* sni abort - abort when absent (ctx) */
|
/* sni abort - success */
|
||||||
{ .on_result = verify_FATAL_ERROR_on_client},
|
client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
|
||||||
{.ctx_ready = use_MANDATORY_SNI_at_ctx, .on_result = verify_SNI_ABSENT_on_server},
|
server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching;
|
||||||
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
|
|
||||||
/* sni abort - abort when absent (ssl) */
|
/* sni abort - abort when absent (ctx) */
|
||||||
{ .on_result = verify_FATAL_ERROR_on_client},
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client;
|
||||||
{.ssl_ready = use_MANDATORY_SNI_at_ssl, .on_result = verify_SNI_ABSENT_on_server},
|
server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_ABSENT_on_server;
|
||||||
|
|
||||||
/* sni abort - success when overwritten */
|
/* sni abort - abort when absent (ssl) */
|
||||||
{.ctx_ready = NULL},
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client;
|
||||||
{.ctx_ready = use_MANDATORY_SNI_at_ctx, .ssl_ready = use_SNI_at_ssl, .on_result = verify_SNI_no_matching},
|
server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_MANDATORY_SNI_at_ssl; server_cb.on_result = verify_SNI_ABSENT_on_server;
|
||||||
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
|
|
||||||
/* sni abort - success when allowing mismatches */
|
/* sni abort - success when overwritten */
|
||||||
{.ssl_ready = different_SNI_at_ssl},
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
|
||||||
{.ctx_ready = use_PSEUDO_MANDATORY_SNI_at_ctx, .on_result = verify_SNI_fake_matching},
|
server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_SNI_no_matching;
|
||||||
};
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
|
|
||||||
for (i = 0; i < sizeof(callbacks) / sizeof(callback_functions); i += 2) {
|
/* sni abort - success when allowing mismatches */
|
||||||
callbacks[i ].method = wolfSSLv23_client_method;
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
|
||||||
callbacks[i + 1].method = wolfSSLv23_server_method;
|
server_cb.ctx_ready = use_PSEUDO_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_fake_matching;
|
||||||
callbacks[i ].devId = devId;
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
callbacks[i + 1].devId = devId;
|
|
||||||
test_wolfSSL_client_server(&callbacks[i], &callbacks[i + 1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void test_wolfSSL_SNI_GetFromBuffer(void)
|
static void test_wolfSSL_SNI_GetFromBuffer(void)
|
||||||
{
|
{
|
||||||
byte buff[] = { /* www.paypal.com */
|
byte buff[] = { /* www.paypal.com */
|
||||||
@ -6874,62 +6873,60 @@ static void verify_ALPN_client_list(WOLFSSL* ssl)
|
|||||||
AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_FreePeerProtocol(ssl, &clist));
|
AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_FreePeerProtocol(ssl, &clist));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void test_wolfSSL_UseALPN_connection(void)
|
static void test_wolfSSL_UseALPN_connection(void)
|
||||||
{
|
{
|
||||||
unsigned long i;
|
callback_functions client_cb;
|
||||||
callback_functions callbacks[] = {
|
callback_functions server_cb;
|
||||||
/* success case same list */
|
|
||||||
{.ssl_ready = use_ALPN_all},
|
XMEMSET(&client_cb, 0, sizeof(callback_functions));
|
||||||
{.ssl_ready = use_ALPN_all, .on_result = verify_ALPN_matching_http1},
|
XMEMSET(&server_cb, 0, sizeof(callback_functions));
|
||||||
|
client_cb.method = wolfSSLv23_client_method;
|
||||||
|
server_cb.method = wolfSSLv23_server_method;
|
||||||
|
server_cb.devId = devId;
|
||||||
|
server_cb.devId = devId;
|
||||||
|
|
||||||
/* success case only one for server */
|
/* success case same list */
|
||||||
{.ssl_ready = use_ALPN_all},
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
|
||||||
{.ssl_ready = use_ALPN_one, .on_result = verify_ALPN_matching_spdy2},
|
server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_matching_http1;
|
||||||
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
|
|
||||||
/* success case only one for client */
|
/* success case only one for server */
|
||||||
{.ssl_ready = use_ALPN_one},
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
|
||||||
{.ssl_ready = use_ALPN_all, .on_result = verify_ALPN_matching_spdy2},
|
server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_one; server_cb.on_result = verify_ALPN_matching_spdy2;
|
||||||
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
|
|
||||||
/* success case none for client */
|
/* success case only one for client */
|
||||||
{.ssl_ready = NULL},
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_one; client_cb.on_result = NULL;
|
||||||
{.ssl_ready = use_ALPN_all},
|
server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_matching_spdy2;
|
||||||
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
|
|
||||||
/* success case mismatch behavior but option 'continue' set */
|
/* success case none for client */
|
||||||
{.ssl_ready = use_ALPN_all_continue, .on_result = verify_ALPN_not_matching_continue},
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
|
||||||
{.ssl_ready = use_ALPN_unknown_continue},
|
server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = NULL;
|
||||||
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
|
|
||||||
/* success case read protocol send by client */
|
/* success case mismatch behavior but option 'continue' set */
|
||||||
{.ssl_ready = use_ALPN_all},
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all_continue; client_cb.on_result = verify_ALPN_not_matching_continue;
|
||||||
{.ssl_ready = use_ALPN_one, .on_result = verify_ALPN_client_list},
|
server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_unknown_continue; server_cb.on_result = NULL;
|
||||||
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
|
|
||||||
/* mismatch behavior with same list
|
/* success case read protocol send by client */
|
||||||
* the first and only this one must be taken */
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
|
||||||
{.ssl_ready = use_ALPN_all},
|
server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_one; server_cb.on_result = verify_ALPN_client_list;
|
||||||
{.ssl_ready = use_ALPN_all, .on_result = verify_ALPN_not_matching_spdy3},
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
|
|
||||||
/* default mismatch behavior */
|
/* mismatch behavior with same list
|
||||||
{.ssl_ready = use_ALPN_all},
|
* the first and only this one must be taken */
|
||||||
{.ssl_ready = use_ALPN_unknown, .on_result = verify_ALPN_FATAL_ERROR_on_client},
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
|
||||||
};
|
server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_not_matching_spdy3;
|
||||||
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
|
|
||||||
for (i = 0; i < sizeof(callbacks) / sizeof(callback_functions); i += 2) {
|
/* default mismatch behavior */
|
||||||
callbacks[i ].method = wolfSSLv23_client_method;
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
|
||||||
callbacks[i + 1].method = wolfSSLv23_server_method;
|
server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_unknown; server_cb.on_result = verify_ALPN_FATAL_ERROR_on_client;
|
||||||
callbacks[i ].devId = devId;
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
callbacks[i + 1].devId = devId;
|
|
||||||
test_wolfSSL_client_server(&callbacks[i], &callbacks[i + 1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void test_wolfSSL_UseALPN_params(void)
|
static void test_wolfSSL_UseALPN_params(void)
|
||||||
{
|
{
|
||||||
#ifndef NO_WOLFSSL_CLIENT
|
#ifndef NO_WOLFSSL_CLIENT
|
||||||
@ -7076,36 +7073,29 @@ static void verify_alpn_matching_http1(WOLFSSL* ssl)
|
|||||||
AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
|
AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void test_wolfSSL_set_alpn_protos(void)
|
static void test_wolfSSL_set_alpn_protos(void)
|
||||||
{
|
{
|
||||||
unsigned long i;
|
callback_functions client_cb;
|
||||||
callback_functions callbacks[] = {
|
callback_functions server_cb;
|
||||||
/* use CTX_alpn_protos */
|
|
||||||
{.ctx_ready = CTX_set_alpn_protos},
|
XMEMSET(&client_cb, 0, sizeof(callback_functions));
|
||||||
{.ctx_ready = CTX_set_alpn_protos, .on_result = verify_alpn_matching_http1},
|
XMEMSET(&server_cb, 0, sizeof(callback_functions));
|
||||||
/* use set_alpn_protos */
|
client_cb.method = wolfSSLv23_client_method;
|
||||||
{.ssl_ready = set_alpn_protos},
|
server_cb.method = wolfSSLv23_server_method;
|
||||||
{.ssl_ready = set_alpn_protos, .on_result = verify_alpn_matching_spdy3},
|
server_cb.devId = devId;
|
||||||
};
|
server_cb.devId = devId;
|
||||||
|
|
||||||
for (i = 0; i < sizeof(callbacks) / sizeof(callback_functions); i += 2) {
|
/* use CTX_alpn_protos */
|
||||||
callbacks[i ].method = wolfSSLv23_client_method;
|
client_cb.ctx_ready = CTX_set_alpn_protos; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
|
||||||
callbacks[i + 1].method = wolfSSLv23_server_method;
|
server_cb.ctx_ready = CTX_set_alpn_protos; server_cb.ssl_ready = NULL; server_cb.on_result = verify_alpn_matching_http1;
|
||||||
callbacks[i ].devId = devId;
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
callbacks[i + 1].devId = devId;
|
|
||||||
test_wolfSSL_client_server(&callbacks[i], &callbacks[i + 1]);
|
/* use set_alpn_protos */
|
||||||
}
|
client_cb.ctx_ready = NULL; client_cb.ssl_ready = set_alpn_protos; client_cb.on_result = NULL;
|
||||||
|
server_cb.ctx_ready = NULL; server_cb.ssl_ready = set_alpn_protos; server_cb.on_result = verify_alpn_matching_spdy3;
|
||||||
|
test_wolfSSL_client_server(&client_cb, &server_cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* HAVE_ALPN_PROTOS_SUPPORT */
|
#endif /* HAVE_ALPN_PROTOS_SUPPORT */
|
||||||
|
|
||||||
static void test_wolfSSL_UseALPN(void)
|
static void test_wolfSSL_UseALPN(void)
|
||||||
|
Reference in New Issue
Block a user