mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-27 00:45:23 +00:00
Persist authenticated private-media delivery receipts (#1466)
Adds a durable receiver-side ledger (BLEPrivateMediaReceiptStore) mapping a deterministic private-media message ID — hash-bound to sender, recipient, and entropy-bearing filename — to the stored file before UI delivery and before the Noise-encrypted delivery ACK, so sender retries and relaunches cannot create duplicate bubbles or files. Receipts are unforgeable without the Noise session; capability bit 9 rides the existing announce bitfield (no wire-format change; rolling upgrade safe both directions). Includes review fixes: corrupt receipt records are quarantined per-record (bytes preserved at <id>.json.corrupt, only that ID fail-closed — previously one bad record silently disabled ALL inbound private media forever); the panic reset now reaches BLEService's own store instance via completePanicReset with a production-wiring test; and both content.delivery.reason.* strings ship with full 30-locale coverage.
This commit is contained in:
@@ -220,26 +220,61 @@ struct ChatTransportEventCoordinatorContextTests {
|
||||
func didReceiveMessage_routesPrivateAndPublic_skipsBlockedAndEmpty() async {
|
||||
let context = MockChatTransportEventContext()
|
||||
let coordinator = ChatTransportEventCoordinator(context: context)
|
||||
let peerID = PeerID(str: "1122334455667788")
|
||||
|
||||
// Blocked messages are dropped before any handling.
|
||||
context.blockedMessageIDs = ["blocked"]
|
||||
context.blockedMessageIDs = ["blocked", "blocked-private"]
|
||||
coordinator.didReceiveMessage(makeMessage(id: "blocked"))
|
||||
coordinator.didReceiveMessage(makeMessage(
|
||||
id: "blocked-private",
|
||||
isPrivate: true,
|
||||
senderPeerID: peerID
|
||||
))
|
||||
// Empty public content is dropped too.
|
||||
coordinator.didReceiveMessage(makeMessage(id: "empty", content: " "))
|
||||
await drainMainActorTasks()
|
||||
#expect(context.handledPublicMessages.isEmpty)
|
||||
#expect(context.handledPrivateMessages.isEmpty)
|
||||
#expect(context.mentionCheckedMessageIDs.isEmpty)
|
||||
#expect(context.meshDeliveryAcks.isEmpty)
|
||||
|
||||
// Private goes to the private handler, public to the public handler;
|
||||
// both get mention checks and haptics.
|
||||
coordinator.didReceiveMessage(makeMessage(id: "pm", isPrivate: true))
|
||||
// both get mention checks and haptics. Stable-media ACK authorization
|
||||
// belongs to BLEFileTransferHandler after its durable commit and this
|
||||
// synchronous acceptance result, not to the generic UI coordinator.
|
||||
let stableMediaID = "media-\(String(repeating: "a", count: 32))"
|
||||
coordinator.didReceiveMessage(makeMessage(
|
||||
id: stableMediaID,
|
||||
isPrivate: true,
|
||||
senderPeerID: peerID
|
||||
))
|
||||
coordinator.didReceiveMessage(makeMessage(
|
||||
id: "legacy-media",
|
||||
isPrivate: true,
|
||||
senderPeerID: peerID
|
||||
))
|
||||
coordinator.didReceiveMessage(makeMessage(id: "pm-missing-sender", isPrivate: true))
|
||||
coordinator.didReceiveMessage(makeMessage(id: "pub"))
|
||||
await drainMainActorTasks()
|
||||
#expect(context.handledPrivateMessages.map(\.id) == ["pm"])
|
||||
#expect(context.handledPrivateMessages.map(\.id) == [
|
||||
stableMediaID,
|
||||
"legacy-media",
|
||||
"pm-missing-sender"
|
||||
])
|
||||
#expect(context.handledPublicMessages.map(\.id) == ["pub"])
|
||||
#expect(context.mentionCheckedMessageIDs == ["pm", "pub"])
|
||||
#expect(context.hapticMessageIDs == ["pm", "pub"])
|
||||
#expect(context.mentionCheckedMessageIDs == [
|
||||
stableMediaID,
|
||||
"legacy-media",
|
||||
"pm-missing-sender",
|
||||
"pub"
|
||||
])
|
||||
#expect(context.hapticMessageIDs == [
|
||||
stableMediaID,
|
||||
"legacy-media",
|
||||
"pm-missing-sender",
|
||||
"pub"
|
||||
])
|
||||
#expect(context.meshDeliveryAcks.isEmpty)
|
||||
}
|
||||
|
||||
@Test @MainActor
|
||||
|
||||
Reference in New Issue
Block a user