Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687import Foundationimport Testing@testable import CoreATProtocol
@Suite("IdentityResolver hostname validation")struct HostnameValidationTests { @Test("Valid DNS-style handles are accepted") func valid() throws { try IdentityResolver.validateHostname("alice.bsky.social") try IdentityResolver.validateHostname("example.com") try IdentityResolver.validateHostname("a-b.c-d.example.com") }
@Test("Handles with URL authority characters are rejected", arguments: [ "alice@bsky.social", "alice.bsky.social/extra", "alice.bsky.social?q=1", "alice.bsky.social#frag", "alice.bsky.social:8080", "alice bsky social", "aliçe.bsky.social", ]) func rejectsInjection(_ input: String) { #expect(throws: IdentityError.self) { try IdentityResolver.validateHostname(input) } }
@Test("Empty, single-label, and malformed handles are rejected", arguments: [ "", "com", ".com", "alice.", "alice..com", "-alice.com", "alice-.com", ]) func rejectsMalformed(_ input: String) { #expect(throws: IdentityError.self) { try IdentityResolver.validateHostname(input) } }
@Test("Labels over 63 characters are rejected") func tooLongLabel() { let longLabel = String(repeating: "a", count: 64) #expect(throws: IdentityError.self) { try IdentityResolver.validateHostname("\(longLabel).com") } }}
@Suite("DID document PDS lookup")struct DIDDocumentPDSTests { @Test("Service matched by #atproto_pds suffix") func matchBySuffix() { let doc = DIDDocument( id: "did:plc:abc", alsoKnownAs: ["at://alice.bsky.social"], service: [DIDService(id: "#atproto_pds", type: "Whatever", serviceEndpoint: "https://pds.example")] ) #expect(doc.pdsEndpoint == "https://pds.example") }
@Test("Service matched by AtprotoPersonalDataServer type") func matchByType() { let doc = DIDDocument( id: "did:plc:abc", alsoKnownAs: ["at://alice.bsky.social"], service: [DIDService(id: "#other", type: "AtprotoPersonalDataServer", serviceEndpoint: "https://pds.example")] ) #expect(doc.pdsEndpoint == "https://pds.example") }
@Test("Document with no matching service returns nil") func noMatch() { let doc = DIDDocument( id: "did:plc:abc", alsoKnownAs: nil, service: [DIDService(id: "#other", type: "Unrelated", serviceEndpoint: "https://example.com")] ) #expect(doc.pdsEndpoint == nil) }}