2026-05-22 14:01:14 +02:00
|
|
|
import XCTest
|
2026-09-20 15:05:19 +02:00
|
|
|
@testable import KeeVaultCore
|
2026-05-22 14:01:14 +02:00
|
|
|
|
|
|
|
|
final class ProtectedStringTests: XCTestCase {
|
|
|
|
|
func test_reveal_returnsOriginalValue() {
|
|
|
|
|
let ps = ProtectedString("hunter2", isProtected: true)
|
|
|
|
|
XCTAssertEqual(ps.reveal(), "hunter2")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_description_isRedactedWhenProtected() {
|
|
|
|
|
let ps = ProtectedString("secret", isProtected: true)
|
|
|
|
|
XCTAssertEqual("\(ps)", "***")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_description_isPlainWhenNotProtected() {
|
|
|
|
|
let ps = ProtectedString("visible", isProtected: false)
|
|
|
|
|
XCTAssertEqual("\(ps)", "visible")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_equality_matchesByRevealedValue() {
|
|
|
|
|
let a = ProtectedString("abc", isProtected: true)
|
|
|
|
|
let b = ProtectedString("abc", isProtected: true)
|
|
|
|
|
XCTAssertEqual(a, b)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_debugDescription_neverRevealSecret() {
|
|
|
|
|
let ps = ProtectedString("topsecret", isProtected: true)
|
|
|
|
|
XCTAssertFalse(ps.debugDescription.contains("topsecret"))
|
|
|
|
|
}
|
|
|
|
|
}
|