Skip to content

Commit

Permalink
Authv2 / Networking improvements (#3820)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1205842942115003/1209170372758735/f

**Description**:

- Small changes for Networking v2 updates
- Removed `Timport TestUtils` and replaced with the new dedicate test
utils for each package
- Dependency tree improved by removing `NetworkProtection` as
`Core.framework` dependency and avoiding runtime issues during testing
like:

```
NetworkProtection NetworkProtectionConnectionBandwidthAnalyzer is implemented in both 
/Core.framework/Core (0x10950f248)
/UnitTests.xctest/UnitTests (0x11873c4e0). One of the two will be used. Which one is undefined.
```
  • Loading branch information
federicocappelli authored Jan 27, 2025
1 parent 87bbd35 commit cf6d456
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 41 deletions.
5 changes: 2 additions & 3 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import BrowserServicesKit
import Bookmarks
import Configuration
import DDGSync
import NetworkProtection

extension Pixel {

Expand Down Expand Up @@ -413,7 +412,7 @@ extension Pixel {
case networkProtectionTunnelFailureDetected
case networkProtectionTunnelFailureRecovered

case networkProtectionLatency(quality: NetworkProtectionLatencyMonitor.ConnectionQuality)
case networkProtectionLatency(quality: String)
case networkProtectionLatencyError

case networkProtectionEnabledOnSearch
Expand Down Expand Up @@ -1382,7 +1381,7 @@ extension Pixel.Event {
case .networkProtectionConnectionTesterExtendedFailureRecovered: return "m_netp_connection_tester_extended_failure_recovered"
case .networkProtectionTunnelFailureDetected: return "m_netp_ev_tunnel_failure"
case .networkProtectionTunnelFailureRecovered: return "m_netp_ev_tunnel_failure_recovered"
case .networkProtectionLatency(let quality): return "m_netp_ev_\(quality.rawValue)_latency"
case .networkProtectionLatency(let quality): return "m_netp_ev_\(quality)_latency"
case .networkProtectionLatencyError: return "m_netp_ev_latency_error_d"
case .networkProtectionRekeyAttempt: return "m_netp_rekey_attempt"
case .networkProtectionRekeyCompleted: return "m_netp_rekey_completed"
Expand Down
36 changes: 18 additions & 18 deletions DuckDuckGo-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@
98424A982CED4F430071C7DB /* ContentBlocking in Frameworks */ = {isa = PBXBuildFile; productRef = 984249C62CED4F430071C7DB /* ContentBlocking */; };
98424A992CED4F430071C7DB /* SubscriptionTestingUtilities in Frameworks */ = {isa = PBXBuildFile; productRef = 984249C92CED4F430071C7DB /* SubscriptionTestingUtilities */; };
98424A9A2CED4F430071C7DB /* Subscription in Frameworks */ = {isa = PBXBuildFile; productRef = 984249C82CED4F430071C7DB /* Subscription */; };
98424A9B2CED4F430071C7DB /* TestUtils in Frameworks */ = {isa = PBXBuildFile; productRef = 984249C52CED4F430071C7DB /* TestUtils */; };
98424A9C2CED4F430071C7DB /* NetworkProtectionTestUtils in Frameworks */ = {isa = PBXBuildFile; productRef = 984249C32CED4F430071C7DB /* NetworkProtectionTestUtils */; };
98424A9D2CED4F430071C7DB /* Common in Frameworks */ = {isa = PBXBuildFile; productRef = 984249C72CED4F430071C7DB /* Common */; };
98424AAB2CED4FF10071C7DB /* CookieStorageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85AD49ED2B6149110085D2D1 /* CookieStorageTests.swift */; };
Expand Down Expand Up @@ -1173,7 +1172,6 @@
F1134ED21F40EF3A00B73467 /* JsonTestDataLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1134ECF1F40EBE200B73467 /* JsonTestDataLoader.swift */; };
F1134ED61F40F29F00B73467 /* StatisticsUserDefaultsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1134ED41F40F15800B73467 /* StatisticsUserDefaultsTests.swift */; };
F114C55B1E66EB020018F95F /* NibLoading.swift in Sources */ = {isa = PBXBuildFile; fileRef = F114C55A1E66EB020018F95F /* NibLoading.swift */; };
F115ED9C2B4EFC8E001A0453 /* TestUtils in Frameworks */ = {isa = PBXBuildFile; productRef = F115ED9B2B4EFC8E001A0453 /* TestUtils */; };
F130D73A1E5776C500C45811 /* OmniBarDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F130D7391E5776C500C45811 /* OmniBarDelegate.swift */; };
F132D6A52C62239B00D85426 /* SubscriptionSettingsHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F132D6A42C62239B00D85426 /* SubscriptionSettingsHeaderView.swift */; };
F1386BA41E6846C40062FC3C /* TabDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1386BA31E6846C40062FC3C /* TabDelegate.swift */; };
Expand Down Expand Up @@ -1214,6 +1212,8 @@
F194FAFB1F14E622009B4DF8 /* UIFontExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F194FAFA1F14E622009B4DF8 /* UIFontExtensionTests.swift */; };
F198D78E1E39762C0088DA8A /* StringExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F198D78D1E39762C0088DA8A /* StringExtensionTests.swift */; };
F1A886781F29394E0096251E /* WebCacheManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1A886771F29394E0096251E /* WebCacheManager.swift */; };
F1A8C6F62D47841B00BBBF5B /* PersistenceTestingUtils in Frameworks */ = {isa = PBXBuildFile; productRef = F1A8C6F52D47841B00BBBF5B /* PersistenceTestingUtils */; };
F1A8C6F82D47843C00BBBF5B /* PersistenceTestingUtils in Frameworks */ = {isa = PBXBuildFile; productRef = F1A8C6F72D47843C00BBBF5B /* PersistenceTestingUtils */; };
F1AE54E81F0425FC00D9A700 /* AuthenticationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1AE54E71F0425FC00D9A700 /* AuthenticationViewController.swift */; };
F1BDDBFD2C340D9C00459306 /* SubscriptionContainerViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1BDDBF92C340D9C00459306 /* SubscriptionContainerViewModelTests.swift */; };
F1BDDBFE2C340D9C00459306 /* SubscriptionFlowViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1BDDBFA2C340D9C00459306 /* SubscriptionFlowViewModelTests.swift */; };
Expand Down Expand Up @@ -3305,9 +3305,9 @@
F486D3362506A037002D07D7 /* OHHTTPStubs in Frameworks */,
F486D3382506A225002D07D7 /* OHHTTPStubsSwift in Frameworks */,
4BE67B052B96B9AB007335F7 /* ContentBlocking in Frameworks */,
F1A8C6F82D47843C00BBBF5B /* PersistenceTestingUtils in Frameworks */,
F15531922BF215ED0029ED04 /* SubscriptionTestingUtilities in Frameworks */,
F15531902BF215ED0029ED04 /* Subscription in Frameworks */,
F115ED9C2B4EFC8E001A0453 /* TestUtils in Frameworks */,
EEFAB4672A73C230008A38E4 /* NetworkProtectionTestUtils in Frameworks */,
4BE67B072B96B9B0007335F7 /* Common in Frameworks */,
);
Expand Down Expand Up @@ -3373,9 +3373,9 @@
98424A972CED4F430071C7DB /* OHHTTPStubsSwift in Frameworks */,
98424A982CED4F430071C7DB /* ContentBlocking in Frameworks */,
98424AB22CEDD6150071C7DB /* BrowserServicesKit in Frameworks */,
F1A8C6F62D47841B00BBBF5B /* PersistenceTestingUtils in Frameworks */,
98424A992CED4F430071C7DB /* SubscriptionTestingUtilities in Frameworks */,
98424A9A2CED4F430071C7DB /* Subscription in Frameworks */,
98424A9B2CED4F430071C7DB /* TestUtils in Frameworks */,
98424A9C2CED4F430071C7DB /* NetworkProtectionTestUtils in Frameworks */,
98424A9D2CED4F430071C7DB /* Common in Frameworks */,
);
Expand Down Expand Up @@ -7114,11 +7114,11 @@
F486D3352506A037002D07D7 /* OHHTTPStubs */,
F486D3372506A225002D07D7 /* OHHTTPStubsSwift */,
EEFAB4662A73C230008A38E4 /* NetworkProtectionTestUtils */,
F115ED9B2B4EFC8E001A0453 /* TestUtils */,
4BE67B042B96B9AB007335F7 /* ContentBlocking */,
4BE67B062B96B9B0007335F7 /* Common */,
F155318F2BF215ED0029ED04 /* Subscription */,
F15531912BF215ED0029ED04 /* SubscriptionTestingUtilities */,
F1A8C6F72D47843C00BBBF5B /* PersistenceTestingUtils */,
);
productName = DuckDuckGoTests;
productReference = 84E341A61E2F7EFB00BDBA6F /* UnitTests.xctest */;
Expand Down Expand Up @@ -7248,13 +7248,13 @@
984249C02CED4F430071C7DB /* OHHTTPStubs */,
984249C22CED4F430071C7DB /* OHHTTPStubsSwift */,
984249C32CED4F430071C7DB /* NetworkProtectionTestUtils */,
984249C52CED4F430071C7DB /* TestUtils */,
984249C62CED4F430071C7DB /* ContentBlocking */,
984249C72CED4F430071C7DB /* Common */,
984249C82CED4F430071C7DB /* Subscription */,
984249C92CED4F430071C7DB /* SubscriptionTestingUtilities */,
98424AB12CEDD6150071C7DB /* BrowserServicesKit */,
98424AB32CEDD61C0071C7DB /* BrowserServicesKitTestsUtils */,
F1A8C6F52D47841B00BBBF5B /* PersistenceTestingUtils */,
);
productName = DuckDuckGoTests;
productReference = 98424AA92CED4F430071C7DB /* WebViewUnitTests.xctest */;
Expand Down Expand Up @@ -11960,8 +11960,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 230.1.0;
branch = fcappelli/authv2/networking_improvements;
kind = branch;
};
};
9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down Expand Up @@ -12193,11 +12193,6 @@
package = 984249C42CED4F430071C7DB /* XCRemoteSwiftPackageReference "BrowserServicesKit" */;
productName = NetworkProtectionTestUtils;
};
984249C52CED4F430071C7DB /* TestUtils */ = {
isa = XCSwiftPackageProductDependency;
package = 984249C42CED4F430071C7DB /* XCRemoteSwiftPackageReference "BrowserServicesKit" */;
productName = TestUtils;
};
984249C62CED4F430071C7DB /* ContentBlocking */ = {
isa = XCSwiftPackageProductDependency;
package = 984249C42CED4F430071C7DB /* XCRemoteSwiftPackageReference "BrowserServicesKit" */;
Expand Down Expand Up @@ -12315,11 +12310,6 @@
package = 98A16C2928A11BDE00A6C003 /* XCRemoteSwiftPackageReference "BrowserServicesKit" */;
productName = NetworkProtectionTestUtils;
};
F115ED9B2B4EFC8E001A0453 /* TestUtils */ = {
isa = XCSwiftPackageProductDependency;
package = 98A16C2928A11BDE00A6C003 /* XCRemoteSwiftPackageReference "BrowserServicesKit" */;
productName = TestUtils;
};
F155318F2BF215ED0029ED04 /* Subscription */ = {
isa = XCSwiftPackageProductDependency;
package = 98A16C2928A11BDE00A6C003 /* XCRemoteSwiftPackageReference "BrowserServicesKit" */;
Expand All @@ -12340,6 +12330,16 @@
package = 98A16C2928A11BDE00A6C003 /* XCRemoteSwiftPackageReference "BrowserServicesKit" */;
productName = SubscriptionTestingUtilities;
};
F1A8C6F52D47841B00BBBF5B /* PersistenceTestingUtils */ = {
isa = XCSwiftPackageProductDependency;
package = 98A16C2928A11BDE00A6C003 /* XCRemoteSwiftPackageReference "BrowserServicesKit" */;
productName = PersistenceTestingUtils;
};
F1A8C6F72D47843C00BBBF5B /* PersistenceTestingUtils */ = {
isa = XCSwiftPackageProductDependency;
package = 98A16C2928A11BDE00A6C003 /* XCRemoteSwiftPackageReference "BrowserServicesKit" */;
productName = PersistenceTestingUtils;
};
F1D43AF92B99C1D300BAB743 /* BareBonesBrowserKit */ = {
isa = XCSwiftPackageProductDependency;
package = F1D43AF82B99C1D300BAB743 /* XCRemoteSwiftPackageReference "BareBonesBrowser" */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"revision" : "2ed8705a2e8a0ba6cb5253ccf3b2f73f98da6bb0",
"version" : "230.1.0"
"branch" : "fcappelli/authv2/networking_improvements",
"revision" : "2e2a6a4b38f29ede2eae8eadfa4d3f0ae54ca744"
}
},
{
Expand Down Expand Up @@ -90,6 +90,15 @@
"version" : "2.0.0"
}
},
{
"identity" : "jwt-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/jwt-kit.git",
"state" : {
"revision" : "c2595b9ad7f512d7f334830b4df1fed6e917946a",
"version" : "4.13.4"
}
},
{
"identity" : "kingfisher",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -144,6 +153,24 @@
"version" : "1.4.0"
}
},
{
"identity" : "swift-asn1",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-asn1.git",
"state" : {
"revision" : "ae33e5941bb88d88538d0a6b19ca0b01e6c76dcf",
"version" : "1.3.1"
}
},
{
"identity" : "swift-crypto",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "ff0f781cf7c6a22d52957e50b104f5768b50c779",
"version" : "3.10.0"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
Expand Down
6 changes: 5 additions & 1 deletion DuckDuckGo/AppLifecycle/AppStates/Launching.swift
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,11 @@ struct Launching: AppState {

let url = URL.pixelUrl(forPixelNamed: pixelName)
let apiHeaders = APIRequestV2.HeadersV2(additionalHeaders: headers)
let request = APIRequestV2(url: url, method: .get, queryItems: parameters, headers: apiHeaders)
guard let request = APIRequestV2(url: url, method: .get, queryItems: parameters.toQueryItems(), headers: apiHeaders) else {
assertionFailure("Invalid request Pixel request")
onComplete(false, nil)
return
}
Task {
do {
_ = try await DefaultAPIService().fetch(request: request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ final class UnifiedFeedbackFormViewModel: ObservableObject {
problemSubCategory: selectedSubcategory ?? "",
customMetadata: metadata?.toString() ?? "")
let headers = APIRequestV2.HeadersV2(additionalHeaders: [HTTPHeaderKey.authorization: "Bearer \(accessToken)"])
let request = APIRequestV2(url: Self.feedbackEndpoint, method: .post, headers: headers, body: payload.toData())
guard let request = APIRequestV2(url: Self.feedbackEndpoint, method: .post, headers: headers, body: payload.toData()) else {
assertionFailure("Invalid request")
return
}

let response: Response = try await apiService.fetch(request: request).decodeBody()
if let error = response.error, !error.isEmpty {
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGoTests/AdAttributionFetcherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import XCTest

@testable import DuckDuckGo
@testable import TestUtils
import PersistenceTestingUtils
import NetworkingTestingUtils

final class AdAttributionFetcherTests: XCTestCase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import History

@testable import Core
@testable import DuckDuckGo
@testable import TestUtils
@testable import PersistenceTestingUtils

final class AutocompleteSuggestionsDataSourceTests: XCTestCase {

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGoTests/AutofillLoginListViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Combine
@testable import Core
@testable import BrowserServicesKit
@testable import Common
@testable import TestUtils
@testable import PersistenceTestingUtils

class AutofillLoginListViewModelTests: XCTestCase {

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGoTests/AutofillVaultKeychainMigratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import XCTest
@testable import Core
import BrowserServicesKit
import TestUtils
import PersistenceTestingUtils

final class AutofillVaultKeychainMigratorTests: XCTestCase {

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGoTests/BookmarkStateRepairTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import XCTest
import CoreData
import Bookmarks
import TestUtils
import PersistenceTestingUtils
@testable import Core
@testable import DuckDuckGo

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGoTests/BookmarksDatabaseSetupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import CoreData
import Bookmarks
@testable import DuckDuckGo
@testable import Core
import TestUtils
import PersistenceTestingUtils

class DummyCoreDataStoreMock: CoreDataStoring {

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGoTests/BookmarksStateValidationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import XCTest
import CoreData
import Bookmarks
import TestUtils
import PersistenceTestingUtils
@testable import Core
@testable import DuckDuckGo

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGoTests/BrokenSiteReportingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import OHHTTPStubsSwift
@testable import Core
import PrivacyDashboard
@testable import DuckDuckGo
import TestUtils
import PersistenceTestingUtils

final class BrokenSiteReportingTests: XCTestCase {
private let data = JsonTestDataLoader()
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGoTests/DailyPixelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import XCTest
import Networking
import TestUtils
import PersistenceTestingUtils
import Persistence
@testable import Core

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGoTests/FireButtonReferenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import XCTest
import os.log
import WebKit
@testable import Core
import TestUtils
import PersistenceTestingUtils

final class FireButtonReferenceTests: XCTestCase {

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGoTests/PersistentPixelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Foundation
import XCTest
import Networking
import Persistence
import TestUtils
import PersistenceTestingUtils
@testable import Core

final class PersistentPixelTests: XCTestCase {
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGoTests/UsageSegmentationStorageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import Foundation
import XCTest
@testable import Core
@testable import TestUtils
@testable import Persistence
import PersistenceTestingUtils

final class UsageSegmentationStorageTests: XCTestCase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ final class NetworkProtectionPacketTunnelProvider: PacketTunnelProvider {
case .quality(let quality):
guard quality != .unknown else { return }
DailyPixel.fireDailyAndCount(
pixel: .networkProtectionLatency(quality: quality),
pixel: .networkProtectionLatency(quality: quality.rawValue),
pixelNameSuffixes: DailyPixel.Constant.legacyDailyPixelSuffixes,
includedParameters: [.appVersion, .atb]
)
Expand Down
2 changes: 1 addition & 1 deletion WebViewUnitTests/CookieStorageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import XCTest
@testable import Core
import WebKit
import Persistence
import TestUtils
import PersistenceTestingUtils

public class CookieStorageTests: XCTestCase {

Expand Down
2 changes: 1 addition & 1 deletion WebViewUnitTests/DataStoreIDManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Foundation
import XCTest
@testable import Core
import WebKit
import TestUtils
import PersistenceTestingUtils

class DataStoreIDManagerTests: XCTestCase {

Expand Down
2 changes: 1 addition & 1 deletion WebViewUnitTests/WebCacheManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import XCTest
@testable import Core
import WebKit
import TestUtils
import PersistenceTestingUtils

extension HTTPCookie {

Expand Down

0 comments on commit cf6d456

Please sign in to comment.