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

97 lines
3.6 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\":["
"\"gateway.test:443\"],\"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;
atomic_uint state_calls;
} smoke_context_t;
static verse_status_t sign_admission(
void *raw,
verse_bytes_view_t input,
uint8_t signature[64]) {
smoke_context_t *context = raw;
assert(input.length == sizeof(MANIFEST) - 1U);
memset(signature, 0xA5, 64U);
atomic_fetch_add(&context->admission_calls, 1U);
return VERSE_STATUS_OK;
}
static verse_status_t sign_tls(
void *raw,
verse_bytes_view_t input,
uint8_t signature[64]) {
smoke_context_t *context = raw;
assert(input.length == sizeof(CREDENTIAL) - 1U);
memset(signature, 0x5A, 64U);
atomic_fetch_add(&context->tls_calls, 1U);
return VERSE_STATUS_OK;
}
static void on_state(void *raw, const verse_state_event_v1_t *event) {
smoke_context_t *context = raw;
assert(event->struct_size == sizeof(*event));
assert(event->abi_version == VERSE_CORE_ABI_VERSION_1);
atomic_fetch_add(&context->state_calls, 1U);
}
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 = sign_admission,
.sign_tls_ed25519 = sign_tls,
.on_state = on_state,
};
verse_core_t *core = NULL;
assert(verse_core_abi_version() == VERSE_CORE_ABI_VERSION_1);
assert(verse_core_create_v1(&config, &core) == VERSE_STATUS_OK);
assert(core != NULL);
const 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(core, &request) == VERSE_STATUS_OK);
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_OK);
assert(verse_core_request_idr_v1(core) == VERSE_STATUS_OK);
assert(verse_core_cancel_v1(core) == VERSE_STATUS_OK);
assert(verse_core_cancel_v1(core) == VERSE_STATUS_OK);
assert(verse_core_destroy_v1(core, 2000U) == VERSE_STATUS_OK);
assert(atomic_load(&context.admission_calls) == 1U);
assert(atomic_load(&context.tls_calls) == 1U);
return EXIT_SUCCESS;
}