mbedtls_test_ssl_endpoint_init: store user_data_n in the endpoint object
This will allow splitting the configuration and setup stages of
`mbedtls_test_ssl_endpoint_init()`, while still checking that the value is
carried over from the configuration to the session context.
No behavior change.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/tests/include/test/ssl_helpers.h b/tests/include/test/ssl_helpers.h
index dc2ab78..276b165 100644
--- a/tests/include/test/ssl_helpers.h
+++ b/tests/include/test/ssl_helpers.h
@@ -194,6 +194,7 @@
mbedtls_ssl_context ssl;
mbedtls_ssl_config conf;
mbedtls_test_mock_socket socket;
+ uintptr_t user_data_cookie; /* A unique value associated with this endpoint */
/* Objects only used by DTLS.
* They should be guarded by MBEDTLS_SSL_PROTO_DTLS, but
diff --git a/tests/src/test_helpers/ssl_helpers.c b/tests/src/test_helpers/ssl_helpers.c
index a122f35..f92b93b 100644
--- a/tests/src/test_helpers/ssl_helpers.c
+++ b/tests/src/test_helpers/ssl_helpers.c
@@ -805,7 +805,6 @@
const mbedtls_test_handshake_test_options *options)
{
int ret = -1;
- uintptr_t user_data_n;
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
const char *psk_identity = "foo";
#endif
@@ -828,10 +827,10 @@
TEST_EQUAL(mbedtls_ssl_get_user_data_n(&ep->ssl), 0);
(void) mbedtls_test_rnd_std_rand(NULL,
- (void *) &user_data_n,
- sizeof(user_data_n));
- mbedtls_ssl_conf_set_user_data_n(&ep->conf, user_data_n);
- mbedtls_ssl_set_user_data_n(&ep->ssl, user_data_n);
+ (void *) &ep->user_data_cookie,
+ sizeof(ep->user_data_cookie));
+ mbedtls_ssl_conf_set_user_data_n(&ep->conf, ep->user_data_cookie);
+ mbedtls_ssl_set_user_data_n(&ep->ssl, ep->user_data_cookie);
mbedtls_test_mock_socket_init(&(ep->socket));
@@ -965,7 +964,8 @@
}
#endif
- TEST_EQUAL(mbedtls_ssl_conf_get_user_data_n(&ep->conf), user_data_n);
+ TEST_EQUAL(mbedtls_ssl_conf_get_user_data_n(&ep->conf),
+ ep->user_data_cookie);
mbedtls_ssl_conf_set_user_data_p(&ep->conf, ep);
/* We've finished the configuration. Now set up a context. */
@@ -996,7 +996,7 @@
NULL);
}
- TEST_EQUAL(mbedtls_ssl_get_user_data_n(&ep->ssl), user_data_n);
+ TEST_EQUAL(mbedtls_ssl_get_user_data_n(&ep->ssl), ep->user_data_cookie);
mbedtls_ssl_set_user_data_p(&ep->ssl, ep);
return 0;