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 #1168

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

federicocappelli
Copy link
Member

@federicocappelli federicocappelli commented Jan 17, 2025

Task/Issue URL: https://app.asana.com/0/1205842942115003/1209170372758735/f
iOS PR: duckduckgo/iOS#3820
macOS PR: duckduckgo/macos-browser#3746
What kind of version bump will this require?: Major (APIRequestV2 init can now return nil, TestUtils library has been replaced)

CC: @miasma13

Description:

Networking v2 Improvements

  • Introduction of RetryPolicy
  • Authentication support improved with refresh callback in case of 401 error
  • Equatable conformance
  • Hashable Conformance
  • APIRequestV2Error Equatable conformance
  • New Oauth framework inside Networking v2
  • Malicious site protection APIClient updated to Networking v2
  • A lot of utilities, moks and improvements added to NetworkingTestingUtils

Additional changes include:

  • DecodableHelper expanded and renamed CodableHelper
  • Date extension with utilities + unit tests
  • Rationalisation of the package "Testing Utils" modules, now every library has its XYZTestingUtils module, I removed the generic TestingUtils

Steps to test this PR:

  • malicious site protection API works as expected

Internal references:

Software Engineering Expectations
Technical Design Template

@federicocappelli federicocappelli requested review from a team, studiosutara and alessandroboron and removed request for a team and studiosutara January 17, 2025 13:28
import Foundation
import Common

extension Dictionary where Key == String, Value == String {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we make it a Collection extension defaulting to KeyValuePairs<String, String> – this will preserve items order

Copy link
Member Author

Choose a reason for hiding this comment

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

Good suggestion thanks, I agree that maintaining the order is a nice to have, I tried to change it in
public typealias QueryItems = any Collection<KeyValuePairs<String, String>>
But that introduces a lot of issues (like can't access values directly by key), then I decided to stuck with

public typealias QueryItem = Dictionary<String, String>.Element
public typealias QueryItems = Array<QueryItem>

Less elegant but achieves the objective of having a data structure of ordered key value pairs

I moved everything to QueryItems.swift

}
urlComps.queryItems = queryItems?.toURLQueryItems(allowedReservedCharacters: allowedQueryReservedCharacters)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are we overwriting existing url components with passed query items, is it intended? It seems not intuitive

Copy link
Member Author

@federicocappelli federicocappelli Jan 17, 2025

Choose a reason for hiding this comment

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

Correct, if a URL already containing query items was passed this would have deleted them, case that I never imagined. Fixed thanks.

QueryParameter.category: configuration.threatKind.rawValue,
QueryParameter.revision: (configuration.revision ?? 0).description,
])
return [QueryParameter.category: configuration.threatKind.rawValue,
Copy link
Collaborator

Choose a reason for hiding this comment

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

addition to my question for APIRequestV2 change, why do we need to overwrite url components with an extra query items parameter? the old url(for:requestType) allowed any url configuration in 1 place, now we need an extra method for it to work. Also it‘s doing url encoding/decoding several times back and forth which seems suboptimal.
I‘d keep an old implementation allowing to combine url items and passed items unless it‘s really needed. Or at least provide some in-code comments why it must be this way and probably add some assertions validating there‘s no URL query items overwritten.

Copy link
Member Author

Choose a reason for hiding this comment

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

In the new Subscription code we don't build the URL before creating the API request, everything happens inside the init, I tried to use the same approach here but I made to many chanhges. As per your previous comment now the APiRequestV2 joins the QueryParams passed and the one already present in the URL, this allowed me to reverte these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants