Skip to content

Commit c5bf651

Browse files
committed
Added test to verify timestamps-as-strings pass verification
1 parent 9203e49 commit c5bf651

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

JWTTests/JWTTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ class JWTDecodeTests : XCTestCase {
131131
XCTAssertEqual(payload as NSDictionary, ["exp": 1728188491])
132132
}
133133
}
134+
135+
func testUnexpiredClaimString() {
136+
// If this just started failing, hello 2024!
137+
let jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxNzI4MTg4NDkxIn0.y4w7lNLrfRRPzuNUfM-ZvPkoOtrTU_d8ZVYasLdZGpk"
138+
assertSuccess(try decode(jwt, algorithm: .HS256("secret"))) { payload in
139+
XCTAssertEqual(payload as NSDictionary, ["exp": "1728188491"])
140+
}
141+
}
134142

135143
// MARK: Not before claim
136144

@@ -140,6 +148,13 @@ class JWTDecodeTests : XCTestCase {
140148
XCTAssertEqual(payload as NSDictionary, ["nbf": 1428189720])
141149
}
142150
}
151+
152+
func testNotBeforeClaimString() {
153+
let jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOiIxNDI4MTg5NzIwIn0.qZsj36irdmIAeXv6YazWDSFbpuxHtEh4Deof5YTpnVI"
154+
assertSuccess(try decode(jwt, algorithm: .HS256("secret"))) { payload in
155+
XCTAssertEqual(payload as NSDictionary, ["nbf": "1428189720"])
156+
}
157+
}
143158

144159
func testInvalidNotBeforeClaim() {
145160
let jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOlsxNDI4MTg5NzIwXX0.PUL1FQubzzJa4MNXe2D3d5t5cMaqFr3kYlzRUzly-C8"
@@ -160,6 +175,13 @@ class JWTDecodeTests : XCTestCase {
160175
XCTAssertEqual(payload as NSDictionary, ["iat": 1428189720])
161176
}
162177
}
178+
179+
func testIssuedAtClaimInThePastString() {
180+
let jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOiIxNDI4MTg5NzIwIn0.M8veWtsY52oBwi7LRKzvNnzhjK0QBS8Su1r0atlns2k"
181+
assertSuccess(try decode(jwt, algorithm: .HS256("secret"))) { payload in
182+
XCTAssertEqual(payload as NSDictionary, ["iat": "1428189720"])
183+
}
184+
}
163185

164186
func testIssuedAtClaimInTheFuture() {
165187
// If this just started failing, hello 2024!

0 commit comments

Comments
 (0)