Use authenticated block metadata in media query fixtures
This commit is contained in:
1 parent
d0a401e166
commit
d2bf40e11a
2 files changed
+29
-5
No files matched your search
@@ -52,6 +52,9 @@ static struct UTUN_INSTANCE* make_minimal(void) {
|
||||
if (media_index_init(db) || media_index_set_base(db, "/tmp")) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "timeout test media schema initialization failed"); exit(1);
|
||||
}
|
||||
if (sqlite3_exec(db, "CREATE TABLE nodes(node_id INTEGER PRIMARY KEY,ed25519_pubkey BLOB);"
|
||||
"INSERT INTO nodes VALUES(841029813740322817,zeroblob(32)),(841029813740322818,zeroblob(32))",
|
||||
NULL, NULL, NULL) != SQLITE_OK) exit(1);
|
||||
for (int i = 0; i < 32; i++) inst->my_ed25519_privkey[i] = (uint8_t)(rand() & 0xFF);
|
||||
memset(inst->my_ed25519_pubkey, 0xDD, 32);
|
||||
inst->md.inst = inst; inst->md.db = db; inst->md.self_node_id = inst->node_id; inst->md.initialized = 1;
|
||||
@@ -96,7 +99,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); }
|
||||
sqlite3_close(inst->topo_sqlite_db); u_free(inst);
|
||||
media_delivery_destroy(inst); sqlite3_close(inst->topo_sqlite_db); u_free(inst);
|
||||
}
|
||||
|
||||
/* ── 2. зависший держатель → фейловер → re-QUERY → fail ── */
|
||||
@@ -127,8 +130,7 @@ int main(void) {
|
||||
}
|
||||
|
||||
media_index_result_free(&r);
|
||||
if (inst->md.downloads) queue_free(inst->md.downloads);
|
||||
sqlite3_close(inst->topo_sqlite_db); u_free(inst);
|
||||
media_delivery_destroy(inst); sqlite3_close(inst->topo_sqlite_db); u_free(inst);
|
||||
}
|
||||
|
||||
printf("\n%d/%d passed, %d failed\n", G_PASSED, G_TOTAL, G_FAILED);
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
#include "../src/media_delivery/media_download.h"
|
||||
#include "../src/routing_layer/etcp_router.h"
|
||||
#include "../src/transport_layer/etcp.h"
|
||||
#include "../src/transport_layer/secure_channel.h"
|
||||
#include "../lib/debug_config.h"
|
||||
#include "../lib/mem.h"
|
||||
#include "../lib/platform_compat.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <openssl/evp.h>
|
||||
#ifdef __SANITIZE_ADDRESS__
|
||||
#include <sanitizer/asan_interface.h>
|
||||
#endif
|
||||
@@ -31,6 +33,7 @@ static struct UASYNC* ua;
|
||||
static char directory[256];
|
||||
static void* injected;
|
||||
static uint8_t* poison_tail;
|
||||
static uint8_t author_key[32] = {1};
|
||||
|
||||
int __real_RAND_bytes(unsigned char* out, int count);
|
||||
int __wrap_RAND_bytes(unsigned char* out, int count) {
|
||||
@@ -92,6 +95,15 @@ static struct UTUN_INSTANCE* instance(uint64_t node) {
|
||||
inst->chat_core = u_calloc(1, sizeof(struct chat_core_ctx)); REQUIRE(inst->chat_core);
|
||||
REQUIRE(sqlite3_open(":memory:", &inst->topo_sqlite_db) == SQLITE_OK);
|
||||
REQUIRE(!media_index_init(inst->topo_sqlite_db) && !media_delivery_init(inst));
|
||||
uint8_t pubkey[32]; size_t length = sizeof(pubkey);
|
||||
EVP_PKEY* key = EVP_PKEY_new_raw_private_key(EVP_PKEY_ED25519, NULL, author_key, 32); REQUIRE(key);
|
||||
REQUIRE(EVP_PKEY_get_raw_public_key(key, pubkey, &length) == 1 && length == 32); EVP_PKEY_free(key);
|
||||
REQUIRE(sqlite3_exec(inst->topo_sqlite_db, "CREATE TABLE nodes(node_id INTEGER PRIMARY KEY,ed25519_pubkey BLOB)",
|
||||
NULL, NULL, NULL) == SQLITE_OK);
|
||||
sqlite3_stmt* st = NULL;
|
||||
REQUIRE(sqlite3_prepare_v2(inst->topo_sqlite_db, "INSERT INTO nodes VALUES(256,?)", -1, &st, NULL) == SQLITE_OK);
|
||||
REQUIRE(sqlite3_bind_blob(st, 1, pubkey, 32, SQLITE_STATIC) == SQLITE_OK && sqlite3_step(st) == SQLITE_DONE);
|
||||
REQUIRE(sqlite3_finalize(st) == SQLITE_OK);
|
||||
return inst;
|
||||
}
|
||||
|
||||
@@ -106,7 +118,13 @@ static struct media_index_result result(int count) {
|
||||
struct media_index_result r = {.file_size = count, .block_size = 1, .num_blocks = count};
|
||||
memset(r.media_id, 0xAA, 16);
|
||||
r.block_ids = u_calloc(count, 16); r.block_sigs = u_calloc(count, 64); REQUIRE(r.block_ids && r.block_sigs);
|
||||
for (int i = 0; i < count; i++) { uint32_t id = (uint32_t)i + 1; memcpy(r.block_ids + i * 16, &id, 4); }
|
||||
EVP_MD_CTX* hash = EVP_MD_CTX_new(); REQUIRE(hash && EVP_DigestInit_ex(hash, EVP_sha256(), NULL) == 1);
|
||||
for (int i = 0; i < count; i++) {
|
||||
uint32_t id = (uint32_t)i + 1; uint8_t byte = (uint8_t)i; memcpy(r.block_ids + i * 16, &id, 4);
|
||||
REQUIRE(sc_ed25519_sign(author_key, &byte, 1, r.block_sigs + i * 64) == SC_OK);
|
||||
REQUIRE(EVP_DigestUpdate(hash, &byte, 1) == 1);
|
||||
}
|
||||
unsigned length; REQUIRE(EVP_DigestFinal_ex(hash, r.content_hash, &length) == 1 && length == 32); EVP_MD_CTX_free(hash);
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -245,15 +263,18 @@ static void test_partial_and_timeout(void) {
|
||||
}
|
||||
|
||||
static void deliver_block(struct UTUN_INSTANCE* c, struct media_download* dl, int bi) {
|
||||
struct packet p = {.from = 1000, .to = CLIENT, .group = GROUP, .len = MEDIA_BLOCK_CHUNK_HDR_SIZE + 1};
|
||||
struct media_download_block* b = &dl->blocks[bi];
|
||||
struct packet p = {.from = b->holders[b->holder_idx], .to = CLIENT, .group = GROUP, .len = MEDIA_BLOCK_CHUNK_HDR_SIZE + 1};
|
||||
struct media_pkt_block_chunk* chunk = (struct media_pkt_block_chunk*)p.data;
|
||||
chunk->subcmd = MEDIA_SUBCMD_BLOCK_CHUNK; chunk->chunk = bi; chunk->data_len = 1;
|
||||
memcpy(chunk->media_id, dl->media_id, 16); memcpy(chunk->block_id, dl->blocks[bi].block_id, 16);
|
||||
memcpy(chunk->transfer_id, b->transfer_id, 16);
|
||||
p.data[MEDIA_BLOCK_CHUNK_HDR_SIZE] = (uint8_t)bi; receive(c, &p);
|
||||
memset(p.data, 0, sizeof(p.data)); p.len = MEDIA_BLOCK_DONE_SIZE;
|
||||
struct media_pkt_block_done* done = (struct media_pkt_block_done*)p.data;
|
||||
done->subcmd = MEDIA_SUBCMD_BLOCK_DONE; done->chunk = bi; done->total_size = 1;
|
||||
memcpy(done->media_id, dl->media_id, 16); memcpy(done->block_id, dl->blocks[bi].block_id, 16);
|
||||
memcpy(done->transfer_id, b->transfer_id, 16);
|
||||
receive(c, &p);
|
||||
}
|
||||
|
||||
@@ -303,6 +324,7 @@ static void test_large_file_and_live_deadline(void) {
|
||||
struct media_pkt_block_chunk* ch = (struct media_pkt_block_chunk*)chunk.data;
|
||||
ch->subcmd = MEDIA_SUBCMD_BLOCK_CHUNK; ch->data_len = 1;
|
||||
memcpy(ch->media_id, r.media_id, 16); memcpy(ch->block_id, r.block_ids, 16);
|
||||
memcpy(ch->transfer_id, dl->blocks[0].transfer_id, 16);
|
||||
uint64_t stop = get_time_tb() + 5000;
|
||||
while (dl->query_deadline_tb && get_time_tb() < stop) {
|
||||
receive(c, &chunk); uasync_poll(ua, 5); REQUIRE(download(c) == dl && !done_count);
|
||||
|
||||
Reference in new issue
Block a user