Skip to content

Commit

Permalink
Merge branch 'main' into bartek/tune-unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bwaresiak committed Nov 21, 2024
2 parents c57f322 + f5f0a13 commit d980060
Show file tree
Hide file tree
Showing 63 changed files with 857 additions and 432 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sync-end-to-end.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
timeout-minutes: 90
strategy:
matrix:
os-version: [15, 16, 17]
os-version: [17] #[15, 16, 17]
max-parallel: 1 # Uncomment this line to run tests sequentially.
fail-fast: false

Expand Down
4 changes: 4 additions & 0 deletions Core/BoolFileMarkerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ final class BoolFileMarkerTests: XCTestCase {
let fileURL = try XCTUnwrap(testFileURL)

let attributes = try FileManager.default.attributesOfItem(atPath: fileURL.path)
#if targetEnvironment(simulator)
XCTAssertNil(attributes[.protectionKey])
#else
XCTAssertEqual(attributes[.protectionKey] as? FileProtectionType, FileProtectionType.none)
#endif
XCTAssertTrue(FileManager.default.fileExists(atPath: fileURL.path))
XCTAssertEqual(marker.isPresent, true)
}
Expand Down
4 changes: 2 additions & 2 deletions Core/CookieStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class CookieStorage {

/// Update ALL cookies. The absence of cookie domains here indicateds they have been removed by the website, so be sure to call this with all cookies that might need to be persisted even if those websites have not been visited yet.
@discardableResult
func updateCookies(_ cookies: [HTTPCookie], keepingPreservedLogins preservedLogins: PreserveLogins) -> CookieDomainsOnUpdateDiagnostic {
func updateCookies(_ cookies: [HTTPCookie], preservingFireproofedDomains fireproofing: Fireproofing) -> CookieDomainsOnUpdateDiagnostic {
guard isConsumed else { return .notConsumed }

isConsumed = false
Expand Down Expand Up @@ -130,7 +130,7 @@ public class CookieStorage {
persistedCookiesByDomain.keys.forEach {
guard !URL.isDuckDuckGo(domain: $0) else { return } // DDG cookies are for SERP settings only

if !preservedLogins.isAllowed(cookieDomain: $0) {
if !fireproofing.isAllowed(cookieDomain: $0) {
persistedCookiesByDomain.removeValue(forKey: $0)
}
}
Expand Down
31 changes: 31 additions & 0 deletions Core/FaviconHasher.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// FaviconHasher.swift
// DuckDuckGo
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//


import Foundation
import Kingfisher

public struct FaviconHasher {

static let salt = "DDGSalt:"
public static func createHash(ofDomain domain: String) -> String {
return "\(Self.salt)\(domain)".sha256()
}

}
1 change: 1 addition & 0 deletions Core/FaviconRequestModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// limitations under the License.
//

import Core
import Kingfisher

class FaviconRequestModifier: ImageDownloadRequestModifier {
Expand Down
43 changes: 43 additions & 0 deletions Core/FaviconsCacheType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// FaviconsCacheType.swift
// DuckDuckGo
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

public enum FaviconsCacheType: String {

static let faviconsFolderName = "Favicons"

case tabs
case fireproof

public func cacheLocation() -> URL? {
return baseCacheURL()?.appendingPathComponent(Self.faviconsFolderName)
}

private func baseCacheURL() -> URL? {
switch self {
case .fireproof:
let groupName = BookmarksDatabase.Constants.bookmarksGroupID
return FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupName)

case .tabs:
return FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first
}
}
}
34 changes: 0 additions & 34 deletions Core/FaviconsHelper.swift

This file was deleted.

5 changes: 5 additions & 0 deletions Core/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public enum FeatureFlag: String {

/// https://app.asana.com/0/72649045549333/1208617860225199/f
case networkProtectionEnforceRoutes

/// https://app.asana.com/0/1208592102886666/1208613627589762/f
case crashReportOptInStatusResetting
}

extension FeatureFlag: FeatureFlagDescribing {
Expand Down Expand Up @@ -118,6 +121,8 @@ extension FeatureFlag: FeatureFlagDescribing {
return .remoteDevelopment(.subfeature(NetworkProtectionSubfeature.enforceRoutes))
case .adAttributionReporting:
return .remoteReleasable(.feature(.adAttributionReporting))
case .crashReportOptInStatusResetting:
return .internalOnly
}
}
}
Expand Down
26 changes: 20 additions & 6 deletions Core/PreserveLogins.swift → Core/Fireproofing.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// PreserveLogins.swift
// Fireproofing.swift
// Core
//
// Copyright © 2020 DuckDuckGo. All rights reserved.
Expand All @@ -19,18 +19,32 @@

import Foundation

public class PreserveLogins {
public protocol Fireproofing {

var loginDetectionEnabled: Bool { get set }
var allowedDomains: [String] { get }

func isAllowed(cookieDomain: String) -> Bool
func isAllowed(fireproofDomain domain: String) -> Bool
func addToAllowed(domain: String)
func remove(domain: String)
func clearAll()

}

// This class is not final because we override allowed domains in WebCacheManagerTests
public class UserDefaultsFireproofing: Fireproofing {

public static let shared: Fireproofing = UserDefaultsFireproofing()

public struct Notifications {
public static let loginDetectionStateChanged = Foundation.Notification.Name("com.duckduckgo.ios.PreserveLogins.loginDetectionStateChanged")
}

public static let shared = PreserveLogins()

@UserDefaultsWrapper(key: .preserveLoginsAllowedDomains, defaultValue: [])
@UserDefaultsWrapper(key: .fireproofingAllowedDomains, defaultValue: [])
private(set) public var allowedDomains: [String]

@UserDefaultsWrapper(key: .preserveLoginsDetectionEnabled, defaultValue: false)
@UserDefaultsWrapper(key: .fireproofingDetectionEnabled, defaultValue: false)
public var loginDetectionEnabled: Bool {
didSet {
NotificationCenter.default.post(name: Notifications.loginDetectionStateChanged, object: nil)
Expand Down
1 change: 1 addition & 0 deletions Core/NotFoundCachingDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// limitations under the License.
//

import Core
import Kingfisher

class NotFoundCachingDownloader: ImageDownloader {
Expand Down
8 changes: 6 additions & 2 deletions Core/SyncBookmarksAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public final class SyncBookmarksAdapter {
public let databaseCleaner: BookmarkDatabaseCleaner
public let syncDidCompletePublisher: AnyPublisher<Void, Never>
let syncErrorHandler: SyncErrorHandling
private let faviconStoring: FaviconStoring

@UserDefaultsWrapper(key: .syncDidMigrateToImprovedListsHandling, defaultValue: false)
private var didMigrateToImprovedListsHandling: Bool
Expand All @@ -88,10 +89,13 @@ public final class SyncBookmarksAdapter {

public init(database: CoreDataDatabase,
favoritesDisplayModeStorage: FavoritesDisplayModeStoring,
syncErrorHandler: SyncErrorHandling) {
syncErrorHandler: SyncErrorHandling,
faviconStoring: FaviconStoring) {
self.database = database
self.favoritesDisplayModeStorage = favoritesDisplayModeStorage
self.syncErrorHandler = syncErrorHandler
self.faviconStoring = faviconStoring

syncDidCompletePublisher = syncDidCompleteSubject.eraseToAnyPublisher()
databaseCleaner = BookmarkDatabaseCleaner(
bookmarkDatabase: database,
Expand Down Expand Up @@ -172,7 +176,7 @@ public final class SyncBookmarksAdapter {
database: database,
stateStore: stateStore,
fetcher: FaviconFetcher(),
faviconStore: Favicons.shared,
faviconStore: faviconStoring,
errorEvents: BookmarksFaviconsFetcherErrorHandler()
)
}
Expand Down
6 changes: 4 additions & 2 deletions Core/SyncDataProviders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@ public class SyncDataProviders: DataProvidersSource {
secureVaultErrorReporter: SecureVaultReporting,
settingHandlers: [SettingSyncHandler],
favoritesDisplayModeStorage: FavoritesDisplayModeStoring,
syncErrorHandler: SyncErrorHandling
syncErrorHandler: SyncErrorHandling,
faviconStoring: FaviconStoring
) {
self.bookmarksDatabase = bookmarksDatabase
self.secureVaultFactory = secureVaultFactory
self.secureVaultErrorReporter = secureVaultErrorReporter
bookmarksAdapter = SyncBookmarksAdapter(database: bookmarksDatabase,
favoritesDisplayModeStorage: favoritesDisplayModeStorage,
syncErrorHandler: syncErrorHandler)
syncErrorHandler: syncErrorHandler,
faviconStoring: faviconStoring)
credentialsAdapter = SyncCredentialsAdapter(secureVaultFactory: secureVaultFactory,
secureVaultErrorReporter: secureVaultErrorReporter,
syncErrorHandler: syncErrorHandler)
Expand Down
6 changes: 3 additions & 3 deletions Core/UserDefaultsPropertyWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public struct UserDefaultsWrapper<T> {
case gridViewEnabled = "com.duckduckgo.ios.tabs.grid"
case gridViewSeen = "com.duckduckgo.ios.tabs.seen"

case preserveLoginsAllowedDomains = "com.duckduckgo.ios.PreserveLogins.userDecision.allowedDomains2"
case preserveLoginsDetectionEnabled = "com.duckduckgo.ios.PreserveLogins.detectionEnabled"
case preserveLoginsLegacyAllowedDomains = "com.duckduckgo.ios.PreserveLogins.userDecision.allowedDomains"
case fireproofingAllowedDomains = "com.duckduckgo.ios.PreserveLogins.userDecision.allowedDomains2"
case fireproofingDetectionEnabled = "com.duckduckgo.ios.PreserveLogins.detectionEnabled"
case fireproofingLegacyAllowedDomains = "com.duckduckgo.ios.PreserveLogins.userDecision.allowedDomains"

case daxIsDismissed = "com.duckduckgo.ios.daxOnboardingIsDismissed"
case daxHomeScreenMessagesSeen = "com.duckduckgo.ios.daxOnboardingHomeScreenMessagesSeen"
Expand Down
4 changes: 2 additions & 2 deletions Core/WebCacheManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class WebCacheManager {
}

public func clear(cookieStorage: CookieStorage = CookieStorage(),
logins: PreserveLogins = PreserveLogins.shared,
fireproofing: Fireproofing = UserDefaultsFireproofing.shared,
dataStoreIdManager: DataStoreIdManaging = DataStoreIdManager.shared) async {

var cookiesToUpdate = [HTTPCookie]()
Expand All @@ -92,7 +92,7 @@ public class WebCacheManager {
// Perform legacy clearing to migrate to new container
cookiesToUpdate += await legacyDataClearing() ?? []

cookieStorage.updateCookies(cookiesToUpdate, keepingPreservedLogins: logins)
cookieStorage.updateCookies(cookiesToUpdate, preservingFireproofedDomains: fireproofing)

// Attempt to clean up leftover stores again after a delay
// This should not be a problem as these containers are not supposed to be used anymore.
Expand Down
Loading

0 comments on commit d980060

Please sign in to comment.