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

Fix local to en_US_POSIX in dates by SharedKeyAuthenticationProvider #28

Merged
merged 1 commit into from
Jul 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public final class SharedKeyAuthenticationProvider: AuthenticationHeaderProvider
if (rfcDate?.isEmpty ?? true) {
let formatter = DateFormatter()
formatter.timeZone = TimeZone(identifier: "UTC")
formatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss 'GMT'" // RFC
formatter.locale = Locale(identifier: "en_US_POSIX") // consistent regardless of the user's device
formatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss 'GMT'" // RFC 1123
rfcDate = formatter.string(from: Date())
request.setValue(rfcDate, forHTTPHeaderField: dateHeaderName)
}
Expand Down
7 changes: 4 additions & 3 deletions Tests/TingleApiClientTests/SharedKeyProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SharedKeyProviderTests: XCTestCase {
let url = URL(string: "https://scoppe.people.tinglesoftware.com/api/v1.1/iprs?idNumber=12345678")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("Tue, 26 Dec 2017 23:09:28 GMT", forHTTPHeaderField: "x-ms-date")
request.setValue("Tue, 26 Dec 2017 23:09:28 GMT", forHTTPHeaderField: "x-ms-date") // RFC 1123

// prepare the authentication provider
let provider = SharedKeyAuthenticationProvider(base64Key: "TiR0p2ZwnUuBGBEDU5LADWBXpxXy3Y9Aq4Fb1nD+6CM=")
Expand All @@ -38,7 +38,7 @@ class SharedKeyProviderTests: XCTestCase {
request.httpMethod = "POST"
request.httpBody = "{}".data(using: .utf8)
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("Tue, 26 Dec 2017 23:09:28 GMT", forHTTPHeaderField: "x-ms-date")
request.setValue("Tue, 26 Dec 2017 23:09:28 GMT", forHTTPHeaderField: "x-ms-date") // RFC 1123

// prepare the authentication provider
let provider = SharedKeyAuthenticationProvider(base64Key: "TiR0p2ZwnUuBGBEDU5LADWBXpxXy3Y9Aq4Fb1nD+6CM=")
Expand Down Expand Up @@ -69,7 +69,8 @@ class SharedKeyProviderTests: XCTestCase {
XCTAssertNotNil(headerValue)
let formatter = DateFormatter()
formatter.timeZone = TimeZone(identifier: "UTC")
formatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss 'GMT'" // RFC
formatter.locale = Locale(identifier: "en_US_POSIX") // consistent regardless of the user's device
formatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss 'GMT'" // RFC 1123
let date = formatter.date(from: headerValue!)
XCTAssertNotNil(date)
XCTAssertTrue(date! < Date())
Expand Down