Files
VerseVDI-Data-Plane/core/tests/ffi/abi_smoke.c
T

118 lines
4.9 KiB
C

#include "versevdi_core.h"
#include <assert.h>
#include <stdatomic.h>
#include <stdlib.h>
#include <string.h>
static const char MANIFEST[] =
"{\"version\":\"1\",\"purpose\":\"launch\",\"session_id\":\"session\","
"\"reconnect_sequence\":0,\"gateway\":{\"id\":\"gateway\",\"addresses\":["
"\"127.0.0.1:9\"],\"public_identity\":\"gateway.test\"},\"tunnel\":{"
"\"versions\":[\"verse-gateway-v1/1\"],\"features\":[\"control.v1\"]},"
"\"profile\":{\"id\":\"standard\",\"bounds\":{\"minimum_kbps\":1000,"
"\"target_kbps\":5000,\"maximum_kbps\":10000},\"display_mode\":null},"
"\"grant\":{\"opaque_value\":\"ggggggggggggggggggggggggggggggggggggggggggg\","
"\"expires_at\":\"2099-01-01T00:00:00Z\",\"audience\":\"audience\"},"
"\"correlation_id\":\"correlation\"}";
static const char CREDENTIAL[] =
"{\"client_device_id\":\"device\",\"device_key_id\":\"key\","
"\"certificate_chain_pem\":\"-----BEGIN CERTIFICATE-----\\nAQID\\n-----END CERTIFICATE-----\","
"\"trust_bundle_pem\":\"-----BEGIN CERTIFICATE-----\\nAQID\\n-----END CERTIFICATE-----\","
"\"expires_at\":\"2099-01-01T00:00:00Z\"}";
typedef struct smoke_context {
atomic_uint admission_calls;
atomic_uint tls_calls;
} smoke_context_t;
static verse_status_t reject_admission(
void *raw,
verse_bytes_view_t input,
uint8_t signature[64]) {
smoke_context_t *context = raw;
(void)input;
(void)signature;
atomic_fetch_add(&context->admission_calls, 1U);
return VERSE_STATUS_INTERNAL;
}
static verse_status_t reject_tls(
void *raw,
verse_bytes_view_t input,
uint8_t signature[64]) {
smoke_context_t *context = raw;
(void)input;
(void)signature;
atomic_fetch_add(&context->tls_calls, 1U);
return VERSE_STATUS_INTERNAL;
}
int main(void) {
smoke_context_t context = {0};
verse_core_config_v1_t config = {
.struct_size = sizeof(config),
.abi_version = VERSE_CORE_ABI_VERSION_1,
.context = &context,
.sign_admission = reject_admission,
.sign_tls_ed25519 = reject_tls,
};
verse_core_t *core = NULL;
assert(verse_core_abi_version() == VERSE_CORE_ABI_VERSION_1);
assert(verse_core_create_v1(NULL, &core) == VERSE_STATUS_INVALID_ARGUMENT);
assert(verse_core_create_v1(&config, NULL) == VERSE_STATUS_INVALID_ARGUMENT);
config.struct_size = 8U;
assert(verse_core_create_v1(&config, &core) == VERSE_STATUS_INVALID_ARGUMENT);
config.struct_size = sizeof(config);
config.abi_version = VERSE_CORE_ABI_VERSION_1 + 1U;
assert(verse_core_create_v1(&config, &core) == VERSE_STATUS_UNSUPPORTED_ABI);
config.abi_version = VERSE_CORE_ABI_VERSION_1;
assert(verse_core_create_v1(&config, &core) == VERSE_STATUS_OK);
assert(core != NULL);
verse_input_event_v1_t input = {
.struct_size = sizeof(input),
.abi_version = VERSE_CORE_ABI_VERSION_1,
.kind = VERSE_INPUT_KEYBOARD,
.values = {1, 0, 30},
};
assert(verse_core_send_input_v1(core, &input) == VERSE_STATUS_INVALID_STATE);
assert(verse_core_request_idr_v1(core) == VERSE_STATUS_INVALID_STATE);
char manifest[sizeof(MANIFEST)];
char credential[sizeof(CREDENTIAL)];
memcpy(manifest, MANIFEST, sizeof(manifest));
memcpy(credential, CREDENTIAL, sizeof(credential));
verse_connect_request_v1_t request = {
.struct_size = sizeof(request),
.abi_version = VERSE_CORE_ABI_VERSION_1,
.manifest_json = {(const uint8_t *)manifest, sizeof(manifest) - 1U},
.tunnel_credential_json = {(const uint8_t *)credential, sizeof(credential) - 1U},
};
assert(verse_core_connect_v1(NULL, &request) == VERSE_STATUS_INVALID_ARGUMENT);
request.struct_size = 8U;
assert(verse_core_connect_v1(core, &request) == VERSE_STATUS_INVALID_ARGUMENT);
request.struct_size = sizeof(request);
request.abi_version = VERSE_CORE_ABI_VERSION_1 + 1U;
assert(verse_core_connect_v1(core, &request) == VERSE_STATUS_UNSUPPORTED_ABI);
request.abi_version = VERSE_CORE_ABI_VERSION_1;
request.manifest_json.data = NULL;
assert(verse_core_connect_v1(core, &request) == VERSE_STATUS_INVALID_ARGUMENT);
request.manifest_json.data = (const uint8_t *)manifest;
assert(verse_core_connect_v1(core, &request) == VERSE_STATUS_TLS);
memset(manifest, 0, sizeof(manifest));
memset(credential, 0, sizeof(credential));
assert(verse_core_send_input_v1(core, &input) == VERSE_STATUS_CANCELLED);
assert(verse_core_request_idr_v1(core) == VERSE_STATUS_CANCELLED);
assert(verse_core_cancel_v1(core) == VERSE_STATUS_OK);
assert(verse_core_cancel_v1(core) == VERSE_STATUS_OK);
assert(atomic_load(&context.admission_calls) == 0U);
assert(atomic_load(&context.tls_calls) == 0U);
assert(verse_core_destroy_v1(core, 2000U) == VERSE_STATUS_OK);
assert(atomic_load(&context.admission_calls) == 0U);
assert(atomic_load(&context.tls_calls) == 0U);
return EXIT_SUCCESS;
}