Skip to content

Commit

Permalink
Use malicious site protection remote settings
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandroboron committed Jan 10, 2025
1 parent f575a61 commit 4d87dab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 4d87dab

Please sign in to comment.