* feat(portal-im): add opt-in SQLite conversation store with retention and per-owner access * feat(portal-im): add authenticated simulator event ingestion with strict HMAC and friend checks * feat(portal-im): HMAC forward successfully accepted viewer IMs from simulator to Robust * feat(portal-im): capture accepted viewer instant messages without blocking delivery * feat(portal-im): add secure opt-in inbox, conversation history, cursor polling and deletion * feat(portal-im): configure secure Robust ingestion, archive and SQLite provider * feat(portal-im): configure secure Robust ingestion, archive and SQLite provider * docs(config): add opt-in citizen IM archive and signed simulator forwarding settings * docs(config): add opt-in citizen IM archive and signed simulator forwarding settings * docs(config): signed opt-in portal IM capture for simulators * docs(openapi): type authenticated portal IM inbox, conversations, settings and polling APIs * docs(portal-im): deployment, portal integration, privacy and two-way chat acceptance tests * docs(portal-im): update existing citizen portal instructions for real opt-in inbox * docs(portal-im): update existing citizen portal instructions for real opt-in inbox * fix(docs): keep embedded citizen ChatGPT instructions syntactically valid * test(portal-im): assert HMAC ingest, per-user opt-in, private history and viewer forwarding * ci(portal-im): verify secure inbox integration on every PR and main build * fix(config): declare optional portal IM environment secret without storing credential * fix(config): declare optional portal IM environment secret without storing credential * fix(config): declare optional portal IM environment secret without storing credential * test(portal-im): update legacy IM source checks after authenticated inbox refactor * test(portal-im): verify ASCII canonical timestamp used consistently with ingestion * test(portal-im): exercise SQLite opt-in, deduplication, cursor, restart and privacy deletion * test(portal-im): exercise SQLite opt-in, deduplication, cursor, restart and privacy deletion * ci(portal-im): execute runtime SQLite privacy and persistence regression
56 lines
2.6 KiB
C#
56 lines
2.6 KiB
C#
using System;
|
|
using System.IO;
|
|
using NexVerse.Server.Api;
|
|
|
|
string dir = Path.Combine(Path.GetTempPath(), "portal-im-regression-" + Guid.NewGuid().ToString("N"));
|
|
Directory.CreateDirectory(dir);
|
|
try
|
|
{
|
|
string file = Path.Combine(dir, "inbox.sqlite");
|
|
Guid alice = Guid.NewGuid(), bob = Guid.NewGuid();
|
|
Guid first = Guid.NewGuid(), second = Guid.NewGuid();
|
|
NexCitizenImStore store = new NexCitizenImStore(file, 30);
|
|
Check(!store.IsEnabled(alice) && !store.IsEnabled(bob), "opt-in must be off by default");
|
|
Check(!store.Append(first, alice, bob, "Alice", "do not store me", "portal"), "no recording without opt-in");
|
|
Check(store.Read(alice, 0, 100).Count == 0, "no preconsent records");
|
|
|
|
store.SetEnabled(alice, true);
|
|
Check(store.IsEnabled(alice), "Alice opted in");
|
|
Check(store.Append(first, alice, bob, "Alice", "test 1", "portal"), "opt-in sender saved");
|
|
Check(store.Read(alice, 0, 100).Count == 1, "sender has one message");
|
|
Check(store.Read(bob, 0, 100).Count == 0, "recipient did not opt in");
|
|
Check(!store.Append(first, alice, bob, "Alice", "test 1", "portal"), "replayed event idempotent");
|
|
|
|
store.SetEnabled(bob, true);
|
|
Check(store.Append(second, bob, alice, "Bob", "reply", "viewer"), "viewer reply archived");
|
|
var a = store.Read(alice, 0, 100);
|
|
var b = store.Read(bob, 0, 100);
|
|
Check(a.Count == 2 && b.Count == 1, "only opted-in owner entries");
|
|
Check(a[1].source == "viewer" && a[1].message == "reply", "viewer reply visible");
|
|
Check(store.Read(alice, a[0].seq, 100).Count == 1, "cursor incremental");
|
|
Check(store.Read(alice, 0, 100, bob).Count == 2, "authorized peer filter");
|
|
Check(store.Conversations(alice, 20).Count == 1, "one private conversation");
|
|
|
|
NexCitizenImStore afterRestart = new NexCitizenImStore(file, 30);
|
|
Check(afterRestart.IsEnabled(bob), "settings survive process restart");
|
|
Check(afterRestart.Read(bob, 0, 100).Count == 1, "messages survive restart");
|
|
|
|
store.SetEnabled(alice, false);
|
|
Check(!store.IsEnabled(alice) && store.Read(alice, 0, 100).Count == 0,
|
|
"opt-out purges all Alice messages");
|
|
Check(store.Read(bob, 0, 100).Count == 1, "opt-out does not erase Bob's copy");
|
|
store.DeleteHistory(bob);
|
|
Check(store.Read(bob, 0, 100).Count == 0 && store.IsEnabled(bob),
|
|
"separate delete-history leaves Bob's opt-in setting intact");
|
|
Console.WriteLine("Portal IM SQLite store runtime regression: OK");
|
|
}
|
|
finally
|
|
{
|
|
try { Directory.Delete(dir, true); } catch (IOException) {}
|
|
}
|
|
|
|
static void Check(bool good, string description)
|
|
{
|
|
if (!good) throw new InvalidOperationException(description);
|
|
}
|