Skip to content

Commit

Permalink
Merge branch 'main' into brad/new-breakage-parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
SlayterDev committed Mar 14, 2024
2 parents 5b48b05 + 1295a22 commit a8d76cd
Show file tree
Hide file tree
Showing 34 changed files with 213 additions and 312 deletions.
11 changes: 0 additions & 11 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ let package = Package(
"UserScript",
"ContentBlocking",
"SecureStorage",
.product(name: "Macros", package: "apple-toolbox"),
],
resources: [
.process("ContentBlocking/UserScripts/contentblockerrules.js"),
Expand Down Expand Up @@ -150,7 +149,6 @@ let package = Package(
"Common",
.product(name: "DDGSyncCrypto", package: "sync_crypto"),
"Networking",
.product(name: "Macros", package: "apple-toolbox"),
],
resources: [
.process("SyncMetadata.xcdatamodeld"),
Expand Down Expand Up @@ -283,7 +281,6 @@ let package = Package(
dependencies: [
"Networking",
"Persistence",
.product(name: "Macros", package: "apple-toolbox"),
],
plugins: [swiftlintPlugin]
),
Expand All @@ -293,7 +290,6 @@ let package = Package(
.target(name: "WireGuardC"),
.product(name: "WireGuard", package: "wireguard-apple"),
"Common",
.product(name: "Macros", package: "apple-toolbox"),
],
swiftSettings: [
.define("DEBUG", .when(configuration: .debug))
Expand Down Expand Up @@ -330,7 +326,6 @@ let package = Package(
name: "Subscription",
dependencies: [
"Common",
.product(name: "Macros", package: "apple-toolbox"),
],
swiftSettings: [
.define("DEBUG", .when(configuration: .debug))
Expand Down Expand Up @@ -375,7 +370,6 @@ let package = Package(
"RemoteMessaging", // Move tests later (lots of test dependencies in BSK)
"SecureStorageTestsUtils",
"TestUtils",
.product(name: "Macros", package: "apple-toolbox"),
],
resources: [
.copy("Resources")
Expand All @@ -387,7 +381,6 @@ let package = Package(
dependencies: [
"DDGSync",
"TestUtils",
.product(name: "Macros", package: "apple-toolbox"),
],
plugins: [swiftlintPlugin]
),
Expand All @@ -402,7 +395,6 @@ let package = Package(
name: "CommonTests",
dependencies: [
"Common",
.product(name: "Macros", package: "apple-toolbox"),
],
plugins: [swiftlintPlugin]
),
Expand All @@ -418,7 +410,6 @@ let package = Package(
dependencies: [
"Navigation",
.product(name: "Swifter", package: "swifter"),
.product(name: "Macros", package: "apple-toolbox"),
],
resources: [
.copy("Resources")
Expand Down Expand Up @@ -485,7 +476,6 @@ let package = Package(
dependencies: [
"SecureStorage",
"SecureStorageTestsUtils",
.product(name: "Macros", package: "apple-toolbox"),
],
plugins: [swiftlintPlugin]
),
Expand All @@ -494,7 +484,6 @@ let package = Package(
dependencies: [
"PrivacyDashboard",
"TestUtils",
.product(name: "Macros", package: "apple-toolbox"),
],
plugins: [swiftlintPlugin]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
//

import Foundation
import Macros

public protocol SuggestionLoading: AnyObject {

Expand Down
5 changes: 2 additions & 3 deletions Sources/DDGSync/DDGSyncing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import BrowserServicesKit
import Combine
import DDGSyncCrypto
import Foundation
import Macros

public enum SyncAuthState: String, Sendable, Codable {
/// Sync engine is not initialized.
Expand Down Expand Up @@ -177,9 +176,9 @@ public enum ServerEnvironment: LosslessStringConvertible {
var baseURL: URL {
switch self {
case .development:
return #URL("https://dev-sync-use.duckduckgo.com")
return URL(string: "https://dev-sync-use.duckduckgo.com")!
case .production:
return #URL("https://sync.duckduckgo.com")
return URL(string: "https://sync.duckduckgo.com")!
}
}

Expand Down
38 changes: 0 additions & 38 deletions Sources/NetworkProtection/AppLaunching.swift

This file was deleted.

25 changes: 17 additions & 8 deletions Sources/NetworkProtection/NetworkProtectionDeviceManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,28 @@ public actor NetworkProtectionDeviceManager: NetworkProtectionDeviceManagement {
if regenerateKey {
keyPair = keyStore.newKeyPair()
} else {
keyPair = keyStore.currentKeyPair() ?? keyStore.newKeyPair()
// Temporary code added on 2024-03-12 to fix a previous issue where users had a really long
// key expiration date. We should remove this after a month or so.
if let existingKeyPair = keyStore.currentKeyPair(),
existingKeyPair.expirationDate > Date().addingTimeInterval(TimeInterval.day) {

keyPair = keyStore.newKeyPair()
} else {
// This is the regular code to restore when the above code is removed.
keyPair = keyStore.currentKeyPair() ?? keyStore.newKeyPair()
}
}

let (selectedServer, newExpiration) = try await register(keyPair: keyPair, selectionMethod: selectionMethod)
os_log("Server registration successul", log: .networkProtection)

keyStore.updateKeyPair(keyPair)

if let newExpiration {
// We only update the expiration date if it happens before our client-set expiration date.
// This way we respect the client-set expiration date, unless the server has set an earlier
// expiration for whatever reason (like if the subscription is known to expire).
//
if let newExpiration, newExpiration < keyPair.expirationDate {
keyPair = KeyPair(privateKey: keyPair.privateKey, expirationDate: newExpiration)
keyStore.updateKeyPair(keyPair)
}
Expand Down Expand Up @@ -224,9 +237,7 @@ public actor NetworkProtectionDeviceManager: NetworkProtectionDeviceManagement {
// If we're looking to exclude a server we should have a few other options available. If we can't find any
// then it means theres an inconsistency in the server list that was returned.
errorEvents?.fire(NetworkProtectionError.serverListInconsistency)

let cachedServer = try cachedServer(registeredWith: keyPair)
return (cachedServer, nil)
throw NetworkProtectionError.serverListInconsistency
}

selectedServer = registeredServer
Expand All @@ -238,9 +249,7 @@ public actor NetworkProtectionDeviceManager: NetworkProtectionDeviceManagement {
}

handle(clientError: error)

let cachedServer = try cachedServer(registeredWith: keyPair)
return (cachedServer, nil)
throw error
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
//

import Foundation
import Macros

public enum NetworkProtectionAuthenticationMethod {
case inviteCode(String)
Expand Down Expand Up @@ -119,8 +118,8 @@ public struct AuthenticationFailureResponse: Decodable {
final class NetworkProtectionBackendClient: NetworkProtectionClient {

enum Constants {
static let productionEndpoint = #URL("https://controller.netp.duckduckgo.com")
static let stagingEndpoint = #URL("https://staging.netp.duckduckgo.com")
static let productionEndpoint = URL(string: "https://controller.netp.duckduckgo.com")!
static let stagingEndpoint = URL(string: "https://staging.netp.duckduckgo.com")!
}

private enum DecoderError: Error {
Expand Down
2 changes: 1 addition & 1 deletion Sources/NetworkProtection/PacketTunnelProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
serverSelectionMethod: currentServerSelectionMethod,
includedRoutes: includedRoutes ?? [],
excludedRoutes: settings.excludedRanges,
regenerateKey: false)
regenerateKey: true)
startTunnel(with: tunnelConfiguration, onDemand: onDemand, completionHandler: completionHandler)
os_log("🔵 Done generating tunnel config", log: .networkProtection, type: .info)
} catch {
Expand Down
5 changes: 2 additions & 3 deletions Sources/NetworkProtection/Settings/VPNSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import Combine
import Foundation
import Macros

/// Persists and publishes changes to tunnel settings.
///
Expand Down Expand Up @@ -80,9 +79,9 @@ public final class VPNSettings {
public var endpointURL: URL {
switch self {
case .production:
return #URL("https://controller.netp.duckduckgo.com")
return URL(string: "https://controller.netp.duckduckgo.com")!
case .staging:
return #URL("https://staging1.netp.duckduckgo.com")
return URL(string: "https://staging1.netp.duckduckgo.com")!
}
}
}
Expand Down
30 changes: 0 additions & 30 deletions Sources/NetworkProtectionTestUtils/MockAppLauncher.swift

This file was deleted.

5 changes: 2 additions & 3 deletions Sources/Subscription/Services/AuthService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import Common
import Foundation
import Macros

public struct AuthService: APIService {

Expand All @@ -30,9 +29,9 @@ public struct AuthService: APIService {
public static var baseURL: URL {
switch SubscriptionPurchaseEnvironment.currentServiceEnvironment {
case .production:
#URL("https://quack.duckduckgo.com/api/auth")
URL(string: "https://quack.duckduckgo.com/api/auth")!
case .staging:
#URL("https://quackdev.duckduckgo.com/api/auth")
URL(string: "https://quackdev.duckduckgo.com/api/auth")!
}
}

Expand Down
5 changes: 2 additions & 3 deletions Sources/Subscription/Services/SubscriptionService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import Common
import Foundation
import Macros

public final class SubscriptionService: APIService {

Expand All @@ -30,9 +29,9 @@ public final class SubscriptionService: APIService {
public static var baseURL: URL {
switch SubscriptionPurchaseEnvironment.currentServiceEnvironment {
case .production:
#URL("https://subscriptions.duckduckgo.com/api")
URL(string: "https://subscriptions.duckduckgo.com/api")!
case .staging:
#URL("https://subscriptions-dev.duckduckgo.com/api")
URL(string: "https://subscriptions-dev.duckduckgo.com/api")!
}
}

Expand Down
13 changes: 6 additions & 7 deletions Sources/Subscription/URL+Subscription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
//

import Foundation
import Macros

public extension URL {

static var subscriptionBaseURL: URL {
switch SubscriptionPurchaseEnvironment.currentServiceEnvironment {
case .production:
#URL("https://duckduckgo.com/subscriptions")
URL(string: "https://duckduckgo.com/subscriptions")!
case .staging:
#URL("https://duckduckgo.com/subscriptions?environment=staging")
URL(string: "https://duckduckgo.com/subscriptions?environment=staging")!
}
}

Expand All @@ -35,7 +34,7 @@ public extension URL {
}

static var subscriptionFAQ: URL {
#URL("https://duckduckgo.com/about")
URL(string: "https://duckduckgo.com/about")!
}

// MARK: - Subscription Email
Expand All @@ -54,17 +53,17 @@ public extension URL {
// MARK: - App Store app manage subscription URL

static var manageSubscriptionsInAppStoreAppURL: URL {
#URL("macappstores://apps.apple.com/account/subscriptions")
URL(string: "macappstores://apps.apple.com/account/subscriptions")!
}

// MARK: - Identity Theft Restoration

static var identityTheftRestoration: URL {
switch SubscriptionPurchaseEnvironment.currentServiceEnvironment {
case .production:
#URL("https://duckduckgo.com/identity-theft-restoration")
URL(string: "https://duckduckgo.com/identity-theft-restoration")!
case .staging:
#URL("https://duckduckgo.com/identity-theft-restoration?environment=staging")
URL(string: "https://duckduckgo.com/identity-theft-restoration?environment=staging")!
}
}
}
3 changes: 1 addition & 2 deletions Sources/TestUtils/Utils/HTTPURLResponseExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
//

import Foundation
import Macros
import Networking

extension HTTPURLResponse {

static let testEtag = "test-etag"
static let testUrl = #URL("http://www.example.com")
static let testUrl = URL(string: "http://www.example.com")!

static let ok = HTTPURLResponse(url: testUrl,
statusCode: 200,
Expand Down
Loading

0 comments on commit a8d76cd

Please sign in to comment.