Update download and router tests for authenticated admission
This commit is contained in:
1 parent
a3b94aff34
commit
d7630b9700
3 files changed
+24
-6
No files matched your search
@@ -60,6 +60,17 @@ static void rx_reset(uint8_t marker) {
|
||||
|
||||
// ======================== Inject helper ========================
|
||||
static struct ETCP_CONN fake_conn;
|
||||
static uint8_t g_sign_ed25519_privkey[SC_PRIVKEY_SIZE];
|
||||
|
||||
static void handshake_packet(etcp_recv_fn cb, struct UTUN_INSTANCE* inst, struct SVC_ROUTE_HDR* h) {
|
||||
int sign = (inst->router_bindings.required_crypto[h->svc_id] & ROUTER_FLAG_SIGNED) != 0;
|
||||
size_t size = sizeof(*h) + (sign ? SC_SIGN_SIZE : 0);
|
||||
struct ll_entry* e = ll_alloc_lldgram(size); if (!e) abort();
|
||||
if (sign) h->flags |= ROUTER_FLAG_SIGNED;
|
||||
memcpy(e->dgram, h, sizeof(*h)); e->len = size;
|
||||
if (sign && sc_ed25519_sign(g_sign_ed25519_privkey, e->dgram, sizeof(*h), e->dgram + sizeof(*h)) != SC_OK) abort();
|
||||
cb(&fake_conn, e);
|
||||
}
|
||||
|
||||
/* Older unit cases construct the immutable body; add the mandatory direct-hop trailer. */
|
||||
static void inject_wire(struct ETCP_CONN* conn, struct ll_entry* e) {
|
||||
@@ -81,10 +92,9 @@ static void establish(etcp_recv_fn cb, struct UTUN_INSTANCE* inst, uint64_t src,
|
||||
h.cmd = ETCP_ID_SVC_ROUTE; h.group_id = TOPO_GROUP_UTUN;
|
||||
h.src_node_id = src; h.dst_node_id = inst->node_id; h.svc_id = svc;
|
||||
h.reset_id = epoch; h.flags = ROUTER_FLAG_START;
|
||||
struct ll_entry* e = ll_alloc_lldgram(sizeof(h));
|
||||
memcpy(e->dgram, &h, sizeof(h)); e->len = sizeof(h); cb(&fake_conn, e);
|
||||
handshake_packet(cb, inst, &h);
|
||||
h.flags = ROUTER_FLAG_START | ROUTER_FLAG_RST; h.peer_reset_id = c->reset_id; h.challenge = c->pending_challenge;
|
||||
e = ll_alloc_lldgram(sizeof(h)); memcpy(e->dgram, &h, sizeof(h)); e->len = sizeof(h); cb(&fake_conn, e);
|
||||
handshake_packet(cb, inst, &h);
|
||||
}
|
||||
|
||||
static void inject(etcp_recv_fn recv_cb, struct UTUN_INSTANCE* inst,
|
||||
@@ -196,7 +206,6 @@ static int g_sign_ready = 0;
|
||||
static struct SC_MYKEYS g_sign_keys;
|
||||
static sc_context_t g_sign_ctx;
|
||||
static uint8_t g_sign_ed25519_pubkey[SC_PUBKEY_SIZE];
|
||||
static uint8_t g_sign_ed25519_privkey[SC_PRIVKEY_SIZE];
|
||||
static const uint64_t SIGNER_NODE = 0xCCCC000000000001ULL;
|
||||
|
||||
static int setup_sign_keys(void) {
|
||||
|
||||
@@ -83,6 +83,7 @@ static void test_cleanup(void) {
|
||||
/* ── минимальный UTUN_INSTANCE с media_delivery ── */
|
||||
|
||||
#include "../src/utun_instance.h"
|
||||
#include "media_members_fixture.h"
|
||||
|
||||
static struct UTUN_INSTANCE* make_minimal_instance(sqlite3* db) {
|
||||
if (media_index_init(db) || media_index_set_base(db, g_temp_dir)) {
|
||||
@@ -93,6 +94,8 @@ static struct UTUN_INSTANCE* make_minimal_instance(sqlite3* db) {
|
||||
inst->ua = g_ua;
|
||||
inst->node_id = 0xDEADBEEFDEADBEEFULL;
|
||||
inst->topo_sqlite_db = db;
|
||||
const uint64_t peers[] = {0xAAA, 0xAAAA000000000001ULL, 0x1111, 0x2222, 0x3333, 0x9001};
|
||||
media_test_group(inst, 0x1234, peers, sizeof(peers) / sizeof(*peers));
|
||||
for (int i = 0; i < 32; i++) inst->my_ed25519_privkey[i] = (uint8_t)(rand() & 0xFF);
|
||||
EVP_PKEY* author = EVP_PKEY_new_raw_private_key(EVP_PKEY_ED25519, NULL, inst->my_ed25519_privkey, 32);
|
||||
size_t key_size = 32;
|
||||
@@ -136,6 +139,7 @@ static struct media_download* make_test_dl(sqlite3* db, struct UTUN_INSTANCE* in
|
||||
dl->file_size = (int64_t)CHUNK_SIZE * num_blocks;
|
||||
dl->active = 1;
|
||||
dl->inst = inst;
|
||||
dl->group_id = 0x1234;
|
||||
dl->author_node_id = 0xAAAA000000000001ULL;
|
||||
memcpy(dl->author_pubkey, inst->my_ed25519_pubkey, 32);
|
||||
|
||||
@@ -160,6 +164,7 @@ static void free_test_dl(struct UTUN_INSTANCE* inst, struct media_download* dl)
|
||||
if (!dl) return;
|
||||
media_download_cancel(inst, dl->media_id, NULL, 0);
|
||||
media_delivery_destroy(inst);
|
||||
media_test_groups_free(inst);
|
||||
}
|
||||
|
||||
/* Полный ответ на текущую пачку; тесты задают только найденных держателей. */
|
||||
@@ -263,6 +268,7 @@ static void test_done_assembly(void) {
|
||||
if (sz == CHUNK_SIZE * 2) OK(); else FAIL("assembled size %d != %d", sz, CHUNK_SIZE * 2);
|
||||
/* dl уже освобождён через md_dl_finish */
|
||||
media_delivery_destroy(inst);
|
||||
media_test_groups_free(inst);
|
||||
sqlite3_close(db); u_free(inst);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "media_members_fixture.h"
|
||||
|
||||
/* Транспорт принимает пакет; недостижимый получатель не отвечает. */
|
||||
int __wrap_etcp_route_send(struct UTUN_INSTANCE* inst, uint64_t group, uint64_t dst,
|
||||
@@ -49,6 +50,8 @@ static struct UTUN_INSTANCE* make_minimal(void) {
|
||||
inst->node_id = 0xDEADBEEFDEADBEEFULL;
|
||||
sqlite3* db = NULL; sqlite3_open(":memory:", &db);
|
||||
inst->topo_sqlite_db = db;
|
||||
const uint64_t peers[] = {0xBADF00D00000001ULL, 0xBADF00D00000002ULL};
|
||||
media_test_group(inst, 0x1234, peers, 2);
|
||||
if (media_index_init(db) || media_index_set_base(db, "/tmp")) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "timeout test media schema initialization failed"); exit(1);
|
||||
}
|
||||
@@ -99,7 +102,7 @@ int main(void) {
|
||||
media_index_result_free(&r);
|
||||
/* нет активной загрузки после finish */
|
||||
if (inst->md.downloads) { struct ll_entry* e = inst->md.downloads->head; int n = 0; while (e) { n++; e = e->next; } if (n != 0) FAIL("downloads leftover=%d", n); }
|
||||
media_delivery_destroy(inst); sqlite3_close(inst->topo_sqlite_db); u_free(inst);
|
||||
media_delivery_destroy(inst); media_test_groups_free(inst); sqlite3_close(inst->topo_sqlite_db); u_free(inst);
|
||||
}
|
||||
|
||||
/* ── 2. зависший держатель → фейловер → re-QUERY → fail ── */
|
||||
@@ -130,7 +133,7 @@ int main(void) {
|
||||
}
|
||||
|
||||
media_index_result_free(&r);
|
||||
media_delivery_destroy(inst); sqlite3_close(inst->topo_sqlite_db); u_free(inst);
|
||||
media_delivery_destroy(inst); media_test_groups_free(inst); sqlite3_close(inst->topo_sqlite_db); u_free(inst);
|
||||
}
|
||||
|
||||
printf("\n%d/%d passed, %d failed\n", G_PASSED, G_TOTAL, G_FAILED);
|
||||
|
||||
Reference in new issue
Block a user