Commit 66141c501b
Unsigned
Layout: unified · split
DomainDig/DomainDataPortabilityService.swift −5
| @@ -1639,8 +1639,3 @@ private enum ImportPayload { | ||
| 1639 | 1639 | } |
| 1640 | 1640 | } |
| 1641 | 1641 | |
| 1642 | private extension String { | |
| 1643 | var nilIfEmpty: String? { | |
| 1644 | isEmpty ? nil : self | |
| 1645 | } | |
| 1646 | } | |
DomainDig/DomainInsightEngine.swift +4 −8
| @@ -133,18 +133,18 @@ enum DomainInsightEngine { | ||
| 133 | 133 | title: "Shared nameserver set detected", |
| 134 | 134 | groups: groupedDomains(for: reports) { |
| 135 | 135 | let value = $0.ownership?.nameservers.sorted().joined(separator: "|") |
| 136 | return value?.nilIfEmpty | |
| 136 | return value?.nilIfBlank | |
| 137 | 137 | }, |
| 138 | 138 | into: &insights |
| 139 | 139 | ) |
| 140 | 140 | appendSharedInsights( |
| 141 | 141 | title: "Shared registrar detected", |
| 142 | groups: groupedDomains(for: reports) { $0.ownership?.registrar?.nilIfEmpty }, | |
| 142 | groups: groupedDomains(for: reports) { $0.ownership?.registrar?.nilIfBlank }, | |
| 143 | 143 | into: &insights |
| 144 | 144 | ) |
| 145 | 145 | appendSharedInsights( |
| 146 | 146 | title: "Shared TLS issuer detected", |
| 147 | groups: groupedDomains(for: reports) { $0.web.tls?.issuer.nilIfEmpty }, | |
| 147 | groups: groupedDomains(for: reports) { $0.web.tls?.issuer.nilIfBlank }, | |
| 148 | 148 | into: &insights |
| 149 | 149 | ) |
| 150 | 150 | |
| @@ -537,7 +537,7 @@ enum DomainInsightEngine { | ||
| 537 | 537 | for reports: [DomainReport], |
| 538 | 538 | keyPath: KeyPath<DomainReport, String?> |
| 539 | 539 | ) -> [String: [String]] { |
| 540 | groupedDomains(for: reports) { $0[keyPath: keyPath]?.nilIfEmpty } | |
| 540 | groupedDomains(for: reports) { $0[keyPath: keyPath]?.nilIfBlank } | |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | private static func groupedDomains( |
| @@ -554,8 +554,4 @@ enum DomainInsightEngine { | ||
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | private extension String { |
| 557 | var nilIfEmpty: String? { | |
| 558 | let trimmed = trimmingCharacters(in: .whitespacesAndNewlines) | |
| 559 | return trimmed.isEmpty ? nil : trimmed | |
| 560 | } | |
| 561 | 557 | } |
DomainDig/DomainName.swift +23 −7
| @@ -15,7 +15,6 @@ import Foundation | ||
| 15 | 15 | enum DomainName { |
| 16 | 16 | private static let maximumLabelBytes = 63 |
| 17 | 17 | private static let maximumHostBytes = 253 |
| 18 | private static let probeLabelCharacters = 8 | |
| 19 | 18 | |
| 20 | 19 | /// The normalized host on success. A Unicode host is returned as typed; only |
| 21 | 20 | /// the length limits are measured on its IDNA-encoded form. |
| @@ -40,12 +39,24 @@ enum DomainName { | ||
| 40 | 39 | // The limits apply to the encoded host, which is what the section |
| 41 | 40 | // services send, so they are measured on the punycode form. |
| 42 | 41 | guard let encoded = DomainHostURL.https(host)?.host else { |
| 43 | // `URL` refuses a host whose encoded label is over the limit instead | |
| 44 | // of reporting which label it was, so the labels are re-encoded one | |
| 45 | // at a time: a label that will not encode even truncated to | |
| 46 | // `probeLabelCharacters` (short enough that it cannot reach the | |
| 47 | // limit whatever it encodes to) is malformed rather than too long. | |
| 48 | if let malformed = labels.first(where: { !canEncode(String($0.prefix(probeLabelCharacters))) }) { | |
| 42 | // `URL` refuses a host whose encoded label is over the limit | |
| 43 | // instead of reporting which label it was, so the two reasons are | |
| 44 | // told apart here: a label holding a character that will not encode | |
| 45 | // on its own is malformed, and anything else that will not encode is | |
| 46 | // too long. | |
| 47 | // | |
| 48 | // Probing per character rather than per prefix is what makes the | |
| 49 | // position irrelevant. The earlier version probed the label's first | |
| 50 | // few characters, so an unencodable character after them was | |
| 51 | // reported as merely too long. | |
| 52 | // | |
| 53 | // Not a complete IDNA characterisation: a label refused for a | |
| 54 | // combination its characters form, rather than for one of them, | |
| 55 | // still falls through to `.labelTooLong`. The input is rejected | |
| 56 | // either way and only the message differs. | |
| 57 | if let malformed = labels.first(where: { label in | |
| 58 | label.contains { !canEncode(String($0)) } | |
| 59 | }) { | |
| 49 | 60 | return .failure(.malformedLabel(malformed)) |
| 50 | 61 | } |
| 51 | 62 | return .failure(.labelTooLong) |
| @@ -97,6 +108,11 @@ enum DomainName { | ||
| 97 | 108 | return character.isLetter || character.isNumber || character == "-" || character == "." |
| 98 | 109 | } |
| 99 | 110 | |
| 111 | /// Whether `label` encodes at all, independent of length. | |
| 112 | /// | |
| 113 | /// An all-ASCII label always does, so only non-ASCII input reaches the | |
| 114 | /// probe. Callers pass a single character to ask whether that character is | |
| 115 | /// encodable anywhere in a label. | |
| 100 | 116 | private static func canEncode(_ label: String) -> Bool { |
| 101 | 117 | guard label.contains(where: { !$0.isASCII }) else { return true } |
| 102 | 118 | // The ASCII suffix keeps the probe a two-label host. |
DomainDig/DomainReportExporter.swift −5
| @@ -819,8 +819,3 @@ enum DomainReportExporter { | ||
| 819 | 819 | } |
| 820 | 820 | } |
| 821 | 821 | |
| 822 | private extension String { | |
| 823 | var nilIfEmpty: String? { | |
| 824 | isEmpty ? nil : self | |
| 825 | } | |
| 826 | } | |
DomainDig/DomainViewModel+Export.swift −9
| @@ -564,12 +564,3 @@ extension DomainViewModel { | ||
| 564 | 564 | } |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | // Deliberately a private copy rather than a shared one. `nilIfEmpty` means two | |
| 568 | // different things in this codebase: DomainInsightEngine's trims whitespace | |
| 569 | // first, every other copy does not. The exporters moved here were using the | |
| 570 | // non-trimming version, so that is what they keep (A14). | |
| 571 | private extension String { | |
| 572 | var nilIfEmpty: String? { | |
| 573 | isEmpty ? nil : self | |
| 574 | } | |
| 575 | } | |
DomainDig/DomainViewModel+Workflows.swift −5
| @@ -137,8 +137,3 @@ extension DomainViewModel { | ||
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | private extension String { | |
| 141 | var nilIfEmpty: String? { | |
| 142 | isEmpty ? nil : self | |
| 143 | } | |
| 144 | } | |
DomainDig/DomainViewModel.swift +19 −26
| @@ -268,6 +268,10 @@ final class DomainViewModel { | ||
| 268 | 268 | private(set) var currentStatusMessage: String? |
| 269 | 269 | private(set) var currentSnapshotTimestamp = Date() |
| 270 | 270 | private(set) var currentHistoryEntryID: UUID? |
| 271 | /// The metadata the current lookup produced, in preference to whatever the | |
| 272 | /// saved entry holds. Nil outside a lookup, when the saved entry is the | |
| 273 | /// only source there is. | |
| 274 | private(set) var currentInspectionMetadata: InspectionMetadata? | |
| 271 | 275 | private(set) var currentReport: DomainReport? |
| 272 | 276 | |
| 273 | 277 | private static let recentSearchesKey = "recentSearches" |
| @@ -582,19 +586,19 @@ final class DomainViewModel { | ||
| 582 | 586 | appVersion: AppVersion.current, |
| 583 | 587 | resolverDisplayName: resolverDisplayName, |
| 584 | 588 | resolverURLString: resolverURLString, |
| 585 | dataSources: currentHistoryEntry?.dataSources ?? [], | |
| 586 | provenanceBySection: currentHistoryEntry?.provenanceBySection ?? [:], | |
| 587 | availabilityConfidence: currentHistoryEntry?.availabilityConfidence, | |
| 588 | ownershipConfidence: currentHistoryEntry?.ownershipConfidence, | |
| 589 | subdomainConfidence: currentHistoryEntry?.subdomainConfidence, | |
| 590 | emailSecurityConfidence: currentHistoryEntry?.emailSecurityConfidence, | |
| 591 | geolocationConfidence: currentHistoryEntry?.geolocationConfidence, | |
| 592 | errorDetails: currentHistoryEntry?.errorDetails ?? [:], | |
| 593 | isPartialSnapshot: currentHistoryEntry?.isPartialSnapshot ?? false, | |
| 594 | validationIssues: currentHistoryEntry?.validationIssues ?? [], | |
| 589 | dataSources: currentInspectionMetadata?.dataSources ?? currentHistoryEntry?.dataSources ?? [], | |
| 590 | provenanceBySection: currentInspectionMetadata?.provenanceBySection ?? currentHistoryEntry?.provenanceBySection ?? [:], | |
| 591 | availabilityConfidence: currentInspectionMetadata?.availabilityConfidence ?? currentHistoryEntry?.availabilityConfidence, | |
| 592 | ownershipConfidence: currentInspectionMetadata?.ownershipConfidence ?? currentHistoryEntry?.ownershipConfidence, | |
| 593 | subdomainConfidence: currentInspectionMetadata?.subdomainConfidence ?? currentHistoryEntry?.subdomainConfidence, | |
| 594 | emailSecurityConfidence: currentInspectionMetadata?.emailSecurityConfidence ?? currentHistoryEntry?.emailSecurityConfidence, | |
| 595 | geolocationConfidence: currentInspectionMetadata?.geolocationConfidence ?? currentHistoryEntry?.geolocationConfidence, | |
| 596 | errorDetails: currentInspectionMetadata?.errorDetails ?? currentHistoryEntry?.errorDetails ?? [:], | |
| 597 | isPartialSnapshot: currentInspectionMetadata?.isPartialSnapshot ?? currentHistoryEntry?.isPartialSnapshot ?? false, | |
| 598 | validationIssues: currentInspectionMetadata?.validationIssues ?? currentHistoryEntry?.validationIssues ?? [], | |
| 595 | 599 | totalLookupDurationMs: lastLookupDurationMs, |
| 596 | snapshotIndex: currentHistoryEntry?.snapshotIndex, | |
| 597 | previousSnapshotID: currentHistoryEntry?.previousSnapshotID, | |
| 600 | snapshotIndex: currentInspectionMetadata?.snapshotIndex ?? currentHistoryEntry?.snapshotIndex, | |
| 601 | previousSnapshotID: currentInspectionMetadata?.previousSnapshotID ?? currentHistoryEntry?.previousSnapshotID, | |
| 598 | 602 | changeCount: currentHistoryEntry?.changeCount ?? currentChangeSummary?.changedSections.count ?? 0, |
| 599 | 603 | severitySummary: currentHistoryEntry?.severitySummary ?? currentChangeSummary?.severity, |
| 600 | 604 | dnsSections: dnsSections, |
| @@ -1477,6 +1481,7 @@ final class DomainViewModel { | ||
| 1477 | 1481 | /// Internal so the tests that pin what each section ends up showing can |
| 1478 | 1482 | /// reach it without a live lookup. |
| 1479 | 1483 | func applySnapshot(_ snapshot: LookupSnapshot) { |
| 1484 | currentInspectionMetadata = InspectionMetadata(snapshot: snapshot) | |
| 1480 | 1485 | currentHistoryEntryID = snapshot.historyEntryID |
| 1481 | 1486 | currentSnapshotTimestamp = snapshot.timestamp |
| 1482 | 1487 | currentResultSource = snapshot.resultSource |
| @@ -2040,6 +2045,7 @@ final class DomainViewModel { | ||
| 2040 | 2045 | searchedDomain = target |
| 2041 | 2046 | hasRun = true |
| 2042 | 2047 | currentHistoryEntryID = nil |
| 2048 | currentInspectionMetadata = nil | |
| 2043 | 2049 | currentSnapshotTimestamp = Date() |
| 2044 | 2050 | currentResultSource = .live |
| 2045 | 2051 | currentCachedSections = [] |
| @@ -2330,6 +2336,7 @@ final class DomainViewModel { | ||
| 2330 | 2336 | /// results cannot be mistaken for this one's. One assignment per section |
| 2331 | 2337 | /// now; it used to be three. |
| 2332 | 2338 | private func clearLookupState() { |
| 2339 | currentInspectionMetadata = nil | |
| 2333 | 2340 | dnsState = .idle |
| 2334 | 2341 | availabilityState = .idle |
| 2335 | 2342 | suggestionsState = .idle |
| @@ -3400,17 +3407,3 @@ final class DomainViewModel { | ||
| 3400 | 3407 | } |
| 3401 | 3408 | } |
| 3402 | 3409 | |
| 3403 | // Private, and not shared with the identically named helpers elsewhere: | |
| 3404 | // DomainInsightEngine's `nilIfEmpty` trims whitespace first and these do not, | |
| 3405 | // so one internal version would quietly change behaviour there (A14). | |
| 3406 | private extension String { | |
| 3407 | var nilIfEmpty: String? { | |
| 3408 | isEmpty ? nil : self | |
| 3409 | } | |
| 3410 | } | |
| 3411 | ||
| 3412 | private extension Array where Element == String { | |
| 3413 | var nilIfEmpty: [String]? { | |
| 3414 | isEmpty ? nil : self | |
| 3415 | } | |
| 3416 | } | |
DomainDig/IntegrationsView.swift −4
| @@ -706,8 +706,4 @@ private struct IntegrationEditorView: View { | ||
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | private extension String { |
| 709 | var nilIfBlank: String? { | |
| 710 | let trimmed = trimmingCharacters(in: .whitespacesAndNewlines) | |
| 711 | return trimmed.isEmpty ? nil : trimmed | |
| 712 | } | |
| 713 | 709 | } |
DomainDig/LookupSnapshot.swift +40
| @@ -282,3 +282,43 @@ extension LookupSnapshot { | ||
| 282 | 282 | ) |
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | ||
| 286 | /// The metadata one inspection produced: where each section came from, how | |
| 287 | /// confident it is, what failed, and whether the result is partial. | |
| 288 | /// | |
| 289 | /// `DomainViewModel.currentSnapshot` used to recover all of this from the | |
| 290 | /// *saved history entry*, so it was empty until the snapshot had been written | |
| 291 | /// and `currentHistoryEntryID` pointed at it. Two consequences, both fixed by | |
| 292 | /// carrying it from the lookup instead: the cards rendered without provenance | |
| 293 | /// between applying a snapshot and saving it, and a lookup that returns before | |
| 294 | /// saving — any partial or failed one — showed no provenance for any section, | |
| 295 | /// which is the case where knowing the source matters most (A12). | |
| 296 | struct InspectionMetadata: Equatable { | |
| 297 | var dataSources: [String] | |
| 298 | var provenanceBySection: [LookupSectionKind: SectionProvenance] | |
| 299 | var availabilityConfidence: ConfidenceLevel? | |
| 300 | var ownershipConfidence: ConfidenceLevel? | |
| 301 | var subdomainConfidence: ConfidenceLevel? | |
| 302 | var emailSecurityConfidence: ConfidenceLevel? | |
| 303 | var geolocationConfidence: ConfidenceLevel? | |
| 304 | var errorDetails: [LookupSectionKind: InspectionFailure] | |
| 305 | var isPartialSnapshot: Bool | |
| 306 | var validationIssues: [String] | |
| 307 | var snapshotIndex: Int? | |
| 308 | var previousSnapshotID: UUID? | |
| 309 | ||
| 310 | init(snapshot: LookupSnapshot) { | |
| 311 | dataSources = snapshot.dataSources | |
| 312 | provenanceBySection = snapshot.provenanceBySection | |
| 313 | availabilityConfidence = snapshot.availabilityConfidence | |
| 314 | ownershipConfidence = snapshot.ownershipConfidence | |
| 315 | subdomainConfidence = snapshot.subdomainConfidence | |
| 316 | emailSecurityConfidence = snapshot.emailSecurityConfidence | |
| 317 | geolocationConfidence = snapshot.geolocationConfidence | |
| 318 | errorDetails = snapshot.errorDetails | |
| 319 | isPartialSnapshot = snapshot.isPartialSnapshot | |
| 320 | validationIssues = snapshot.validationIssues | |
| 321 | snapshotIndex = snapshot.snapshotIndex | |
| 322 | previousSnapshotID = snapshot.previousSnapshotID | |
| 323 | } | |
| 324 | } | |
DomainDig/ResultPrimitives.swift −5
| @@ -284,11 +284,6 @@ extension View { | ||
| 284 | 284 | } |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | private extension String { | |
| 288 | var nilIfEmpty: String? { | |
| 289 | isEmpty ? nil : self | |
| 290 | } | |
| 291 | } | |
| 292 | 287 | |
| 293 | 288 | extension ChangeImpactClassification { |
| 294 | 289 | var tone: AppStatusTone { |
DomainDig/StringConveniences.swift added +32
| @@ -0,0 +1,32 @@ | ||
| 1 | import Foundation | |
| 2 | ||
| 3 | /// Two different questions, with two names. | |
| 4 | /// | |
| 5 | /// Seven files used to declare a private `nilIfEmpty`, and one of them — | |
| 6 | /// `DomainInsightEngine` — trimmed whitespace first while the rest did not, so | |
| 7 | /// the same name meant two things and nothing could be shared (A14). Naming the | |
| 8 | /// trimming one `nilIfBlank` separates them, which is what lets there be one | |
| 9 | /// copy of each. | |
| 10 | extension String { | |
| 11 | /// `nil` when there is nothing at all, keeping a string of spaces. | |
| 12 | /// | |
| 13 | /// For values already normalised upstream, where whitespace would be | |
| 14 | /// content rather than noise. | |
| 15 | var nilIfEmpty: String? { | |
| 16 | isEmpty ? nil : self | |
| 17 | } | |
| 18 | ||
| 19 | /// `nil` when there is nothing but whitespace, and trimmed otherwise. | |
| 20 | /// | |
| 21 | /// For values straight from a text field or an imported row. | |
| 22 | var nilIfBlank: String? { | |
| 23 | let trimmed = trimmingCharacters(in: .whitespacesAndNewlines) | |
| 24 | return trimmed.isEmpty ? nil : trimmed | |
| 25 | } | |
| 26 | } | |
| 27 | ||
| 28 | extension Array where Element == String { | |
| 29 | var nilIfEmpty: [String]? { | |
| 30 | isEmpty ? nil : self | |
| 31 | } | |
| 32 | } | |
DomainDigTests/DomainNameTests.swift +27
| @@ -77,6 +77,33 @@ final class DomainNameTests: XCTestCase { | ||
| 77 | 77 | ) |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | /// C8: the probe used to look only at a label's first few characters, so | |
| 81 | /// an unencodable character sitting after them reported `.labelTooLong` | |
| 82 | /// instead of `.malformedLabel`. | |
| 83 | /// | |
| 84 | /// Calibrated on the character rather than hard-coded, because which | |
| 85 | /// scalars IDNA refuses is Foundation's business and moves between | |
| 86 | /// releases. If none of the candidates is refused, there is nothing to | |
| 87 | /// assert on this runtime. | |
| 88 | func testAnUnencodableCharacterIsMalformedWhereverItSitsInTheLabel() throws { | |
| 89 | let candidates = ["\u{200B}", "\u{FFFF}", "\u{2E2F}", "\u{1D173}"] | |
| 90 | guard let unencodable = candidates.first(where: { character in | |
| 91 | DomainName.validate("\(character).com") == .failure(.malformedLabel(character)) | |
| 92 | }) else { | |
| 93 | throw XCTSkip("no IDNA-unencodable character among the candidates on this runtime") | |
| 94 | } | |
| 95 | ||
| 96 | // Far enough in that the old eight-character prefix probe missed it, | |
| 97 | // and short enough that the label cannot be over the byte limit. | |
| 98 | let label = String(repeating: "a", count: 20) + unencodable | |
| 99 | ||
| 100 | XCTAssertEqual( | |
| 101 | DomainName.validate("\(label).com"), | |
| 102 | .failure(.malformedLabel(label)), | |
| 103 | "an unencodable character past the probe length still makes the label malformed" | |
| 104 | ) | |
| 105 | } | |
| 106 | ||
| 80 | 107 | func testAcceptsAUnicodeHost() { |
| 81 | 108 | XCTAssertEqual(DomainName.validate("münchen.de"), .success("münchen.de")) |
| 82 | 109 | } |
DomainDigTests/Fixtures/SnapshotFixture.swift +2 −1
| @@ -272,12 +272,13 @@ enum SnapshotFixture { | ||
| 272 | 272 | |
| 273 | 273 | static func provenance( |
| 274 | 274 | source: String = "test", |
| 275 | provider: String? = nil, | |
| 275 | 276 | resultSource: LookupResultSource = .live |
| 276 | 277 | ) -> SectionProvenance { |
| 277 | 278 | SectionProvenance( |
| 278 | 279 | source: source, |
| 279 | 280 | collectedAt: referenceDate, |
| 280 | provider: nil, | |
| 281 | provider: provider, | |
| 281 | 282 | resolver: nil, |
| 282 | 283 | resultSource: resultSource |
| 283 | 284 | ) |
DomainDigTests/SectionStateTests.swift +55 −17
| @@ -47,6 +47,51 @@ final class SectionStateTests: XCTestCase { | ||
| 47 | 47 | /// Starting a lookup puts every section in flight; applying a snapshot |
| 48 | 48 | /// takes them all out of it. Nothing may be left loading, or the section |
| 49 | 49 | /// spins forever. |
| 50 | // MARK: Provenance (A12) | |
| 51 | ||
| 52 | /// Provenance used to be recovered from the saved history entry, so it was | |
| 53 | /// empty until the snapshot had been written. It now comes from the | |
| 54 | /// snapshot itself, which is visible here because nothing is saved. | |
| 55 | func testProvenanceIsAvailableBeforeTheSnapshotIsSaved() { | |
| 56 | let viewModel = makeViewModel() | |
| 57 | let provenance = SnapshotFixture.provenance(source: "DNS-over-HTTPS query", provider: "Selected DoH resolver") | |
| 58 | ||
| 59 | viewModel.applySnapshot( | |
| 60 | SnapshotFixture.snapshot(provenanceBySection: [.dns: provenance]) | |
| 61 | ) | |
| 62 | ||
| 63 | XCTAssertNil(viewModel.currentHistoryEntryID, "nothing should have been saved") | |
| 64 | XCTAssertEqual(viewModel.currentSnapshot.provenanceBySection[.dns], provenance) | |
| 65 | } | |
| 66 | ||
| 67 | /// The case the finding called out: a lookup that ends with a status | |
| 68 | /// message returns before saving, so this was the state in which every | |
| 69 | /// section showed no source at all. | |
| 70 | func testProvenanceSurvivesASnapshotThatWouldNotBeSaved() { | |
| 71 | let viewModel = makeViewModel() | |
| 72 | let provenance = SnapshotFixture.provenance(source: "RDAP domain lookup", provider: "rdap.org") | |
| 73 | ||
| 74 | viewModel.applySnapshot( | |
| 75 | SnapshotFixture.snapshot(provenanceBySection: [.ownership: provenance]) | |
| 76 | ) | |
| 77 | ||
| 78 | XCTAssertEqual(viewModel.currentSnapshot.provenanceBySection[.ownership], provenance) | |
| 79 | XCTAssertEqual(viewModel.currentSnapshot.provenanceBySection.count, 1) | |
| 80 | } | |
| 81 | ||
| 82 | /// Reset drops it, so a cleared screen does not keep claiming a source. | |
| 83 | func testResetClearsTheInspectionMetadata() { | |
| 84 | let viewModel = makeViewModel() | |
| 85 | viewModel.applySnapshot( | |
| 86 | SnapshotFixture.snapshot(provenanceBySection: [.dns: SnapshotFixture.provenance()]) | |
| 87 | ) | |
| 88 | XCTAssertFalse(viewModel.currentSnapshot.provenanceBySection.isEmpty) | |
| 89 | ||
| 90 | viewModel.reset() | |
| 91 | ||
| 92 | XCTAssertTrue(viewModel.currentSnapshot.provenanceBySection.isEmpty) | |
| 93 | } | |
| 94 | ||
| 50 | 95 | func testApplyingASnapshotSettlesEverySection() { |
| 51 | 96 | let viewModel = makeViewModel() |
| 52 | 97 | _ = viewModel.beginLookup(for: "example.com") |
| @@ -195,29 +240,22 @@ final class SectionStateTests: XCTestCase { | ||
| 195 | 240 | |
| 196 | 241 | // MARK: Provenance |
| 197 | 242 | |
| 198 | /// Provenance does not come from the snapshot that was just applied. | |
| 199 | /// `currentSnapshot` reads it from the saved history entry | |
| 200 | /// (`DomainViewModel:623`), and `applySnapshot` stores it nowhere — so | |
| 201 | /// between applying and saving, and on a lookup that ends with a status | |
| 202 | /// message and is therefore never saved, the cards show no provenance at | |
| 203 | /// all. Recorded as A12. | |
| 243 | /// Provenance now comes from the snapshot that was just applied, which is | |
| 244 | /// A12 closed. It used to be recovered from the saved history entry, so | |
| 245 | /// between applying and saving — and on a lookup that ends with a status | |
| 246 | /// message and is therefore never saved — the cards showed none at all. | |
| 204 | 247 | /// |
| 205 | /// This pins the behaviour as it is rather than as it should be, so that | |
| 206 | /// A2's collapse can carry provenance with the section state and change | |
| 207 | /// this test deliberately. | |
| 208 | func testProvenanceIsNotCarriedByTheAppliedSnapshot() { | |
| 248 | /// This asserts through the section slice the view consumes, which is what | |
| 249 | /// the earlier version of this test pinned in the opposite direction. | |
| 250 | func testTheAppliedSnapshotCarriesProvenanceToTheSection() { | |
| 209 | 251 | let viewModel = makeViewModel() |
| 252 | let provenance = SnapshotFixture.provenance(source: "Direct TLS handshake", provider: "Target host") | |
| 210 | 253 | |
| 211 | 254 | viewModel.applySnapshot( |
| 212 | SnapshotFixture.snapshot( | |
| 213 | provenanceBySection: [.ssl: SnapshotFixture.provenance(source: "test")] | |
| 214 | ) | |
| 255 | SnapshotFixture.snapshot(provenanceBySection: [.ssl: provenance]) | |
| 215 | 256 | ) |
| 216 | 257 | |
| 217 | XCTAssertNil( | |
| 218 | viewModel.webSectionData.tls.provenance, | |
| 219 | "provenance now survives applySnapshot — update this test and close A12" | |
| 220 | ) | |
| 258 | XCTAssertEqual(viewModel.webSectionData.tls.provenance, provenance) | |
| 221 | 259 | } |
| 222 | 260 | |
| 223 | 261 | // MARK: A second lookup clears the first one's results |