Skip to content

Commit

Permalink
Fix incorrect branded UA (#2662)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1177771139624306/1207102109845550/f
CC: @jonathanKingston 

**Description**:
Fix incorrect branded UA

**Steps to test this PR**:
1. Open any site and check if the UA is equal to "Mozilla/5.0
(Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like
Gecko) Version/17.1 Safari/605.1.15"
  • Loading branch information
jaceklyp authored Apr 18, 2024
1 parent f0ce53f commit 1b0f864
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "46989693916f56d1186bd59ac15124caef896560",
"version" : "1.3.1"
Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/UserAgent/Model/UserAgent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extension UserAgent {
return version
}()

static let ddgVersion: String = safariVersion.appending(" Ddg/\(safariVersion)")
static let ddgVersion: String = "Ddg/\(safariVersion)"

// MARK: - User Agents

Expand All @@ -66,7 +66,7 @@ extension UserAgent {
"Safari/537.36"
static let `default` = UserAgent.safari
static let webViewDefault = ""
static let brandedDefault = Self.default.appending(ddgVersion)
static let brandedDefault = "\(Self.default) \(ddgVersion)"

static let localUserAgentConfiguration: KeyValuePairs<RegEx, String> = [
// use safari when serving up PDFs from duckduckgo directly
Expand Down
9 changes: 9 additions & 0 deletions UnitTests/UserAgent/Model/UserAgentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ final class UserAgentTests: XCTestCase {
XCTAssertNotEqual(UserAgent.for("https://duckduckgo.com".url, privacyConfig: config), UserAgent.webViewDefault)
}

func testWhenDefaultPolicyIsBrandThenBrandedUserAgentIsUsed() {
let config = MockPrivacyConfiguration()
config.featureSettings = [
"defaultPolicy": "brand"
] as! [String: Any]

XCTAssertEqual(UserAgent.for("http://wikipedia.org".url, privacyConfig: config), UserAgent.brandedDefault)
}

func testThatRemoteConfigurationTakesPrecedenceOverLocalConfiguration() {
let config = MockPrivacyConfiguration()

Expand Down

0 comments on commit 1b0f864

Please sign in to comment.