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

Implement config changes to UA #2037

Merged
merged 8 commits into from
Oct 3, 2023
Merged

Implement config changes to UA #2037

merged 8 commits into from
Oct 3, 2023

Conversation

jaceklyp
Copy link
Contributor

Task/Issue URL: https://app.asana.com/0/0/1205442309571983/f
CC: @jonathanKingston

Description:
It allows to modify UA through config by either using the old logic, safari UA or safari UA with DDG component.

Steps to test this PR: TBD
1.
2.

private func closestLogic(forUrl url: URL?,
isDesktop: Bool,
privacyConfig: PrivacyConfiguration = ContentBlocking.shared.privacyConfigurationManager.privacyConfig) -> String {
let customUAEnabled = privacyConfig.isEnabled(featureKey: .customUserAgent)
Copy link
Contributor

Choose a reason for hiding this comment

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

From the logic it turns out that func closestLogic is only called when the customUAEnabled is enabled.

@miasma13
Copy link
Contributor

Overall it looks fine. One small comment and the tests are failing due to user agent changes.

return defaultSafari
}

private func ddgFixedLogic(isDesktop: Bool) -> String {
Copy link
Collaborator

@jonathanKingston jonathanKingston Sep 29, 2023

Choose a reason for hiding this comment

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

This method should be the closest policy, fixed will contain the DuckDuckGo part.

Maybe the confusion came in that this is now a fixed UA, but the fixed policy is about repairing known issues in our existing UA.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This method shouldn't be used when the user is <16.6 also.

Copy link
Contributor

@miasma13 miasma13 left a comment

Choose a reason for hiding this comment

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

LGTM

if let match = regex?.firstMatch(in: baseAgent, range: NSRange(baseAgent.startIndex..., in: baseAgent)) {
let range = Range(match.range(at: 1), in: baseAgent)
if let range = range {
return String(baseAgent[range])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've not validated yet this but the approach looks correct.

return true
private var shouldUseUpdatedLogic: Bool {
guard let webKitVersion else { return false }
return webKitVersion.versionCompare("605.1.15") != .orderedAscending
Copy link
Collaborator

@jonathanKingston jonathanKingston Oct 2, 2023

Choose a reason for hiding this comment

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

I think this will be true for "605.1.14" and "605.1.16" etc which is incorrect.

I think the following might be what we're wanting:

Suggested change
return webKitVersion.versionCompare("605.1.15") != .orderedAscending
return webKitVersion.versionCompare("605.1.14") == .orderedDescending

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this is fine - added two tests that should validate that - please could you take a look at them?

@@ -28,6 +28,8 @@ final class UserAgentTests: XCTestCase {
private struct DefaultAgent {
static let mobile = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"
static let tablet = "Mozilla/5.0 (iPad; CPU OS 12_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"
static let oldWebkitVersionMobile = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4 like Mac OS X) AppleWebKit/605.1.14 (KHTML, like Gecko) Mobile/15E148"
static let newWebkitVersionMobile = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4 like Mac OS X) AppleWebKit/605.1.16 (KHTML, like Gecko) Mobile/15E148"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you also add a test for AppleWebKit/605.1.15 too? I'm a little nervous based on that comparison

Copy link
Contributor Author

Choose a reason for hiding this comment

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

of course, I didn't add it initially, because pretty much everything else testes this use case

}) { return ddgFixedLogic(forUrl: url, isDesktop: isDesktop, privacyConfig: privacyConfig) }

if closestUserAgentVersions(forConfig: privacyConfig).contains(statistics.atbWeek ?? "") {
if canUseClosestLogic {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could bury this check within the closestLogic as you have for ddgFixedLogic and just keep the single other check within ddgFixedLogic to keep the fall-back behaviour correct.

But also... we're going to rip this out quickly again hopefully too; so feel free to ignore.

Copy link
Contributor Author

@jaceklyp jaceklyp Oct 2, 2023

Choose a reason for hiding this comment

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

That was my initial idea, but it caused a side effect that made one test fail - when the closest user agent "could not be used" because of old webkit version it fallbacked to oldUserAgentLogic which returned the old UA string which contained "DuckDuckGo/7" component. So inside ddgFixedLogic we were appending yet another DuckDuckGo/7 component.

So my idea was to make it as specific as it can be, because we want to remove it soon.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah you'd still need the check in ddgFixedLogic to keep the same structure I think that should work (but also not tried).

@jaceklyp jaceklyp merged commit 9ec80b6 into develop Oct 3, 2023
5 of 6 checks passed
@jaceklyp jaceklyp deleted the jacek/ua branch October 3, 2023 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants