Files
bitchat/bitchatTests/Utils/InputValidatorTests.swift
T
3074fa0fcb Refactor/repo hardening 01 (#462)
* BinaryProtocol: add optional padding control; BitchatPacket API for padded/unpadded bytes; BLEService: use unpadded encoding and remove ad-hoc unpadding on BLE writes

* BLEService: balance BLE padding — pad Noise handshake/encrypted frames; leave public/announce/leave unpadded; keep fragmentation consistent with chosen padding

* BLEService: replace Timer with DispatchSourceTimer on bleQueue; NostrTransport: cache placeholder NoiseEncryptionService to avoid reallocation

* Unify peerID validation: InputValidator handles 16-hex, 64-hex, or alnum-/_; NoiseSecurityValidator now delegates to InputValidator

* UI: use standard green for geohash toolbar badge and count (less bright in light mode)

* UI: standardize geohash sheet green to app standard (dark: system green, light: darker green) for buttons and checkmark

* Docs: align BinaryProtocol compression docs to zlib; Logs: reduce NostrTransport DELIVERED ack logs to debug to cut noise

* Tests: add InputValidator peerID coverage and BinaryProtocol padding round-trip/length tests

* Project: ensure Xcode project reflects new tests (references added)

---------

Co-authored-by: jack <jackjackbits@users.noreply.github.com>
2025-08-20 13:29:53 +02:00

38 lines
1.2 KiB
Swift

//
// InputValidatorTests.swift
// bitchatTests
//
// This is free and unencumbered software released into the public domain.
//
import XCTest
@testable import bitchat
final class InputValidatorTests: XCTestCase {
func test_accepts_short_hex_peer_id() {
XCTAssertTrue(InputValidator.validatePeerID("0011223344556677"))
XCTAssertTrue(InputValidator.validatePeerID("aabbccddeeff0011"))
}
func test_accepts_full_noise_key_hex() {
let hex64 = String(repeating: "ab", count: 32) // 64 hex chars
XCTAssertTrue(InputValidator.validatePeerID(hex64))
}
func test_accepts_internal_alnum_dash_underscore() {
XCTAssertTrue(InputValidator.validatePeerID("peer_123-ABC"))
XCTAssertTrue(InputValidator.validatePeerID("nostr_user_01"))
}
func test_rejects_invalid_characters() {
XCTAssertFalse(InputValidator.validatePeerID("peer!@#"))
XCTAssertFalse(InputValidator.validatePeerID("gggggggggggggggg")) // not hex for short form
}
func test_rejects_too_long() {
let tooLong = String(repeating: "a", count: 65)
XCTAssertFalse(InputValidator.validatePeerID(tooLong))
}
}