test(chat): cover long role histories and deletion from owner commit callbacks
This commit is contained in:
1 parent
6f6fdae4b2
commit
8d46d9aa10
1 file changed
+36
-1
@@ -469,6 +469,41 @@ static void tags_semantics(struct UTUN_INSTANCE* inst) {
|
||||
puts("PASS tags:stale editor,no-op,repeated edits,history retry,control JSON,GUI patch,foreign txn,canonical version bounds");
|
||||
}
|
||||
|
||||
static void tags_long_history(struct UTUN_INSTANCE* inst) {
|
||||
struct chat_member_tags* edit = chat_member_tags_load(inst, channel, inst->node_id); assert(edit);
|
||||
int version = atoi(chat_member_tags_get(edit, "ver")) + 1; chat_member_tags_free(edit);
|
||||
char history[400]; size_t used = 0;
|
||||
for (unsigned i = 0; i < 160; i++) { history[used++] = 'e'; history[used++] = '1'; }
|
||||
memcpy(history + used, "d2", 3);
|
||||
char json[512]; snprintf(json, sizeof(json), "{\"ver\":\"%d\",\"admin\":\"%s\"}", version, history);
|
||||
uint8_t key[32], body[MS_ADM_TAGS_MAX + 8], signature[64], display[CHAT_MEMBER_DISPLAY_SIZE];
|
||||
assert(!topo_node_sqlite_channel_get_priv(inst->topo_sqlite_db, channel, key));
|
||||
int bytes = member_sync_build_owner_msg(inst->node_id, json, body, sizeof(body));
|
||||
assert(bytes > 0 && sc_ed25519_sign(key, body, (size_t)bytes, signature) == SC_OK); OPENSSL_cleanse(key, sizeof(key));
|
||||
int changes = member_sync_put(inst, channel, inst->node_id, inst->my_keys.public_key, inst->my_ed25519_pubkey,
|
||||
NULL, 0, NULL, 0, NULL, json, signature, 0, 0, NULL); assert(changes >= 0 && (changes & MS_APPLY_CHANGED));
|
||||
assert(!chat_core_get_single_member(inst, channel, inst->node_id, display) && !(display[10] & CHAT_MEMBER_FLAG_ADMIN));
|
||||
edit = chat_member_tags_load(inst, channel, inst->node_id); assert(edit && !strcmp(chat_member_tags_get(edit, "admin"), "no"));
|
||||
assert(!chat_member_tags_set(edit, "admin", "yes") && !chat_member_tags_commit(inst, edit)); chat_member_tags_free(edit);
|
||||
assert(!chat_core_get_single_member(inst, channel, inst->node_id, display) && (display[10] & CHAT_MEMBER_FLAG_ADMIN));
|
||||
char sql[128]; snprintf(sql, sizeof(sql), "SELECT json_extract(adm_tags,'$.admin') FROM peers_%s WHERE node_id=?", channel);
|
||||
sqlite3_stmt* st = NULL; assert(sqlite3_prepare_v2(inst->topo_sqlite_db, sql, -1, &st, NULL) == SQLITE_OK);
|
||||
assert(sqlite3_bind_int64(st, 1, (sqlite3_int64)inst->node_id) == SQLITE_OK && sqlite3_step(st) == SQLITE_ROW);
|
||||
const char* saved = (const char*)sqlite3_column_text(st, 0); assert(!strncmp(saved, history, strlen(history)) && saved[strlen(history)] == 'e');
|
||||
assert(sqlite3_finalize(st) == SQLITE_OK);
|
||||
puts("PASS tags:role history beyond256 bytes preserves the final action in editor/display and appends without dropping history");
|
||||
}
|
||||
|
||||
static void tags_callback_deletion(struct UTUN_INSTANCE* inst) {
|
||||
char parent[32]; strcpy(parent, channel); uint64_t child = chat_core_create_channel_auto(inst, "delete from tags event"); assert(child);
|
||||
snprintf(channel, sizeof(channel), "%llu", (unsigned long long)child);
|
||||
struct chat_member_tags* edit = chat_member_tags_load(inst, channel, inst->node_id); assert(edit);
|
||||
assert(!chat_member_tags_set(edit, "test", "delete")); delete_on_event = 1;
|
||||
assert(!chat_member_tags_commit(inst, edit) && !delete_on_event && !topo_groups_find(inst->topo_groups, child));
|
||||
chat_member_tags_free(edit); strcpy(channel, parent);
|
||||
puts("PASS tags:channel deletion from committed notification keeps editor ownership valid");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
debug_config_init(); debug_set_level(DEBUG_LEVEL_ERROR); size_t baseline = u_get_allocated_count();
|
||||
unicode();
|
||||
@@ -491,7 +526,7 @@ int main(void) {
|
||||
assert(rc < 0 && !fail_read && timestamp == 123 && !memcmp(profile, previous, sizeof(profile)) && !memcmp(signature, old_signature, 64));
|
||||
assert(!chat_core_get_my_profile(inst, channel, profile, sizeof(profile), signature, ×tamp) && timestamp > 0);
|
||||
chat_event_set_handler(inst, event); reader_faults(inst); writer_faults(inst); damaged_profile(inst); semantic_profile(inst);
|
||||
owner_faults(inst); avatar(inst); tags_reader_failure(inst); tags_faults(inst); tags_semantics(inst);
|
||||
owner_faults(inst); avatar(inst); tags_reader_failure(inst); tags_faults(inst); tags_semantics(inst); tags_long_history(inst); tags_callback_deletion(inst);
|
||||
registration_failure(inst, ua); callback_deletion(inst);
|
||||
uint8_t before[32], after[32]; snapshot(reader, before); unsigned count = events;
|
||||
target = "COMMIT /* profile */"; fault = F_EXEC; fail_rollback = 1; inst->running = 1;
|
||||
|
||||
Reference in new issue
Block a user