Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #8155: Update user agent for iOS 17. #8156

Merged
merged 1 commit into from
Sep 26, 2023
Merged
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
13 changes: 12 additions & 1 deletion Sources/Shared/UserAgentBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public struct UserAgentBuilder {
// These are not super precise because each iOS version can have slighly different desktop UA.
// The only differences are with exact `Version/XX` and `MAC OS X 10_XX` numbers.
private var desktopUA: String {

let iOS17DesktopUA =
"""
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) \
AppleWebKit/605.1.15 (KHTML, like Gecko) \
Version/17.0 \
Safari/605.1.15
"""

let iOS16DesktopUA =
"""
Expand Down Expand Up @@ -85,7 +93,8 @@ public struct UserAgentBuilder {
case 14: return iOS14DesktopUA
case 15: return iOS15DesktopUA
case 16: return iOS16DesktopUA
default: return iOS16DesktopUA
case 17: return iOS17DesktopUA
default: return iOS17DesktopUA
}
}

Expand All @@ -108,6 +117,7 @@ public struct UserAgentBuilder {
case 14: return "14_6"
case 15: return "15_5"
case 16: return "16_6"
case 17: return "17_0_1"
default: return "\(os.majorVersion)_0"

}
Expand All @@ -120,6 +130,7 @@ public struct UserAgentBuilder {
case 14: return "14.1.1"
case 15: return "15.5"
case 16: return "16.6"
case 17: return "17.0"
default: return "\(os.majorVersion).0"
}
}
Expand Down
60 changes: 54 additions & 6 deletions Tests/SharedTests/UserAgentBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ class UserAgentBuilderTests: XCTestCase {
Version/16.6 \
Safari/605.1.15
"""

let iOS17DesktopUA =
"""
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) \
AppleWebKit/605.1.15 (KHTML, like Gecko) \
Version/17.0 \
Safari/605.1.15
"""

let iOS13 = OperatingSystemVersion(majorVersion: 13, minorVersion: 0, patchVersion: 0)

Expand Down Expand Up @@ -101,6 +109,18 @@ class UserAgentBuilderTests: XCTestCase {
iOS16DesktopUA,
UserAgentBuilder(device: iPad, iOSVersion: iOS16).build(desktopMode: true),
"iOS 16 desktop User Agent on iPad doesn't match")

let iOS17 = OperatingSystemVersion(majorVersion: 17, minorVersion: 0, patchVersion: 1)

XCTAssertEqual(
iOS17DesktopUA,
UserAgentBuilder(device: iPhone, iOSVersion: iOS17).build(desktopMode: true),
"iOS 16 desktop User Agent on iPhone doesn't match")

XCTAssertEqual(
iOS17DesktopUA,
UserAgentBuilder(device: iPad, iOSVersion: iOS17).build(desktopMode: true),
"iOS 16 desktop User Agent on iPad doesn't match")
}

func testSpecificMobileUA() {
Expand All @@ -113,6 +133,34 @@ class UserAgentBuilderTests: XCTestCase {
// At the moment each iOS version has one corresponding Safari UA attached
// so for example 13.1 and 13.3 have the same UA.

// MARK: - iOS 17
let iPhone_safari_17_UA = """
Mozilla/5.0 (iPhone; CPU iPhone OS 17_0_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) \
Version/17.0 \
Mobile/15E148 \
Safari/604.1
"""

let iPad_safari_17_UA = """
Mozilla/5.0 (iPad; CPU OS 17_0_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) \
Version/17.0 \
Mobile/15E148 \
Safari/604.1
"""

// MARK: 17.0.1
let ios17_0_1 = OperatingSystemVersion(majorVersion: 17, minorVersion: 0, patchVersion: 1)

XCTAssertEqual(
iPhone_safari_17_UA,
UserAgentBuilder(device: iPhone, iOSVersion: ios17_0_1).build(desktopMode: false),
"User agent for iOS 17.0.1 iPhone doesn't match.")

XCTAssertEqual(
iPad_safari_17_UA,
UserAgentBuilder(device: iPad, iOSVersion: ios17_0_1).build(desktopMode: false),
"User agent for iOS 17.0.1 iPad doesn't match.")

// MARK: - iOS 16
let iPhone_safari_16_UA = """
Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) \
Expand Down Expand Up @@ -257,25 +305,25 @@ class UserAgentBuilderTests: XCTestCase {
}

func testFutureProofDesktopUA() {
let iOS16DesktopUA =
let iOS17DesktopUA =
"""
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) \
AppleWebKit/605.1.15 (KHTML, like Gecko) \
Version/16.6 \
Version/17.0 \
Safari/605.1.15
"""

let iOS34 = OperatingSystemVersion(majorVersion: 34, minorVersion: 0, patchVersion: 0)

XCTAssertEqual(
iOS16DesktopUA,
iOS17DesktopUA,
UserAgentBuilder(device: iPhone, iOSVersion: iOS34).build(desktopMode: true),
"iOS 16 fallback desktop User Agent on iPhone doesn't match")
"iOS 17 fallback desktop User Agent on iPhone doesn't match")

XCTAssertEqual(
iOS16DesktopUA,
iOS17DesktopUA,
UserAgentBuilder(device: iPad, iOSVersion: iOS34).build(desktopMode: true),
"iOS 16 fallback desktop User Agent on iPad doesn't match")
"iOS 17 fallback desktop User Agent on iPad doesn't match")
}

func testFutureProofMobileUA() {
Expand Down