Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authv2 / Networking improvements #3820

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing just these allows us to remove NetworkProtection as dependency of Core and "flatten" the dependency tree, solving possible runtime issues during testing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diegoreymendez Do you have anything against this change? I can explain the rationale if needed.

case networkProtectionLatencyError

case networkProtectionEnabledOnSearch
Expand Down Expand Up @@ -1381,7 +1380,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
162 changes: 104 additions & 58 deletions DuckDuckGo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"revision" : "b3a8ea5ef9821203fe88a12e3f15ad48b7278a6a",
"version" : "224.7.2"
"branch" : "fcappelli/authv2/networking_improvements",
"revision" : "a426daed5e348a0f0e179f010733edae5c74da6e"
}
},
{
"identity" : "content-scope-scripts",
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/content-scope-scripts",
"state" : {
"revision" : "0502ed7de4130bd8705daebaca9aeb20d3e62d15",
"version" : "7.5.0"
"revision" : "7958ddab724c26326333cae13fe81478290607fa",
"version" : "7.6.0"
}
},
{
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 Expand Up @@ -176,8 +203,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/sync_crypto",
"state" : {
"revision" : "0c8bf3c0e75591bc366407b9d7a73a9fcfc7736f",
"version" : "0.3.0"
"revision" : "cc726cebb67367466bc31ced4784e16d44ac68d1",
"version" : "0.4.0"
}
},
{
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.map({ item in (key: item.key, value: item.value) }), 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