Skip to content

Commit f2bbd1d

Browse files
committed
See if explicitly handling Ints in parsing JWT times fixes Ubuntu builds
1 parent 65dfb1a commit f2bbd1d

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

Sources/JWT/ClaimSet.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ func parseTimeInterval(_ value: Any?) -> Date? {
66
if let string = value as? String, let interval = TimeInterval(string) {
77
return Date(timeIntervalSince1970: interval)
88
}
9+
10+
if let interval = value as? Int {
11+
let double = Double(interval)
12+
return Date(timeIntervalSince1970: double)
13+
}
914

1015
if let interval = value as? TimeInterval {
1116
return Date(timeIntervalSince1970: interval)

Tests/JWTTests/JWTDecodeTests.swift

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,7 @@ class DecodeTests: XCTestCase {
5757
let jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjgxODg0OTF9.EW7k-8Mvnv0GpvOKJalFRLoCB3a3xGG3i7hAZZXNAz0"
5858

5959
let claims = try JWT.decode(jwt, algorithm: .hs256("secret".data(using: .utf8)!))
60-
61-
if let expirationClaim = claims.expiration?.timeIntervalSince1970 {
62-
XCTAssertEqual(Int(expirationClaim), 1728188491)
63-
} else {
64-
XCTFail()
65-
}
60+
XCTAssertEqual(claims.expiration?.timeIntervalSince1970, 1728188491)
6661
}
6762

6863
func testUnexpiredClaimString() throws {
@@ -79,11 +74,7 @@ class DecodeTests: XCTestCase {
7974
let jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0MjgxODk3MjB9.jFT0nXAJvEwyG6R7CMJlzNJb7FtZGv30QRZpYam5cvs"
8075

8176
let claims = try JWT.decode(jwt, algorithm: .hs256("secret".data(using: .utf8)!))
82-
if let notBeforeClaim = claims.notBefore?.timeIntervalSince1970 {
83-
XCTAssertEqual(Int(notBeforeClaim), 1428189720)
84-
} else {
85-
XCTFail()
86-
}
77+
XCTAssertEqual(claims.notBefore?.timeIntervalSince1970, 1428189720)
8778
}
8879

8980
func testNotBeforeClaimString() throws {
@@ -110,11 +101,7 @@ class DecodeTests: XCTestCase {
110101
let jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0MjgxODk3MjB9.I_5qjRcCUZVQdABLwG82CSuu2relSdIyJOyvXWUAJh4"
111102

112103
let claims = try JWT.decode(jwt, algorithm: .hs256("secret".data(using: .utf8)!))
113-
if let issuedAtClaim = claims.issuedAt?.timeIntervalSince1970 {
114-
XCTAssertEqual(Int(issuedAtClaim), 1428189720)
115-
} else {
116-
XCTFail()
117-
}
104+
XCTAssertEqual(claims.issuedAt?.timeIntervalSince1970, 1428189720)
118105
}
119106

120107
func testIssuedAtClaimInThePastString() throws {

0 commit comments

Comments
 (0)