mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-26 19:45:20 +00:00
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.
65 lines
2.1 KiB
Swift
65 lines
2.1 KiB
Swift
//
|
|
// PeerCapabilitiesTests.swift
|
|
// bitchatTests
|
|
//
|
|
// This is free and unencumbered software released into the public domain.
|
|
// For more information, see <https://unlicense.org>
|
|
//
|
|
|
|
import Testing
|
|
import Foundation
|
|
@testable import BitFoundation
|
|
|
|
struct PeerCapabilitiesTests {
|
|
@Test
|
|
func encodingIsMinimalAndRoundTrips() {
|
|
#expect(PeerCapabilities([]).encoded() == Data([0x00]))
|
|
#expect(PeerCapabilities.prekeys.encoded() == Data([0x01]))
|
|
#expect(PeerCapabilities.meshDiagnostics.encoded() == Data([0x40]))
|
|
#expect(PeerCapabilities.privateMedia.encoded() == Data([0x00, 0x01]))
|
|
|
|
#expect(
|
|
PeerCapabilities.privateMediaReceipts.encoded()
|
|
== Data([0x00, 0x02])
|
|
)
|
|
#expect(
|
|
PeerCapabilities.nonDestructiveNoiseReplacement.encoded()
|
|
== Data([0x00, 0x04])
|
|
)
|
|
|
|
let high = PeerCapabilities(rawValue: 1 << 11)
|
|
#expect(high.encoded() == Data([0x00, 0x08]))
|
|
|
|
let all: PeerCapabilities = [
|
|
.prekeys,
|
|
.wifiBulk,
|
|
.gateway,
|
|
.groups,
|
|
.board,
|
|
.vouch,
|
|
.meshDiagnostics,
|
|
.privateMedia,
|
|
.privateMediaReceipts,
|
|
.nonDestructiveNoiseReplacement
|
|
]
|
|
#expect(PeerCapabilities(encoded: all.encoded()) == all)
|
|
#expect(PeerCapabilities(encoded: high.encoded()) == high)
|
|
#expect(PeerCapabilities(encoded: PeerCapabilities([]).encoded()) == [])
|
|
}
|
|
|
|
@Test
|
|
func decodingToleratesUnknownBitsAndOversizedFields() {
|
|
// Unknown bits survive a round-trip untouched.
|
|
let unknown = PeerCapabilities(encoded: Data([0xFF, 0xFF]))
|
|
#expect(unknown.rawValue == 0xFFFF)
|
|
#expect(unknown.contains(.gateway))
|
|
|
|
// Fields longer than 8 bytes keep the low 64 bits and ignore the rest.
|
|
let oversized = Data([0x01] + [UInt8](repeating: 0x00, count: 7) + [0xAA, 0xBB])
|
|
#expect(PeerCapabilities(encoded: oversized) == .prekeys)
|
|
|
|
// Empty value decodes to no capabilities.
|
|
#expect(PeerCapabilities(encoded: Data()) == [])
|
|
}
|
|
}
|