From 4136f6e601ba1443837a940a550fc63fd37df7d6 Mon Sep 17 00:00:00 2001 From: Andrew Lees <32634907+Andrew-Lees11@users.noreply.github.com> Date: Mon, 18 Mar 2019 11:59:53 +0000 Subject: [PATCH] Added test for pattern matching JWTError (#46) --- Tests/SwiftJWTTests/TestJWT.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Tests/SwiftJWTTests/TestJWT.swift b/Tests/SwiftJWTTests/TestJWT.swift index 0361868..b1852d4 100644 --- a/Tests/SwiftJWTTests/TestJWT.swift +++ b/Tests/SwiftJWTTests/TestJWT.swift @@ -133,7 +133,8 @@ class TestJWT: XCTestCase { ("testMicroProfile", testMicroProfile), ("testValidateClaims", testValidateClaims), ("testValidateClaimsLeeway", testValidateClaimsLeeway), - ] + ("testErrorPattenMatching", testErrorPattenMatching), + ] } func testSignAndVerify() { @@ -539,6 +540,16 @@ class TestJWT: XCTestCase { jwt.claims.nbf = Date(timeIntervalSinceNow: 10) XCTAssertEqual(jwt.validateClaims(leeway: 20), .success, "Validation failed") } + + func testErrorPattenMatching() { + do { + let _ = try JWT(jwtString: "InvalidString", verifier: .rs256(publicKey: rsaPublicKey)) + } catch JWTError.invalidJWTString { + // Caught correct error + } catch { + XCTFail("Incorrect error thrown: \(error)") + } + } } func read(fileName: String) -> Data {