Skip to content

Commit

Permalink
Added test to verify timestamps-as-strings pass verification
Browse files Browse the repository at this point in the history
  • Loading branch information
parrots committed Sep 27, 2015
1 parent 9203e49 commit c5bf651
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions JWTTests/JWTTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"
Expand All @@ -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!
Expand Down

0 comments on commit c5bf651

Please sign in to comment.