Four shipping defects (remainder of !3) !4
13 files changed, +218 −33
Layout: unified · split
DomainDig.xcodeproj/project.pbxproj +4
| @@ -26,6 +26,7 @@ | ||
| 26 | 26 | A5AF921BC1C2E6E940CC05DC /* SnapshotFixture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CA789D3607B55E3612E6FFA /* SnapshotFixture.swift */; }; |
| 27 | 27 | C7CA9E02B0DC2708DE7A8563 /* DomainDataPortabilityServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC948A02EC0184228BC4630E /* DomainDataPortabilityServiceTests.swift */; }; |
| 28 | 28 | E959C4D24DAAB3CB80D854B2 /* DiffServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15A25DF2B8BB52589D49986B /* DiffServiceTests.swift */; }; |
| 29 | A1B2C3D40000000000000202 /* InspectionInputTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C3D40000000000000201 /* InspectionInputTests.swift */; }; | |
| 29 | 30 | EA12012CDB4C21ABB4217D86 /* LocalAPIContractTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D85A44C5F315A1644AC9073 /* LocalAPIContractTests.swift */; }; |
| 30 | 31 | /* End PBXBuildFile section */ |
| 31 | 32 | |
| @@ -96,6 +97,7 @@ | ||
| 96 | 97 | 8BDC00010000000000000001 /* DomainDigUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DomainDigUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; |
| 97 | 98 | 8BF9DA842F9B13FB00EF41D5 /* DomainDataPortabilityService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainDataPortabilityService.swift; sourceTree = "<group>"; }; |
| 98 | 99 | A1B2C3D40000000000000101 /* HistoryEntryCodableTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = HistoryEntryCodableTests.swift; sourceTree = "<group>"; }; |
| 100 | A1B2C3D40000000000000201 /* InspectionInputTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = InspectionInputTests.swift; sourceTree = "<group>"; }; | |
| 99 | 101 | A77F7ED29E7C6669F5E61C04 /* DomainDigTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DomainDigTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; |
| 100 | 102 | CC948A02EC0184228BC4630E /* DomainDataPortabilityServiceTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = DomainDataPortabilityServiceTests.swift; sourceTree = "<group>"; }; |
| 101 | 103 | DE8B269A01CC5E593DA3DFC2 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS26.0.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; |
| @@ -233,6 +235,7 @@ | ||
| 233 | 235 | 435AFB3F99D579D3D7B58279 /* DataMigrationServiceTests.swift */, |
| 234 | 236 | 499B99A1866999A38AC475F5 /* AppInfoTests.swift */, |
| 235 | 237 | A1B2C3D40000000000000101 /* HistoryEntryCodableTests.swift */, |
| 238 | A1B2C3D40000000000000201 /* InspectionInputTests.swift */, | |
| 236 | 239 | ); |
| 237 | 240 | path = DomainDigTests; |
| 238 | 241 | sourceTree = "<group>"; |
| @@ -493,6 +496,7 @@ | ||
| 493 | 496 | EA12012CDB4C21ABB4217D86 /* LocalAPIContractTests.swift in Sources */, |
| 494 | 497 | 4F96CEB875EC3501E784CE39 /* DataMigrationServiceTests.swift in Sources */, |
| 495 | 498 | 99024E91EED2275FD80E83A9 /* AppInfoTests.swift in Sources */, |
| 499 | A1B2C3D40000000000000202 /* InspectionInputTests.swift in Sources */, | |
| 496 | 500 | ); |
| 497 | 501 | runOnlyForDeploymentPostprocessing = 0; |
| 498 | 502 | }; |
DomainDig/DomainAvailabilityService.swift +7 −6
| @@ -9,15 +9,16 @@ struct DomainAvailabilityService { | ||
| 9 | 9 | return DomainAvailabilityResult(domain: domain, status: .unknown) |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | if await checkViaRDAP(domain: normalizedDomain) == .registered { | |
| 13 | return DomainAvailabilityResult(domain: normalizedDomain, status: .registered) | |
| 12 | // RDAP is the registry's own record, so it settles both directions. | |
| 13 | if let registryStatus = await checkViaRDAP(domain: normalizedDomain) { | |
| 14 | return DomainAvailabilityResult(domain: normalizedDomain, status: registryStatus) | |
| 14 | 15 | } |
| 15 | 16 | |
| 17 | // Without a registry answer only "registered" is decidable: a name that | |
| 18 | // resolves is registered. Absence of records is not evidence of | |
| 19 | // availability, because the DoH layer drops the response code, so | |
| 20 | // NXDOMAIN and a resolver failure arrive here identically. | |
| 16 | 21 | let fallbackStatus = await checkViaDNSFallback(domain: normalizedDomain) |
| 17 | if fallbackStatus == .registered { | |
| 18 | return DomainAvailabilityResult(domain: normalizedDomain, status: .unknown) | |
| 19 | } | |
| 20 | ||
| 21 | 22 | return DomainAvailabilityResult(domain: normalizedDomain, status: fallbackStatus) |
| 22 | 23 | } |
| 23 | 24 | |
DomainDig/DomainHostURL.swift added +30
| @@ -0,0 +1,30 @@ | ||
| 1 | import Foundation | |
| 2 | ||
| 3 | /// Request URLs for an inspected host. | |
| 4 | /// | |
| 5 | /// The inspected domain is free text, so it cannot be forced into a URL: | |
| 6 | /// `URL(string: "https://exa mple.com")` is nil, and a section service that | |
| 7 | /// built its request with `!` trapped on any host carrying a space, a tab or a | |
| 8 | /// control character — reachable by typing `example .com`, or by separating | |
| 9 | /// bulk input with spaces instead of commas or newlines. | |
| 10 | enum DomainHostURL { | |
| 11 | static func https(_ host: String) -> URL? { | |
| 12 | url(scheme: "https", host: host) | |
| 13 | } | |
| 14 | ||
| 15 | static func http(_ host: String) -> URL? { | |
| 16 | url(scheme: "http", host: host) | |
| 17 | } | |
| 18 | ||
| 19 | /// `nil` when `host` cannot form a URL with a host component. | |
| 20 | static func url(scheme: String, host: String) -> URL? { | |
| 21 | let trimmedHost = host.trimmingCharacters(in: .whitespacesAndNewlines) | |
| 22 | guard !trimmedHost.isEmpty, | |
| 23 | trimmedHost.rangeOfCharacter(from: .whitespacesAndNewlines) == nil, | |
| 24 | let url = URL(string: "\(scheme)://\(trimmedHost)"), | |
| 25 | url.host?.isEmpty == false else { | |
| 26 | return nil | |
| 27 | } | |
| 28 | return url | |
| 29 | } | |
| 30 | } | |
DomainDig/HTTPHeadersService.swift +4 −1
| @@ -36,7 +36,10 @@ struct HTTPHeadersResult { | ||
| 36 | 36 | |
| 37 | 37 | struct HTTPHeadersService { |
| 38 | 38 | static func fetch(domain: String) async -> ServiceResult<HTTPHeadersResult> { |
| 39 | let url = URL(string: "https://\(domain)")! | |
| 39 | guard let url = DomainHostURL.https(domain) else { | |
| 40 | return .error("Not a valid domain name") | |
| 41 | } | |
| 42 | ||
| 40 | 43 | var request = URLRequest(url: url, timeoutInterval: 10) |
| 41 | 44 | request.httpMethod = "HEAD" |
| 42 | 45 | let metricsDelegate = TaskMetricsDelegate() |
DomainDig/IPGeolocationService.swift +4 −1
| @@ -2,7 +2,10 @@ import Foundation | ||
| 2 | 2 | |
| 3 | 3 | struct IPGeolocationService { |
| 4 | 4 | static func lookup(ip: String) async -> ServiceResult<IPGeolocation> { |
| 5 | let url = URL(string: "https://ipapi.co/\(ip)/json/")! | |
| 5 | guard let url = URL(string: "https://ipapi.co/\(ip)/json/") else { | |
| 6 | return .error("Not a valid IP address") | |
| 7 | } | |
| 8 | ||
| 6 | 9 | let request = URLRequest(url: url, timeoutInterval: 10) |
| 7 | 10 | |
| 8 | 11 | do { |
DomainDig/Info.plist +8 −4
| @@ -2,10 +2,6 @@ | ||
| 2 | 2 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 3 | 3 | <plist version="1.0"> |
| 4 | 4 | <dict> |
| 5 | <key>Allow Arbitrary Loads (or NSAllowsArbitraryLoads) </key> | |
| 6 | <true/> | |
| 7 | <key>App Transport Security Settings (or NSAppTransportSecurity)</key> | |
| 8 | <dict/> | |
| 9 | 5 | <key>BGTaskSchedulerPermittedIdentifiers</key> |
| 10 | 6 | <array> |
| 11 | 7 | <string>net.cleberg.DomainDig.monitor.refresh</string> |
| @@ -24,6 +20,14 @@ | ||
| 24 | 20 | </array> |
| 25 | 21 | <key>CKSharingSupported</key> |
| 26 | 22 | <true/> |
| 23 | <!-- The app inspects hosts the user names, including tracing the | |
| 24 | http -> https redirect that is the point of the redirect check, so | |
| 25 | requests cannot be restricted to TLS. --> | |
| 26 | <key>NSAppTransportSecurity</key> | |
| 27 | <dict> | |
| 28 | <key>NSAllowsArbitraryLoads</key> | |
| 29 | <true/> | |
| 30 | </dict> | |
| 27 | 31 | <key>NSSupportsLiveActivities</key> |
| 28 | 32 | <true/> |
| 29 | 33 | <key>UIBackgroundModes</key> |
DomainDig/IntegrationService.swift +14 −1
| @@ -586,6 +586,7 @@ private enum IntegrationError: LocalizedError { | ||
| 586 | 586 | case missingSecret |
| 587 | 587 | case invalidResponse(Int) |
| 588 | 588 | case invalidSMTPPort |
| 589 | case insecureCredentials | |
| 589 | 590 | case smtp(String) |
| 590 | 591 | case streamClosed |
| 591 | 592 | |
| @@ -601,6 +602,8 @@ private enum IntegrationError: LocalizedError { | ||
| 601 | 602 | return "The remote endpoint returned \(statusCode)." |
| 602 | 603 | case .invalidSMTPPort: |
| 603 | 604 | return "The SMTP port is invalid." |
| 605 | case .insecureCredentials: | |
| 606 | return "SMTP credentials cannot be sent over an unencrypted connection. Use Direct TLS, usually on port 465." | |
| 604 | 607 | case .smtp(let message): |
| 605 | 608 | return message |
| 606 | 609 | case .streamClosed: |
| @@ -669,10 +672,20 @@ private enum SMTPClient { | ||
| 669 | 672 | configuration: EmailIntegrationConfiguration, |
| 670 | 673 | password: String |
| 671 | 674 | ) async throws { |
| 672 | guard let port = NWEndpoint.Port(rawValue: UInt16(configuration.port)) else { | |
| 675 | // `UInt16(_:)` traps above 65535, which the editor's port field allows. | |
| 676 | guard let portNumber = UInt16(exactly: configuration.port), | |
| 677 | let port = NWEndpoint.Port(rawValue: portNumber) else { | |
| 673 | 678 | throw IntegrationError.invalidSMTPPort |
| 674 | 679 | } |
| 675 | 680 | |
| 681 | // AUTH LOGIN sends the username and password base64-encoded, which is | |
| 682 | // not encryption. Without TLS from the first byte they would go out in | |
| 683 | // the clear, so refuse before the connection opens. STARTTLS is not an | |
| 684 | // option here: NWConnection cannot upgrade an established connection. | |
| 685 | guard configuration.username.isEmpty || configuration.securityMode == .directTLS else { | |
| 686 | throw IntegrationError.insecureCredentials | |
| 687 | } | |
| 688 | ||
| 676 | 689 | let parameters: NWParameters = { |
| 677 | 690 | switch configuration.securityMode { |
| 678 | 691 | case .plain: |
DomainDig/IntegrationsView.swift +4
| @@ -468,6 +468,10 @@ private struct IntegrationEditorView: View { | ||
| 468 | 468 | validationMessage = "SMTP password is required." |
| 469 | 469 | return |
| 470 | 470 | } |
| 471 | if smtpSecurity != .directTLS, !emailUsername.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { | |
| 472 | validationMessage = "A username needs Direct TLS, usually on port 465. Without it the password would be sent in cleartext." | |
| 473 | return | |
| 474 | } | |
| 471 | 475 | |
| 472 | 476 | let target = IntegrationTarget( |
| 473 | 477 | id: targetID, |
DomainDig/Models.swift +1 −1
| @@ -1808,7 +1808,7 @@ enum SMTPSecurityMode: String, Codable, CaseIterable, Identifiable, Sendable { | ||
| 1808 | 1808 | var title: String { |
| 1809 | 1809 | switch self { |
| 1810 | 1810 | case .plain: |
| 1811 | return "Plain" | |
| 1811 | return "None (no TLS)" | |
| 1812 | 1812 | case .directTLS: |
| 1813 | 1813 | return "Direct TLS" |
| 1814 | 1814 | } |
DomainDig/RDAPService.swift +47 −16
| @@ -1,20 +1,34 @@ | ||
| 1 | 1 | import Foundation |
| 2 | 2 | |
| 3 | 3 | enum RDAPService { |
| 4 | /// The registry's answer about `domain`, or nil when the registry did not | |
| 5 | /// give one. | |
| 4 | 6 | static func registrationStatus(for domain: String) async -> DomainAvailabilityStatus? { |
| 5 | 7 | let normalizedDomain = normalize(domain) |
| 6 | 8 | guard !normalizedDomain.isEmpty else { return nil } |
| 7 | 9 | |
| 8 | 10 | switch await fetchRDAPResponse(for: normalizedDomain) { |
| 9 | case let .success(response): | |
| 10 | return response.isDomainRecord ? .registered : nil | |
| 11 | case .empty: | |
| 12 | return nil | |
| 13 | case .error: | |
| 11 | case .found: | |
| 12 | return .registered | |
| 13 | case .notRegistered: | |
| 14 | return .available | |
| 15 | case .empty, .failed: | |
| 14 | 16 | return nil |
| 15 | 17 | } |
| 16 | 18 | } |
| 17 | 19 | |
| 20 | /// Whether an RDAP response came from a registry's own server rather than | |
| 21 | /// from the `rdap.org` bootstrap redirector. | |
| 22 | /// | |
| 23 | /// `rdap.org` answers 404 both for a domain its registry does not hold and | |
| 24 | /// for a TLD it knows no RDAP server for; only the first says anything about | |
| 25 | /// registration. `URLSession` follows the bootstrap redirect, so a response | |
| 26 | /// URL on another host is the registry's own answer. | |
| 27 | static func answeredByRegistry(responseURL: URL?) -> Bool { | |
| 28 | guard let host = responseURL?.host?.lowercased() else { return false } | |
| 29 | return host != bootstrapHost && !host.hasSuffix(".\(bootstrapHost)") | |
| 30 | } | |
| 31 | ||
| 18 | 32 | static func ownership(for domain: String) async -> ServiceResult<DomainOwnership> { |
| 19 | 33 | let normalizedDomain = normalize(domain) |
| 20 | 34 | guard !normalizedDomain.isEmpty else { |
| @@ -22,7 +36,7 @@ enum RDAPService { | ||
| 22 | 36 | } |
| 23 | 37 | |
| 24 | 38 | switch await fetchRDAPResponse(for: normalizedDomain) { |
| 25 | case let .success(response): | |
| 39 | case let .found(response): | |
| 26 | 40 | let ownership = DomainOwnership( |
| 27 | 41 | registrar: response.registrarName, |
| 28 | 42 | registrant: response.registrantName, |
| @@ -33,9 +47,11 @@ enum RDAPService { | ||
| 33 | 47 | abuseEmail: response.abuseEmail |
| 34 | 48 | ) |
| 35 | 49 | return .success(ownership) |
| 50 | case .notRegistered: | |
| 51 | return .empty("Unavailable") | |
| 36 | 52 | case let .empty(message): |
| 37 | 53 | return .empty(message) |
| 38 | case let .error(message): | |
| 54 | case let .failed(message): | |
| 39 | 55 | return .error(message) |
| 40 | 56 | } |
| 41 | 57 | } |
| @@ -47,10 +63,24 @@ enum RDAPService { | ||
| 47 | 63 | } |
| 48 | 64 | } |
| 49 | 65 | |
| 50 | private func fetchRDAPResponse(for domain: String) async -> ServiceResult<RDAPDomainResponse> { | |
| 66 | private let bootstrapHost = "rdap.org" | |
| 67 | ||
| 68 | /// What a single RDAP fetch established. | |
| 69 | private enum RDAPFetchOutcome { | |
| 70 | /// A domain record, from whichever server answered. | |
| 71 | case found(RDAPDomainResponse) | |
| 72 | /// The registry's own RDAP server reported no such domain. | |
| 73 | case notRegistered | |
| 74 | /// An answer that settles nothing: a non-domain record, or a 404 from the | |
| 75 | /// bootstrap redirector rather than from a registry. | |
| 76 | case empty(String) | |
| 77 | case failed(String) | |
| 78 | } | |
| 79 | ||
| 80 | private func fetchRDAPResponse(for domain: String) async -> RDAPFetchOutcome { | |
| 51 | 81 | let startedAt = DomainDebugLog.signpostStart("RDAP.fetch", domain: domain) |
| 52 | guard let url = URL(string: "https://rdap.org/domain/\(domain)") else { | |
| 53 | return .error("Unavailable") | |
| 82 | guard let url = URL(string: "https://\(bootstrapHost)/domain/\(domain)") else { | |
| 83 | return .failed("Unavailable") | |
| 54 | 84 | } |
| 55 | 85 | |
| 56 | 86 | do { |
| @@ -61,7 +91,7 @@ private func fetchRDAPResponse(for domain: String) async -> ServiceResult<RDAPDo | ||
| 61 | 91 | let (data, response) = try await URLSession.shared.data(for: request) |
| 62 | 92 | guard let httpResponse = response as? HTTPURLResponse else { |
| 63 | 93 | DomainDebugLog.error("RDAP.badResponse domain=\(domain) response=nil") |
| 64 | return .error(URLError(.badServerResponse).localizedDescription) | |
| 94 | return .failed(URLError(.badServerResponse).localizedDescription) | |
| 65 | 95 | } |
| 66 | 96 | |
| 67 | 97 | switch httpResponse.statusCode { |
| @@ -73,19 +103,20 @@ private func fetchRDAPResponse(for domain: String) async -> ServiceResult<RDAPDo | ||
| 73 | 103 | return .empty("Unavailable") |
| 74 | 104 | } |
| 75 | 105 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=200 bytes=\(data.count)") |
| 76 | return .success(rdapResponse) | |
| 106 | return .found(rdapResponse) | |
| 77 | 107 | case 404: |
| 78 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=404") | |
| 79 | return .empty("Unavailable") | |
| 108 | let fromRegistry = RDAPService.answeredByRegistry(responseURL: httpResponse.url) | |
| 109 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=404 registry=\(fromRegistry)") | |
| 110 | return fromRegistry ? .notRegistered : .empty("Unavailable") | |
| 80 | 111 | default: |
| 81 | 112 | DomainDebugLog.error("RDAP.httpError domain=\(domain) status=\(httpResponse.statusCode)") |
| 82 | 113 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "status=\(httpResponse.statusCode)") |
| 83 | return .error("Unavailable") | |
| 114 | return .failed("Unavailable") | |
| 84 | 115 | } |
| 85 | 116 | } catch { |
| 86 | 117 | DomainDebugLog.error("RDAP.error domain=\(domain) error=\(error.localizedDescription)") |
| 87 | 118 | DomainDebugLog.signpostEnd("RDAP.fetch", start: startedAt, domain: domain, extra: "error") |
| 88 | return .error(error.localizedDescription) | |
| 119 | return .failed(error.localizedDescription) | |
| 89 | 120 | } |
| 90 | 121 | } |
| 91 | 122 | |
DomainDig/RedirectChainService.swift +10 −2
| @@ -2,12 +2,20 @@ import Foundation | ||
| 2 | 2 | |
| 3 | 3 | struct RedirectChainService { |
| 4 | 4 | static func trace(domain: String) async -> ServiceResult<[RedirectHop]> { |
| 5 | guard let httpsURL = DomainHostURL.https(domain) else { | |
| 6 | return .error("Not a valid domain name") | |
| 7 | } | |
| 8 | ||
| 5 | 9 | do { |
| 6 | let hops = try await followChain(startingURL: URL(string: "https://\(domain)")!) | |
| 10 | let hops = try await followChain(startingURL: httpsURL) | |
| 7 | 11 | return hops.isEmpty ? .empty("No redirect data available") : .success(hops) |
| 8 | 12 | } catch { |
| 13 | guard let httpURL = DomainHostURL.http(domain) else { | |
| 14 | return .error(error.localizedDescription) | |
| 15 | } | |
| 16 | ||
| 9 | 17 | do { |
| 10 | let hops = try await followChain(startingURL: URL(string: "http://\(domain)")!) | |
| 18 | let hops = try await followChain(startingURL: httpURL) | |
| 11 | 19 | return hops.isEmpty ? .empty("No redirect data available") : .success(hops) |
| 12 | 20 | } catch { |
| 13 | 21 | return .error(error.localizedDescription) |
DomainDig/SSLCheckService.swift +4 −1
| @@ -4,6 +4,10 @@ import Security | ||
| 4 | 4 | struct SSLCheckService { |
| 5 | 5 | |
| 6 | 6 | static func check(domain: String) async -> ServiceResult<SSLCertificateInfo> { |
| 7 | guard let url = DomainHostURL.https(domain) else { | |
| 8 | return .error("Not a valid domain name") | |
| 9 | } | |
| 10 | ||
| 7 | 11 | let delegate = SSLSessionDelegate() |
| 8 | 12 | let session = URLSession( |
| 9 | 13 | configuration: .ephemeral, |
| @@ -12,7 +16,6 @@ struct SSLCheckService { | ||
| 12 | 16 | ) |
| 13 | 17 | defer { session.invalidateAndCancel() } |
| 14 | 18 | |
| 15 | let url = URL(string: "https://\(domain)")! | |
| 16 | 19 | let request = URLRequest(url: url, timeoutInterval: 10) |
| 17 | 20 | |
| 18 | 21 | do { |
DomainDigTests/InspectionInputTests.swift added +81
| @@ -0,0 +1,81 @@ | ||
| 1 | import XCTest | |
| 2 | @testable import DomainDig | |
| 3 | ||
| 4 | /// The inspected domain is free text, and the section services used to force it | |
| 5 | /// into a URL with `!`. These pin the two pure helpers that replaced that. | |
| 6 | final class DomainHostURLTests: XCTestCase { | |
| 7 | ||
| 8 | func testBuildsHTTPSURLForAPlainHost() { | |
| 9 | XCTAssertEqual(DomainHostURL.https("example.com")?.absoluteString, "https://example.com") | |
| 10 | } | |
| 11 | ||
| 12 | func testBuildsHTTPURLForAPlainHost() { | |
| 13 | XCTAssertEqual(DomainHostURL.http("example.com")?.absoluteString, "http://example.com") | |
| 14 | } | |
| 15 | ||
| 16 | func testTrimsSurroundingWhitespace() { | |
| 17 | XCTAssertEqual(DomainHostURL.https(" example.com\n")?.absoluteString, "https://example.com") | |
| 18 | } | |
| 19 | ||
| 20 | /// The crash this replaced: `URL(string: "https://exa mple.com")` is nil, so | |
| 21 | /// the force-unwrap trapped. Reachable by typing `example .com`, or by | |
| 22 | /// separating bulk input with spaces instead of commas or newlines. | |
| 23 | func testRejectsAnInteriorSpace() { | |
| 24 | XCTAssertNil(DomainHostURL.https("exa mple.com")) | |
| 25 | } | |
| 26 | ||
| 27 | func testRejectsAnInteriorTab() { | |
| 28 | XCTAssertNil(DomainHostURL.https("exa\tmple.com")) | |
| 29 | } | |
| 30 | ||
| 31 | func testRejectsAControlCharacter() { | |
| 32 | XCTAssertNil(DomainHostURL.https("exa\u{0}mple.com")) | |
| 33 | } | |
| 34 | ||
| 35 | func testRejectsInputWithNoHostComponent() { | |
| 36 | XCTAssertNil(DomainHostURL.https("")) | |
| 37 | XCTAssertNil(DomainHostURL.https(" ")) | |
| 38 | XCTAssertNil(DomainHostURL.https("/")) | |
| 39 | XCTAssertNil(DomainHostURL.https(":443")) | |
| 40 | } | |
| 41 | ||
| 42 | func testEncodesAnInternationalizedHost() { | |
| 43 | XCTAssertEqual(DomainHostURL.https("münchen.de")?.host, "xn--mnchen-3ya.de") | |
| 44 | } | |
| 45 | } | |
| 46 | ||
| 47 | /// `rdap.org` answers 404 both for a domain its registry does not hold and for a | |
| 48 | /// TLD it knows no RDAP server for. Only the first means "available", so the | |
| 49 | /// availability check turns on which server answered. | |
| 50 | final class RDAPRegistryOriginTests: XCTestCase { | |
| 51 | ||
| 52 | func testRegistryResponseCountsAsAnAnswer() { | |
| 53 | let url = URL(string: "https://rdap.verisign.com/com/v1/domain/example.com") | |
| 54 | XCTAssertTrue(RDAPService.answeredByRegistry(responseURL: url)) | |
| 55 | } | |
| 56 | ||
| 57 | func testBootstrapResponseDoesNotCountAsAnAnswer() { | |
| 58 | let url = URL(string: "https://rdap.org/domain/example.invalidtld") | |
| 59 | XCTAssertFalse(RDAPService.answeredByRegistry(responseURL: url)) | |
| 60 | } | |
| 61 | ||
| 62 | func testBootstrapSubdomainDoesNotCountAsAnAnswer() { | |
| 63 | let url = URL(string: "https://www.rdap.org/domain/example.invalidtld") | |
| 64 | XCTAssertFalse(RDAPService.answeredByRegistry(responseURL: url)) | |
| 65 | } | |
| 66 | ||
| 67 | func testHostMatchIsCaseInsensitive() { | |
| 68 | let url = URL(string: "https://RDAP.ORG/domain/example.com") | |
| 69 | XCTAssertFalse(RDAPService.answeredByRegistry(responseURL: url)) | |
| 70 | } | |
| 71 | ||
| 72 | func testMissingResponseURLDoesNotCountAsAnAnswer() { | |
| 73 | XCTAssertFalse(RDAPService.answeredByRegistry(responseURL: nil)) | |
| 74 | } | |
| 75 | ||
| 76 | /// A host that merely ends in the bootstrap name is a different domain. | |
| 77 | func testLookalikeHostCountsAsAnAnswer() { | |
| 78 | let url = URL(string: "https://notrdap.org/domain/example.com") | |
| 79 | XCTAssertTrue(RDAPService.answeredByRegistry(responseURL: url)) | |
| 80 | } | |
| 81 | } | |