Skip to content

Commit

Permalink
Update JWTKit version (#154)
Browse files Browse the repository at this point in the history
* Update JWTKit version

* Actually update Swift version in mainfest
  • Loading branch information
ptoffy committed Apr 24, 2024
1 parent 690a134 commit 0b56253
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Package.swift
@@ -1,4 +1,4 @@
// swift-tools-version:5.9
// swift-tools-version:5.10
import PackageDescription

let package = Package(
Expand All @@ -13,7 +13,7 @@ let package = Package(
.library(name: "JWT", targets: ["JWT"]),
],
dependencies: [
.package(url: "https://github.com/vapor/jwt-kit.git", from: "5.0.0-beta.2"),
.package(url: "https://github.com/vapor/jwt-kit.git", from: "5.0.0-beta.3"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.92.0"),
],
targets: [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -19,7 +19,7 @@
<img src="https://img.shields.io/github/actions/workflow/status/vapor/jwt/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration">
</a>
<a href="https://swift.org">
<img src="https://design.vapor.codes/images/swift59up.svg" alt="Swift 5.9+">
<img src="https://design.vapor.codes/images/swift510up.svg" alt="Swift 5.10+">
</a>
</p>
<br>
Expand Down
25 changes: 14 additions & 11 deletions Tests/JWTTests/JWTTests.swift
Expand Up @@ -9,10 +9,10 @@ class JWTTests: XCTestCase {
defer { app.shutdown() }

// Add HMAC with SHA-256 signer.
await app.jwt.keys.addHS256(key: "secret")
await app.jwt.keys.addHMAC(key: "secret", digestAlgorithm: .sha256)

await app.jwt.keys.addHS256(key: "foo", kid: "a")
await app.jwt.keys.addHS256(key: "bar", kid: "b")
await app.jwt.keys.addHMAC(key: "foo", digestAlgorithm: .sha256, kid: "a")
await app.jwt.keys.addHMAC(key: "bar", digestAlgorithm: .sha256, kid: "b")

app.jwt.apple.applicationIdentifier = "..."
app.get("apple") { req async throws -> HTTPStatus in
Expand Down Expand Up @@ -62,7 +62,7 @@ class JWTTests: XCTestCase {
// signature verification here.
// Since we have an ExpirationClaim, we will
// call its verify method.
func verify(using _: JWTAlgorithm) async throws {
func verify(using _: some JWTAlgorithm) async throws {
try self.expiration.verifyNotExpired()
}
}
Expand Down Expand Up @@ -124,7 +124,7 @@ class JWTTests: XCTestCase {
defer { app.shutdown() }

// configures an es512 signer using random key
await app.jwt.keys.addES512(key: ES512PrivateKey())
await app.jwt.keys.addECDSA(key: ES512PrivateKey())

// jwt creation using req.jwt.sign
app.post("login") { req async throws -> LoginResponse in
Expand Down Expand Up @@ -166,7 +166,7 @@ class JWTTests: XCTestCase {

// create a token from a different signer
let fakeToken = try await JWTKeyCollection()
.addES512(key: ES512PrivateKey()).sign(TestUser(name: "bob"))
.addECDSA(key: ES512PrivateKey()).sign(TestUser(name: "bob"))
try app.testable().test(
.GET, "me", headers: ["authorization": "Bearer \(fakeToken)"]
) { res in
Expand All @@ -181,7 +181,7 @@ class JWTTests: XCTestCase {
defer { app.shutdown() }

// configures an es512 signer using random key
await app.jwt.keys.addES512(key: ES512PrivateKey())
await app.jwt.keys.addECDSA(key: ES512PrivateKey())

// jwt creation using req.jwt.sign
app.post("login") { req async throws -> LoginResponse in
Expand Down Expand Up @@ -241,7 +241,7 @@ class JWTTests: XCTestCase {
}

// create a token from a different signer
let fakeToken = try await JWTKeyCollection().addES512(key: ES512PrivateKey()).sign(TestUser(name: "bob"))
let fakeToken = try await JWTKeyCollection().addECDSA(key: ES512PrivateKey()).sign(TestUser(name: "bob"))
try app.testable().test(
.GET, "me", headers: ["authorization": "Bearer \(fakeToken)"]
) { res in
Expand Down Expand Up @@ -287,7 +287,7 @@ class JWTTests: XCTestCase {
var id: UUID
var userName: String

func verify(using _: JWTAlgorithm) throws {}
func verify(using _: some JWTAlgorithm) throws {}
}

// creates a new application for testing
Expand Down Expand Up @@ -324,7 +324,10 @@ class JWTTests: XCTestCase {
-----END RSA PRIVATE KEY-----
"""

try await app.jwt.keys.addRS256(key: Insecure.RSA.PrivateKey(pem: [UInt8](privateKeyString.utf8)))
try await app.jwt.keys.addRSA(
key: Insecure.RSA.PrivateKey(pem: [UInt8](privateKeyString.utf8)),
digestAlgorithm: .sha256
)

app.get { req async throws -> String in
let authorizationPayload = UserPayload(id: UUID(), userName: "John Smith")
Expand Down Expand Up @@ -370,7 +373,7 @@ struct LoginCredentials: Content {
struct TestUser: Content, Authenticatable, JWTPayload {
var name: String

func verify(using _: JWTAlgorithm) throws {
func verify(using _: some JWTAlgorithm) throws {
// nothing to verify
}
}
Expand Down

0 comments on commit 0b56253

Please sign in to comment.