From 4d87dab7f2cea9dae403d0f120d70b58086beb47 Mon Sep 17 00:00:00 2001 From: Alessandro Boron Date: Fri, 10 Jan 2025 11:56:39 +1100 Subject: [PATCH] Use malicious site protection remote settings --- .../MaliciousSiteProtectionManager+Config.swift | 7 ------- .../MaliciousSiteProtectionManager.swift | 11 +++++++++-- .../Mocks/MaliciousSiteProtectionMocks.swift | 6 +++++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/DuckDuckGo/MaliciousSiteProtection/MaliciousSiteProtectionManager+Config.swift b/DuckDuckGo/MaliciousSiteProtection/MaliciousSiteProtectionManager+Config.swift index 4578482ba6..7f04602a87 100644 --- a/DuckDuckGo/MaliciousSiteProtection/MaliciousSiteProtectionManager+Config.swift +++ b/DuckDuckGo/MaliciousSiteProtection/MaliciousSiteProtectionManager+Config.swift @@ -31,13 +31,6 @@ extension MaliciousSiteProtectionManager { } } - static func updateInterval(for dataKind: MaliciousSiteProtection.DataManager.StoredDataType) -> TimeInterval { - switch dataKind { - case .hashPrefixSet: .minutes(20) - case .filterSet: .hours(12) - } - } - struct EmbeddedDataProvider: MaliciousSiteProtection.EmbeddedDataProviding { // swiftlint:disable:next nesting diff --git a/DuckDuckGo/MaliciousSiteProtection/MaliciousSiteProtectionManager.swift b/DuckDuckGo/MaliciousSiteProtection/MaliciousSiteProtectionManager.swift index c4f5fea1bc..a2e76b0799 100644 --- a/DuckDuckGo/MaliciousSiteProtection/MaliciousSiteProtectionManager.swift +++ b/DuckDuckGo/MaliciousSiteProtection/MaliciousSiteProtectionManager.swift @@ -47,7 +47,7 @@ final class MaliciousSiteProtectionManager: MaliciousSiteDetecting { dataManager: MaliciousSiteProtection.DataManager? = nil, detector: MaliciousSiteProtection.MaliciousSiteDetecting? = nil, preferencesManager: MaliciousSiteProtectionPreferencesPublishing = MaliciousSiteProtectionPreferencesManager(), - maliciousSiteProtectionFeatureFlagger: MaliciousSiteProtectionFeatureFlagger = MaliciousSiteProtectionFeatureFlags(), + maliciousSiteProtectionFeatureFlagger: MaliciousSiteProtectionFeatureFlagger & MaliciousSiteProtectionFeatureFlagsSettingsProvider = MaliciousSiteProtectionFeatureFlags(), updateIntervalProvider: UpdateManager.UpdateIntervalProvider? = nil ) { let embeddedDataProvider = EmbeddedDataProvider() @@ -71,11 +71,18 @@ final class MaliciousSiteProtectionManager: MaliciousSiteDetecting { eventMapping: Self.debugEvents ) + let remoteIntervalProvider: (MaliciousSiteProtection.DataManager.StoredDataType) -> TimeInterval = { dataKind in + switch dataKind { + case .hashPrefixSet: .minutes(maliciousSiteProtectionFeatureFlagger.hashPrefixUpdateFrequency) + case .filterSet: .minutes(maliciousSiteProtectionFeatureFlagger.filterSetUpdateFrequency) + } + } + self.updateManager = MaliciousSiteProtection.UpdateManager( apiEnvironment: apiEnvironment, service: apiService, dataManager: dataManager, - updateIntervalProvider: updateIntervalProvider ?? Self.updateInterval + updateIntervalProvider: updateIntervalProvider ?? remoteIntervalProvider ) self.preferencesManager = preferencesManager diff --git a/DuckDuckGoTests/MaliciousSiteProtection/Mocks/MaliciousSiteProtectionMocks.swift b/DuckDuckGoTests/MaliciousSiteProtection/Mocks/MaliciousSiteProtectionMocks.swift index 0944c13579..d576cc1757 100644 --- a/DuckDuckGoTests/MaliciousSiteProtection/Mocks/MaliciousSiteProtectionMocks.swift +++ b/DuckDuckGoTests/MaliciousSiteProtection/Mocks/MaliciousSiteProtectionMocks.swift @@ -114,12 +114,16 @@ final class MockMaliciousSiteProtectionPreferencesManager: MaliciousSiteProtecti } } -final class MockMaliciousSiteProtectionFeatureFlags: MaliciousSiteProtectionFeatureFlagger { +final class MockMaliciousSiteProtectionFeatureFlags: MaliciousSiteProtectionFeatureFlagger, MaliciousSiteProtectionFeatureFlagsSettingsProvider { var shouldDetectMaliciousThreatForDomainResult = false var isMaliciousSiteProtectionEnabled: Bool = false + var hashPrefixUpdateFrequency: Int = 10 + + var filterSetUpdateFrequency: Int = 20 + func shouldDetectMaliciousThreat(forDomain domain: String?) -> Bool { shouldDetectMaliciousThreatForDomainResult }