Skip to content

Commit

Permalink
refactor(test): Require encryption for the discovery tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfr committed Nov 10, 2023
1 parent dee1a2c commit 6f5a557
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 5 deletions.
8 changes: 4 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,6 @@ if(UA_ENABLE_SUBSCRIPTIONS)
ua_add_test(server/check_local_monitored_item.c)
endif()

if(UA_ENABLE_DISCOVERY)
ua_add_test(server/check_discovery.c)
endif()

if(UA_ENABLE_PUBSUB)
ua_add_test(pubsub/check_pubsub_encoding.c)
ua_add_test(pubsub/check_pubsub_encoding_custom.c)
Expand Down Expand Up @@ -426,6 +422,10 @@ if(UA_ENABLE_ENCRYPTION)
else()
MESSAGE(WARNING "Certificate authentication with LibreSSL as crypto backend is not supported.")
endif()

if(UA_ENABLE_DISCOVERY)
ua_add_test(server/check_discovery.c)
endif()
endif()

if(UA_ENABLE_ENCRYPTION_MBEDTLS)
Expand Down
71 changes: 70 additions & 1 deletion tests/server/check_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#include <open62541/client.h>
#include <open62541/client_config_default.h>
#include <open62541/server_config_default.h>
#include <open62541/plugin/pki_default.h>

#include "server/ua_server_internal.h"
#include "../encryption/certificates.h"

#include <fcntl.h>
#include <stdio.h>
Expand Down Expand Up @@ -52,6 +54,22 @@ static void
configure_lds_server(UA_Server *pServer) {
UA_ServerConfig *config_lds = UA_Server_getConfig(pServer);

/* Load certificate and private key */
UA_ByteString certificate;
certificate.length = CERT_DER_LENGTH;
certificate.data = CERT_DER_DATA;

UA_ByteString privateKey;
privateKey.length = KEY_DER_LENGTH;
privateKey.data = KEY_DER_DATA;

UA_ServerConfig_setDefaultWithSecurityPolicies(config_lds, 4840,
&certificate, &privateKey,
NULL, 0, NULL, 0, NULL, 0);

UA_CertificateVerification_AcceptAll(&config_lds->secureChannelPKI);
UA_CertificateVerification_AcceptAll(&config_lds->sessionPKI);

config_lds->applicationDescription.applicationType =
UA_APPLICATIONTYPE_DISCOVERYSERVER;
UA_String_clear(&config_lds->applicationDescription.applicationUri);
Expand Down Expand Up @@ -119,7 +137,22 @@ setup_register(void) {

server_register = UA_Server_new();
UA_ServerConfig *config_register = UA_Server_getConfig(server_register);
UA_ServerConfig_setMinimal(config_register, 16664, NULL);

/* Load certificate and private key */
UA_ByteString certificate;
certificate.length = CERT_DER_LENGTH;
certificate.data = CERT_DER_DATA;

UA_ByteString privateKey;
privateKey.length = KEY_DER_LENGTH;
privateKey.data = KEY_DER_DATA;

UA_ServerConfig_setDefaultWithSecurityPolicies(config_register, 16664,
&certificate, &privateKey,
NULL, 0, NULL, 0, NULL, 0);

UA_CertificateVerification_AcceptAll(&config_register->secureChannelPKI);
UA_CertificateVerification_AcceptAll(&config_register->sessionPKI);

UA_String_clear(&config_register->applicationDescription.applicationUri);
config_register->applicationDescription.applicationUri =
Expand Down Expand Up @@ -150,6 +183,18 @@ registerServer(void) {
memset(&cc, 0, sizeof(UA_ClientConfig));
UA_ClientConfig_setDefault(&cc);

/* Load certificate and private key */
UA_ByteString certificate;
certificate.length = CERT_DER_LENGTH;
certificate.data = CERT_DER_DATA;

UA_ByteString privateKey;
privateKey.length = KEY_DER_LENGTH;
privateKey.data = KEY_DER_DATA;

UA_ClientConfig_setDefaultEncryption(&cc, certificate, privateKey, NULL, 0, NULL, 0);
UA_CertificateVerification_AcceptAll(&cc.certificateVerification);

*running_register = false;
THREAD_JOIN(server_thread_register);

Expand All @@ -170,6 +215,18 @@ unregisterServer(void) {
memset(&cc, 0, sizeof(UA_ClientConfig));
UA_ClientConfig_setDefault(&cc);

/* Load certificate and private key */
UA_ByteString certificate;
certificate.length = CERT_DER_LENGTH;
certificate.data = CERT_DER_DATA;

UA_ByteString privateKey;
privateKey.length = KEY_DER_LENGTH;
privateKey.data = KEY_DER_DATA;

UA_ClientConfig_setDefaultEncryption(&cc, certificate, privateKey, NULL, 0, NULL, 0);
UA_CertificateVerification_AcceptAll(&cc.certificateVerification);

*running_register = false;
THREAD_JOIN(server_thread_register);

Expand Down Expand Up @@ -204,6 +261,18 @@ Server_register_semaphore(void) {
memset(&cc, 0, sizeof(UA_ClientConfig));
UA_ClientConfig_setDefault(&cc);

/* Load certificate and private key */
UA_ByteString certificate;
certificate.length = CERT_DER_LENGTH;
certificate.data = CERT_DER_DATA;

UA_ByteString privateKey;
privateKey.length = KEY_DER_LENGTH;
privateKey.data = KEY_DER_DATA;

UA_ClientConfig_setDefaultEncryption(&cc, certificate, privateKey, NULL, 0, NULL, 0);
UA_CertificateVerification_AcceptAll(&cc.certificateVerification);

*running_register = false;
THREAD_JOIN(server_thread_register);

Expand Down

0 comments on commit 6f5a557

Please sign in to comment.