Skip to content

Commit

Permalink
Merge branch 'main' into anh/netp-pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
quanganhdo committed Dec 8, 2023
2 parents 99e460e + 33e5510 commit c48c55f
Show file tree
Hide file tree
Showing 20 changed files with 236 additions and 154 deletions.
16 changes: 8 additions & 8 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/duckduckgo-autofill.git",
"state" : {
"revision" : "93677cc02cfe650ce7f417246afd0e8e972cd83e",
"version" : "10.0.0"
"revision" : "dbecae0df07650a21b5632a92fa2e498c96af7b5",
"version" : "10.0.1"
}
},
{
Expand All @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/privacy-dashboard",
"state" : {
"revision" : "daa9708223b4b4318fb6448ca44801dfabcddc6f",
"version" : "3.0.0"
"revision" : "38336a574e13090764ba09a6b877d15ee514e371",
"version" : "3.1.1"
}
},
{
Expand All @@ -59,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "6b2aa2748a7881eebb9f84fb10c01293e15b52ca",
"version" : "0.5.0"
"revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531",
"version" : "1.2.3"
}
},
{
Expand All @@ -86,8 +86,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/TrackerRadarKit",
"state" : {
"revision" : "4684440d03304e7638a2c8086895367e90987463",
"version" : "1.2.1"
"revision" : "a6b7ba151d9dc6684484f3785293875ec01cc1ff",
"version" : "1.2.2"
}
},
{
Expand Down
11 changes: 7 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ let package = Package(
.library(name: "SecureStorage", targets: ["SecureStorage"])
],
dependencies: [
.package(url: "https://github.com/duckduckgo/duckduckgo-autofill.git", exact: "10.0.0"),
.package(url: "https://github.com/duckduckgo/duckduckgo-autofill.git", exact: "10.0.1"),
.package(url: "https://github.com/duckduckgo/GRDB.swift.git", exact: "2.2.0"),
.package(url: "https://github.com/duckduckgo/TrackerRadarKit", exact: "1.2.1"),
.package(url: "https://github.com/duckduckgo/TrackerRadarKit", exact: "1.2.2"),
.package(url: "https://github.com/duckduckgo/sync_crypto", exact: "0.2.0"),
.package(url: "https://github.com/gumob/PunycodeSwift.git", exact: "2.1.0"),
.package(url: "https://github.com/duckduckgo/privacy-dashboard", exact: "3.1.1" ),
.package(url: "https://github.com/duckduckgo/content-scope-scripts", exact: "4.52.0"),
.package(url: "https://github.com/duckduckgo/privacy-dashboard", exact: "3.0.0"),
.package(url: "https://github.com/httpswift/swifter.git", exact: "1.5.0"),
.package(url: "https://github.com/duckduckgo/bloom_cpp.git", exact: "3.0.0"),
.package(url: "https://github.com/duckduckgo/wireguard-apple", exact: "1.1.1")
Expand Down Expand Up @@ -251,7 +251,10 @@ let package = Package(
.copy("Resources/Bookmarks_V2.sqlite-wal"),
.copy("Resources/Bookmarks_V3.sqlite"),
.copy("Resources/Bookmarks_V3.sqlite-shm"),
.copy("Resources/Bookmarks_V3.sqlite-wal")
.copy("Resources/Bookmarks_V3.sqlite-wal"),
.copy("Resources/Bookmarks_V4.sqlite"),
.copy("Resources/Bookmarks_V4.sqlite-shm"),
.copy("Resources/Bookmarks_V4.sqlite-wal")
]),
.testTarget(
name: "BrowserServicesKitTests",
Expand Down
2 changes: 1 addition & 1 deletion Sources/Bookmarks/FaviconsFetcher/FaviconFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class FaviconFetcher: NSObject, FaviconFetching {
let metadataFetcher = LPMetadataProvider()

// Allow LinkPresentation to fail so that we can fall back to fetching hardcoded paths
let metadata: LPLinkMetadata? = await {
let metadata: LPLinkMetadata? = await { @MainActor in
if #available(iOS 15.0, macOS 12.0, *) {
var request = URLRequest(url: url)
request.attribution = .user
Expand Down
15 changes: 5 additions & 10 deletions Sources/DDGSync/internal/AccountManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,12 @@ struct AccountManager: AccountManaging {
throw SyncError.noToken
}

let devices = try await fetchDevicesForAccount(account)

// Logout other devices first or the call will fail
for device in devices.filter({ $0.id != account.deviceId }) {
try await logout(deviceId: device.id, token: token)
}
let request = api.createAuthenticatedJSONRequest(url: endpoints.deleteAccount, method: .POST, authToken: token)
let result = try await request.execute()
let statusCode = result.response.statusCode

// This is the last device, the backend will perge the data after this
// An explicit delete account endpoint might be better though
if let thisDevice = devices.first(where: { $0.id == account.deviceId }) {
try await logout(deviceId: thisDevice.id, token: token)
guard statusCode == 204 else {
throw SyncError.unexpectedStatusCode(statusCode)
}
}

Expand Down
5 changes: 4 additions & 1 deletion Sources/DDGSync/internal/Endpoints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ class Endpoints {
private(set) var baseURL: URL

private(set) var signup: URL
private(set) var connect: URL
private(set) var login: URL
private(set) var logoutDevice: URL
private(set) var connect: URL
private(set) var deleteAccount: URL

private(set) var syncGet: URL
private(set) var syncPatch: URL
Expand All @@ -47,6 +48,7 @@ class Endpoints {
signup = baseURL.appendingPathComponent("sync/signup")
login = baseURL.appendingPathComponent("sync/login")
logoutDevice = baseURL.appendingPathComponent("sync/logout-device")
deleteAccount = baseURL.appendingPathComponent("sync/delete-account")
connect = baseURL.appendingPathComponent("sync/connect")

syncGet = baseURL.appendingPathComponent("sync")
Expand All @@ -63,6 +65,7 @@ extension Endpoints {
signup = baseURL.appendingPathComponent("sync/signup")
login = baseURL.appendingPathComponent("sync/login")
logoutDevice = baseURL.appendingPathComponent("sync/logout-device")
deleteAccount = baseURL.appendingPathComponent("sync/delete-account")
connect = baseURL.appendingPathComponent("sync/connect")

syncGet = baseURL.appendingPathComponent("sync")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension RemoteAPIRequestCreating {
func createAuthenticatedJSONRequest(url: URL,
method: HTTPRequestMethod,
authToken: String,
json: Data,
json: Data? = nil,
headers: [String: String] = [:],
parameters: [String: String] = [:]) -> HTTPRequesting {
var headers = headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//

import Foundation
import Common

public protocol NetworkProtectionLocationListRepository {
func fetchLocationList() async throws -> [NetworkProtectionLocation]
Expand All @@ -26,17 +27,24 @@ final public class NetworkProtectionLocationListCompositeRepository: NetworkProt
@MainActor private static var locationList: [NetworkProtectionLocation] = []
private let client: NetworkProtectionClient
private let tokenStore: NetworkProtectionTokenStore
private let errorEvents: EventMapping<NetworkProtectionError>

convenience public init(environment: VPNSettings.SelectedEnvironment, tokenStore: NetworkProtectionTokenStore) {
convenience public init(environment: VPNSettings.SelectedEnvironment,
tokenStore: NetworkProtectionTokenStore,
errorEvents: EventMapping<NetworkProtectionError>) {
self.init(
client: NetworkProtectionBackendClient(environment: environment),
tokenStore: tokenStore
tokenStore: tokenStore,
errorEvents: errorEvents
)
}

init(client: NetworkProtectionClient, tokenStore: NetworkProtectionTokenStore) {
init(client: NetworkProtectionClient,
tokenStore: NetworkProtectionTokenStore,
errorEvents: EventMapping<NetworkProtectionError>) {
self.client = client
self.tokenStore = tokenStore
self.errorEvents = errorEvents
}

@MainActor
Expand All @@ -50,11 +58,15 @@ final public class NetworkProtectionLocationListCompositeRepository: NetworkProt
}
Self.locationList = try await client.getLocations(authToken: authToken).get()
} catch let error as NetworkProtectionErrorConvertible {
errorEvents.fire(error.networkProtectionError)
throw error.networkProtectionError
} catch let error as NetworkProtectionError {
errorEvents.fire(error)
throw error
} catch {
throw NetworkProtectionError.unhandledError(function: #function, line: #line, error: error)
let unhandledError = NetworkProtectionError.unhandledError(function: #function, line: #line, error: error)
errorEvents.fire(unhandledError)
throw unhandledError
}
return Self.locationList
}
Expand Down
6 changes: 5 additions & 1 deletion Sources/NetworkProtection/Settings/RoutingRange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public enum RoutingRange {

public static let alwaysExcludedIPv4Ranges: [RoutingRange] = [
.section("IPv4 - Always Excluded"),
.range("10.0.0.0/8" /* 255.0.0.0 */, description: "disabled for enforceRoutes"),
// This is disabled because excluded routes seem to trump included routes, and our DNS
// server's IP address lives in this range.
// Ref: https://app.asana.com/0/1203708860857015/1206099277258514/f
//
// .range("10.0.0.0/8" /* 255.0.0.0 */, description: "disabled for enforceRoutes"),
.range("100.64.0.0/16" /* 255.255.0.0 */, description: "Shared Address Space"),
.range("127.0.0.0/8" /* 255.0.0.0 */, description: "Loopback"),
.range("169.254.0.0/16" /* 255.255.0.0 */, description: "Link-local"),
Expand Down
2 changes: 1 addition & 1 deletion Sources/PrivacyDashboard/Model/CookieConsentInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct CookieConsentInfo: Encodable {
let optoutFailed: Bool?
let selftestFailed: Bool?
let configurable = true

public init(consentManaged: Bool, cosmetic: Bool?, optoutFailed: Bool?, selftestFailed: Bool?) {
self.consentManaged = consentManaged
self.cosmetic = cosmetic
Expand Down
2 changes: 1 addition & 1 deletion Sources/PrivacyDashboard/Model/ProtectionStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import Foundation

public struct ProtectionStatus: Encodable {

let unprotectedTemporary: Bool
let enabledFeatures: [String]
let allowlisted: Bool
Expand Down
10 changes: 5 additions & 5 deletions Sources/PrivacyDashboard/Model/TrackerInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public struct TrackerInfo: Encodable {
case requests
case installedSurrogates
}

public private (set) var trackers = Set<DetectedRequest>()
private(set) var thirdPartyRequests = Set<DetectedRequest>()
public private(set) var installedSurrogates = Set<String>()

public init() { }

// MARK: - Collecting detected elements
Expand All @@ -43,12 +43,12 @@ public struct TrackerInfo: Encodable {
public mutating func add(detectedThirdPartyRequest request: DetectedRequest) {
thirdPartyRequests.insert(request)
}

public mutating func addInstalledSurrogateHost(_ host: String, for tracker: DetectedRequest, onPageWithURL url: URL) {
guard tracker.pageUrl == url.absoluteString else { return }
installedSurrogates.insert(host)
}

// MARK: - Helper accessors

public var trackersBlocked: [DetectedRequest] {
Expand All @@ -67,5 +67,5 @@ public struct TrackerInfo: Encodable {
try container.encode(allRequests, forKey: .requests)
try container.encode(installedSurrogates, forKey: .installedSurrogates)
}

}
Loading

0 comments on commit c48c55f

Please sign in to comment.