70 lines
1.8 KiB
C
70 lines
1.8 KiB
C
#include "test_transport_tls.h"
|
|
#include "transport_tls.h"
|
|
#include "transport_tcp.h"
|
|
#include "test_utils.h"
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
static void test_tls_global_init() {
|
|
bool ok = tls_global_init();
|
|
// Should succeed in normal environments with OpenSSL
|
|
// May fail in minimal environments, but we just test it doesn't crash
|
|
EXPECT_TRUE(true);
|
|
}
|
|
|
|
static void test_client_connect_tls_bad_host() {
|
|
// Ensure TLS is initialized
|
|
tls_global_init();
|
|
|
|
Client* client = client_create();
|
|
EXPECT_NOT_NULL(client);
|
|
|
|
// Connecting without TLS setup should fail
|
|
bool connected = client_connect_tls(client, "192.0.2.1", 443, NULL, NULL, NULL);
|
|
EXPECT_FALSE(connected);
|
|
|
|
client_disconnect(client);
|
|
client_delete(client);
|
|
}
|
|
|
|
static void test_client_connect_tls_null_params() {
|
|
tls_global_init();
|
|
|
|
Client* client = client_create();
|
|
EXPECT_NOT_NULL(client);
|
|
|
|
bool connected = client_connect_tls(client, NULL, 0, NULL, NULL, NULL);
|
|
EXPECT_FALSE(connected);
|
|
|
|
client_disconnect(client);
|
|
client_delete(client);
|
|
}
|
|
|
|
static void test_server_create_tls_no_cert() {
|
|
Server* server = server_create(0);
|
|
if (server != NULL) {
|
|
// Trying to set up TLS without cert/key files should fail
|
|
bool ok = server_create_tls(server, "/nonexistent/cert.pem", "/nonexistent/key.pem",
|
|
"/nonexistent/ca.pem");
|
|
EXPECT_FALSE(ok);
|
|
server_delete(&server);
|
|
}
|
|
}
|
|
|
|
static void test_server_create_tls_null_files() {
|
|
Server* server = server_create(0);
|
|
if (server != NULL) {
|
|
bool ok = server_create_tls(server, NULL, NULL, NULL);
|
|
EXPECT_FALSE(ok);
|
|
server_delete(&server);
|
|
}
|
|
}
|
|
|
|
void test_transport_tls() {
|
|
test_tls_global_init();
|
|
test_client_connect_tls_bad_host();
|
|
test_client_connect_tls_null_params();
|
|
test_server_create_tls_no_cert();
|
|
test_server_create_tls_null_files();
|
|
}
|