diff --git a/JWTTests/JWTTests.swift b/JWTTests/JWTTests.swift index 3e0edc6..9f8e4d4 100644 --- a/JWTTests/JWTTests.swift +++ b/JWTTests/JWTTests.swift @@ -131,6 +131,14 @@ class JWTDecodeTests : XCTestCase { XCTAssertEqual(payload as NSDictionary, ["exp": 1728188491]) } } + + func testUnexpiredClaimString() { + // If this just started failing, hello 2024! + let jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxNzI4MTg4NDkxIn0.y4w7lNLrfRRPzuNUfM-ZvPkoOtrTU_d8ZVYasLdZGpk" + assertSuccess(try decode(jwt, algorithm: .HS256("secret"))) { payload in + XCTAssertEqual(payload as NSDictionary, ["exp": "1728188491"]) + } + } // MARK: Not before claim @@ -140,6 +148,13 @@ class JWTDecodeTests : XCTestCase { XCTAssertEqual(payload as NSDictionary, ["nbf": 1428189720]) } } + + func testNotBeforeClaimString() { + let jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOiIxNDI4MTg5NzIwIn0.qZsj36irdmIAeXv6YazWDSFbpuxHtEh4Deof5YTpnVI" + assertSuccess(try decode(jwt, algorithm: .HS256("secret"))) { payload in + XCTAssertEqual(payload as NSDictionary, ["nbf": "1428189720"]) + } + } func testInvalidNotBeforeClaim() { let jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOlsxNDI4MTg5NzIwXX0.PUL1FQubzzJa4MNXe2D3d5t5cMaqFr3kYlzRUzly-C8" @@ -160,6 +175,13 @@ class JWTDecodeTests : XCTestCase { XCTAssertEqual(payload as NSDictionary, ["iat": 1428189720]) } } + + func testIssuedAtClaimInThePastString() { + let jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOiIxNDI4MTg5NzIwIn0.M8veWtsY52oBwi7LRKzvNnzhjK0QBS8Su1r0atlns2k" + assertSuccess(try decode(jwt, algorithm: .HS256("secret"))) { payload in + XCTAssertEqual(payload as NSDictionary, ["iat": "1428189720"]) + } + } func testIssuedAtClaimInTheFuture() { // If this just started failing, hello 2024!