Skip to content

Commit 4136f6e

Browse files
Added test for pattern matching JWTError (#46)
1 parent e7b5111 commit 4136f6e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Tests/SwiftJWTTests/TestJWT.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ class TestJWT: XCTestCase {
133133
("testMicroProfile", testMicroProfile),
134134
("testValidateClaims", testValidateClaims),
135135
("testValidateClaimsLeeway", testValidateClaimsLeeway),
136-
]
136+
("testErrorPattenMatching", testErrorPattenMatching),
137+
]
137138
}
138139

139140
func testSignAndVerify() {
@@ -539,6 +540,16 @@ class TestJWT: XCTestCase {
539540
jwt.claims.nbf = Date(timeIntervalSinceNow: 10)
540541
XCTAssertEqual(jwt.validateClaims(leeway: 20), .success, "Validation failed")
541542
}
543+
544+
func testErrorPattenMatching() {
545+
do {
546+
let _ = try JWT<TestClaims>(jwtString: "InvalidString", verifier: .rs256(publicKey: rsaPublicKey))
547+
} catch JWTError.invalidJWTString {
548+
// Caught correct error
549+
} catch {
550+
XCTFail("Incorrect error thrown: \(error)")
551+
}
552+
}
542553
}
543554

544555
func read(fileName: String) -> Data {

0 commit comments

Comments
 (0)