Skip to content

Commit

Permalink
remove jwt-kit
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Dec 4, 2024
1 parent 5f8ed4a commit 319b768
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 82 deletions.
27 changes: 0 additions & 27 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"pins" : [
{
"identity" : "jwt-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/jwt-kit.git",
"state" : {
"revision" : "6f745e91e2422608fe14c9a66ee3826cb661e2a6",
"version" : "5.1.1"
}
},
{
"identity" : "swift-asn1",
"kind" : "remoteSourceControl",
Expand All @@ -18,15 +9,6 @@
"version" : "1.3.0"
}
},
{
"identity" : "swift-certificates",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-certificates.git",
"state" : {
"revision" : "1fbb6ef21f1525ed5faf4c95207b9c11bea27e94",
"version" : "1.6.1"
}
},
{
"identity" : "swift-concurrency-extras",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -63,15 +45,6 @@
"version" : "1.3.0"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "96a2f8a0fa41e9e09af4585e2724c4e825410b91",
"version" : "1.6.2"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
Expand Down
2 changes: 0 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.2"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.17.2"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.2.2"),
.package(url: "https://github.com/vapor/jwt-kit.git", from: "5.0.0"),
],
targets: [
.target(
Expand Down Expand Up @@ -131,7 +130,6 @@ let package = Package(
.product(name: "CustomDump", package: "swift-custom-dump"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "JWTKit", package: "jwt-kit"),
"PostgREST",
"Realtime",
"TestHelpers",
Expand Down
27 changes: 0 additions & 27 deletions Supabase.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,6 @@
"version" : "4.1.1"
}
},
{
"identity" : "jwt-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/jwt-kit.git",
"state" : {
"revision" : "6f745e91e2422608fe14c9a66ee3826cb661e2a6",
"version" : "5.1.1"
}
},
{
"identity" : "svgview",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -72,15 +63,6 @@
"version" : "1.5.5"
}
},
{
"identity" : "swift-certificates",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-certificates.git",
"state" : {
"revision" : "1fbb6ef21f1525ed5faf4c95207b9c11bea27e94",
"version" : "1.6.1"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -135,15 +117,6 @@
"version" : "1.1.0"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "96a2f8a0fa41e9e09af4585e2724c4e825410b91",
"version" : "1.6.2"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
Expand Down
34 changes: 8 additions & 26 deletions Tests/RealtimeTests/RealtimeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import ConcurrencyExtras
import CustomDump
import Helpers
import InlineSnapshotTesting
import JWTKit
import TestHelpers
import XCTest

Expand Down Expand Up @@ -344,23 +343,24 @@ final class RealtimeTests: XCTestCase {
}

func testSetAuth() async {
let token = await generateJWT()
await sut.setAuth(token)
let validToken =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjY0MDkyMjExMjAwfQ.GfiEKLl36X8YWcatHg31jRbilovlGecfUKnOyXMSX9c"
await sut.setAuth(validToken)

XCTAssertEqual(sut.mutableState.accessToken, token)
XCTAssertEqual(sut.mutableState.accessToken, validToken)
}

func testSetAuthWithExpiredToken() async throws {
let token = await generateJWT(exp: 0)
await sut.setAuth(token)
let expiredToken =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOi02NDA5MjIxMTIwMH0.tnbZRC8vEyK3zaxPxfOjNgvpnuum18dxYlXeHJ4r7u8"
await sut.setAuth(expiredToken)

XCTAssertNotEqual(sut.mutableState.accessToken, token)
XCTAssertNotEqual(sut.mutableState.accessToken, expiredToken)
}

func testSetAuthWithNonJWT() async throws {
let token = "sb-token"
await sut.setAuth(token)
XCTAssertEqual(sut.mutableState.accessToken, token)
}

private func connectSocketAndWait() async {
Expand All @@ -387,21 +387,3 @@ extension RealtimeMessageV2 {
]
)
}

private func generateJWT(exp: TimeInterval = 60) async -> String? {
struct Payload: JWTPayload {
let exp: ExpirationClaim
func verify(using algorithm: some JWTAlgorithm) async throws {
try exp.verifyNotExpired()
}
}

let keys = JWTKeyCollection()
await keys.add(hmac: "your-256-bit-secret", digestAlgorithm: .sha256)

return try? await keys.sign(
Payload(
exp: ExpirationClaim(value: Date().addingTimeInterval(exp))
)
)
}

0 comments on commit 319b768

Please sign in to comment.