diff --git a/tests/test_db_sync.c b/tests/test_db_sync.c index 2f84cd33..30af5bf3 100644 --- a/tests/test_db_sync.c +++ b/tests/test_db_sync.c @@ -337,6 +337,41 @@ int main(void) { printf(" PASS\n"); // =================================================================== + // Phase 5b: ссылка ответа проходит реальный PUSH и разрешается на обоих узлах. + printf("Phase 5b: signed reply reference over PUSH\n"); + { + sqlite3_stmt* st = NULL; char original[65], json[256]; + if (sqlite3_prepare_v2(inst_a->topo_sqlite_db, + "SELECT lower(hex(message_id)) FROM push_t ORDER BY timestamp LIMIT 1", -1, &st, NULL) != SQLITE_OK + || sqlite3_step(st) != SQLITE_ROW) { + DEBUG_ERROR(DEBUG_CATEGORY_CHAT_SYNC, "reply test: original lookup failed"); + sqlite3_finalize(st); test_phase = 2; goto done; + } + snprintf(original, sizeof(original), "%s", sqlite3_column_text(st, 0)); sqlite3_finalize(st); + snprintf(json, sizeof(json), "{\"ct\":\"text/plain\",\"d\":\"Answer\",\"reply_to\":\"%s\"}", original); + uint64_t ts = db_sync_next_timestamp(si_a); uint8_t body[264], signature[64]; + memcpy(body, &ts, 8); memcpy(body + 8, json, strlen(json)); + if (sc_ed25519_sign(inst_a->my_ed25519_privkey, body, 8 + strlen(json), signature) != SC_OK + || db_sync_insert_signed(si_a, json, strlen(json), signature, 64, ts, NULL) != 0) { + DEBUG_ERROR(DEBUG_CATEGORY_CHAT_SYNC, "reply test: signed submission failed"); test_phase = 2; goto done; + } + ca_target = cb_target = 4; + if (!wait_for("reply PUSH", _cond_both_count, PHASE_TIMEOUT_TB)) { test_phase = 2; goto done; } + struct UTUN_INSTANCE* peers[] = {inst_a, inst_b}; + for (unsigned i = 0; i < 2; i++) { + const char* sql = "SELECT count(*) FROM push_t r JOIN push_t o ON " + "lower(hex(o.message_id))=json_extract(CAST(r.data AS TEXT),'$.reply_to')"; + st = NULL; + if (sqlite3_prepare_v2(peers[i]->topo_sqlite_db, sql, -1, &st, NULL) != SQLITE_OK + || sqlite3_step(st) != SQLITE_ROW || sqlite3_column_int(st, 0) != 1) { + DEBUG_ERROR(DEBUG_CATEGORY_CHAT_SYNC, "reply test: reference unresolved peer=%u", i); + sqlite3_finalize(st); test_phase = 2; goto done; + } + sqlite3_finalize(st); + } + } + printf(" signed reply resolves on sender and receiver PASS\n"); + // Phase 6: triple star — cascade notification. // =================================================================== printf("Phase 6: triple star\n");