From 1694957b27545c45f943e80175eb9dbe4dd7eca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20=C5=81yp?= Date: Tue, 10 Sep 2024 13:24:35 +0200 Subject: [PATCH 1/2] Fix privacy icon glitch --- DuckDuckGo.xcodeproj/project.pbxproj | 4 ++-- .../xcshareddata/swiftpm/Package.resolved | 6 +++--- DuckDuckGo/PrivacyIconLogic.swift | 5 +++-- DuckDuckGo/TabViewController.swift | 7 ++++--- DuckDuckGoTests/PrivacyIconLogicTests.swift | 15 ++++++++++++++- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index 9a57964978..676298259b 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -10772,8 +10772,8 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit"; requirement = { - kind = exactVersion; - version = 191.2.3; + branch = "coldfix/191.2.3-1"; + kind = branch; }; }; 9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 81fa28071f..397dd755f3 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/DuckDuckGo/BrowserServicesKit", "state" : { - "revision" : "b83ccf14b5844e8876de04bcc3074a15569f3b26", - "version" : "191.2.3" + "branch" : "coldfix/191.2.3-1", + "revision" : "3bac7c0924eeebd58b8868ef44489fac0fb7ec44" } }, { @@ -138,7 +138,7 @@ { "identity" : "swift-argument-parser", "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-argument-parser.git", + "location" : "https://github.com/apple/swift-argument-parser", "state" : { "revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b", "version" : "1.4.0" diff --git a/DuckDuckGo/PrivacyIconLogic.swift b/DuckDuckGo/PrivacyIconLogic.swift index 9ae915497f..727d46480e 100644 --- a/DuckDuckGo/PrivacyIconLogic.swift +++ b/DuckDuckGo/PrivacyIconLogic.swift @@ -37,8 +37,9 @@ final class PrivacyIconLogic { } else { let config = ContentBlocking.shared.privacyConfigurationManager.privacyConfig let isUserUnprotected = config.isUserUnprotected(domain: privacyInfo.url.host) - - let notFullyProtected = !privacyInfo.https || isUserUnprotected || privacyInfo.serverTrust == nil + + let isServerTrustInvalid = (privacyInfo.shouldCheckServerTrust ? privacyInfo.serverTrust == nil : false) + let notFullyProtected = !privacyInfo.https || isUserUnprotected || isServerTrustInvalid return notFullyProtected ? .shieldWithDot : .shield } diff --git a/DuckDuckGo/TabViewController.swift b/DuckDuckGo/TabViewController.swift index f413f40730..514b8931de 100644 --- a/DuckDuckGo/TabViewController.swift +++ b/DuckDuckGo/TabViewController.swift @@ -993,7 +993,7 @@ class TabViewController: UIViewController { self.privacyInfo = privacyInfo didGoBackForward = false } else { - privacyInfo = makePrivacyInfo(url: url) + privacyInfo = makePrivacyInfo(url: url, shouldCheckServerTrust: true) } } else { privacyInfo = nil @@ -1001,14 +1001,15 @@ class TabViewController: UIViewController { onPrivacyInfoChanged() } - public func makePrivacyInfo(url: URL) -> PrivacyInfo? { + public func makePrivacyInfo(url: URL, shouldCheckServerTrust: Bool = false) -> PrivacyInfo? { guard let host = url.host else { return nil } let entity = ContentBlocking.shared.trackerDataManager.trackerData.findParentEntityOrFallback(forHost: host) let privacyInfo = PrivacyInfo(url: url, parentEntity: entity, - protectionStatus: makeProtectionStatus(for: host)) + protectionStatus: makeProtectionStatus(for: host), + shouldCheckServerTrust: shouldCheckServerTrust) let isValid = certificateTrustEvaluator.evaluateCertificateTrust(trust: webView.serverTrust) if let isValid { privacyInfo.serverTrust = isValid ? webView.serverTrust : nil diff --git a/DuckDuckGoTests/PrivacyIconLogicTests.swift b/DuckDuckGoTests/PrivacyIconLogicTests.swift index ebecb5d55c..b12ef295e8 100644 --- a/DuckDuckGoTests/PrivacyIconLogicTests.swift +++ b/DuckDuckGoTests/PrivacyIconLogicTests.swift @@ -96,7 +96,7 @@ class PrivacyIconLogicTests: XCTestCase { let url = PrivacyIconLogicTests.pageURL let entity = Entity(displayName: "E", domains: [], prevalence: 100.0) let protectionStatus = ProtectionStatus(unprotectedTemporary: false, enabledFeatures: [], allowlisted: false, denylisted: false) - let privacyInfo = PrivacyInfo(url: url, parentEntity: entity, protectionStatus: protectionStatus) + let privacyInfo = PrivacyInfo(url: url, parentEntity: entity, protectionStatus: protectionStatus, shouldCheckServerTrust: true) let icon = PrivacyIconLogic.privacyIcon(for: privacyInfo) @@ -105,6 +105,19 @@ class PrivacyIconLogicTests: XCTestCase { XCTAssertEqual(icon, .shieldWithDot) } + func testPrivacyIconIsShieldWithoutDotForNoSecTrustAndShouldCheckServerTrustIsFalse() { + let url = PrivacyIconLogicTests.pageURL + let entity = Entity(displayName: "E", domains: [], prevalence: 100.0) + let protectionStatus = ProtectionStatus(unprotectedTemporary: false, enabledFeatures: [], allowlisted: false, denylisted: false) + let privacyInfo = PrivacyInfo(url: url, parentEntity: entity, protectionStatus: protectionStatus) + + let icon = PrivacyIconLogic.privacyIcon(for: privacyInfo) + + XCTAssertTrue(url.isHttps) + XCTAssertTrue(privacyInfo.https) + XCTAssertEqual(icon, .shield) + } + } final class MockSecTrust: SecurityTrust {} From 2c66c93e504080689da8ba727b4ff82528c8024e Mon Sep 17 00:00:00 2001 From: Bartek Waresiak Date: Tue, 10 Sep 2024 15:44:47 +0200 Subject: [PATCH 2/2] Update BSK ref --- DuckDuckGo.xcodeproj/project.pbxproj | 4 ++-- .../xcshareddata/swiftpm/Package.resolved | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index 676298259b..2b2dbb7ae1 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -10772,8 +10772,8 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit"; requirement = { - branch = "coldfix/191.2.3-1"; - kind = branch; + kind = exactVersion; + version = "191.2.3-1"; }; }; 9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 397dd755f3..674a98fc2d 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/DuckDuckGo/BrowserServicesKit", "state" : { - "branch" : "coldfix/191.2.3-1", - "revision" : "3bac7c0924eeebd58b8868ef44489fac0fb7ec44" + "revision" : "3bac7c0924eeebd58b8868ef44489fac0fb7ec44", + "version" : "191.2.3-1" } }, { @@ -138,7 +138,7 @@ { "identity" : "swift-argument-parser", "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-argument-parser", + "location" : "https://github.com/apple/swift-argument-parser.git", "state" : { "revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b", "version" : "1.4.0"