Test typed PM delivery and strict voice attachment metadata
This commit is contained in:
1 parent
c58b92ecd7
commit
0dc2b0135a
2 files changed
+71
-7
No files matched your search
+20
-7
@@ -178,17 +178,21 @@ static int protocol_checks(struct media_test* t) {
|
||||
struct UTUN_INSTANCE* a = t->nodes[A];
|
||||
struct UTUN_INSTANCE* m = t->nodes[M];
|
||||
const uint8_t* desc = dm_message_media(t->body, t->body_len);
|
||||
uint8_t input[DM_MEDIA_DESC_SIZE + 1];
|
||||
memcpy(input, desc, DM_MEDIA_DESC_SIZE); input[DM_MEDIA_DESC_SIZE] = 'x';
|
||||
uint8_t input[DM_MEDIA_DESC_SIZE + ATTACHMENT_WIRE_MAX];
|
||||
struct attachment_info info = { .kind = ATTACHMENT_FILE, .name = "rollback.bin" };
|
||||
int metadata_len = attachment_encode(&info, input + DM_MEDIA_DESC_SIZE, ATTACHMENT_WIRE_MAX);
|
||||
if (metadata_len < 0) return -1;
|
||||
memcpy(input, desc, DM_MEDIA_DESC_SIZE);
|
||||
if (sqlite3_exec(a->topo_sqlite_db, "CREATE TEMP TRIGGER reject_dm_file BEFORE INSERT ON dm_files"
|
||||
" BEGIN SELECT RAISE(ABORT,'injected media registration failure'); END", NULL, NULL, NULL)) return -1;
|
||||
int rejected = dm_send(a, t->conv, "file", input, sizeof(input)) < 0;
|
||||
int rejected = dm_send(a, t->conv, "file", input, DM_MEDIA_DESC_SIZE + metadata_len) < 0;
|
||||
if (sqlite3_exec(a->topo_sqlite_db, "DROP TRIGGER reject_dm_file", NULL, NULL, NULL)) return -1;
|
||||
if (!rejected || value(a, "SELECT last_out_seq FROM dm_conversations") != 1 ||
|
||||
value(a, "SELECT count(*) FROM dm_messages") != 1 || value(a, "SELECT count(*) FROM dm_outbox") != 0) return -1;
|
||||
char json[8192]; size_t len;
|
||||
if (dm_list_messages_json(a, t->conv, 200, 0, json, sizeof(json), &len) ||
|
||||
!strstr(json, "\"media_status\":\"delivered\"") || !strstr(json, "\"media_path\":")) return -1;
|
||||
!strstr(json, "\"media_status\":\"delivered\"") || !strstr(json, "\"media_path\":") ||
|
||||
!strstr(json, "\"content_type\":\"audio/opus\"") || !strstr(json, "\"duration_ms\":3000")) return -1;
|
||||
uint8_t request[8 + sizeof(t->body)];
|
||||
memcpy(request, &t->ids[B], 8); memcpy(request + 8, t->body, t->body_len);
|
||||
uint8_t* metadata = (uint8_t*)dm_message_media(request + 8, t->body_len);
|
||||
@@ -212,6 +216,15 @@ static int protocol_checks(struct media_test* t) {
|
||||
}
|
||||
|
||||
/* Таймер служит heartbeat: большие криптозадачи не должны останавливать сценарий. */
|
||||
/* Одни и те же transfer/custody гарантии для разных типов вложений. */
|
||||
static int send_fixture(struct media_test* t, enum attachment_kind kind, const char* name) {
|
||||
struct attachment_info info = { .kind = kind };
|
||||
snprintf(info.name, sizeof(info.name), "%s", name);
|
||||
if (kind == ATTACHMENT_VOICE) { info.duration_ms = 3000; memset(info.waveform, 'A', 100); }
|
||||
if (kind == ATTACHMENT_VIDEO) { info.duration_ms = 3000; info.width = 640; info.height = 480; }
|
||||
return dm_send_file(t->nodes[A], t->conv, t->file, &info, 0);
|
||||
}
|
||||
|
||||
static void tick(void* arg) {
|
||||
struct media_test* t = arg;
|
||||
t->timer = NULL; t->ticks++; t->heartbeats++;
|
||||
@@ -228,7 +241,7 @@ static void tick(void* arg) {
|
||||
break;
|
||||
case 1:
|
||||
if (live(a, t->ids[B]) && live(m, t->ids[A])) {
|
||||
if (dm_send_file(a, t->conv, t->file, "direct.bin")) { failure(t, "direct file enqueue"); return; }
|
||||
if (send_fixture(t, ATTACHMENT_VOICE, "direct.opus")) { failure(t, "direct voice enqueue"); return; }
|
||||
t->phase++;
|
||||
}
|
||||
break;
|
||||
@@ -244,7 +257,7 @@ static void tick(void* arg) {
|
||||
break;
|
||||
case 3:
|
||||
if (!live(a, t->ids[B])) {
|
||||
if (dm_send_file(a, t->conv, t->file, "offline.bin")) { failure(t, "offline file enqueue"); return; }
|
||||
if (send_fixture(t, ATTACHMENT_VIDEO, "offline.mp4")) { failure(t, "offline video enqueue"); return; }
|
||||
t->phase++;
|
||||
}
|
||||
break;
|
||||
@@ -282,7 +295,7 @@ static void tick(void* arg) {
|
||||
break;
|
||||
case 7:
|
||||
if (!live(a, t->ids[B])) {
|
||||
if (dm_send_file(a, t->conv, t->file, "expires.bin")) { failure(t, "TTL file enqueue"); return; }
|
||||
if (send_fixture(t, ATTACHMENT_FILE, "expires.bin")) { failure(t, "TTL file enqueue"); return; }
|
||||
t->phase++;
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user