Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions Tests/AuthenticationTests/APIKeyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,32 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import XCTest

@testable import Authentication

import JWTKit
import Testing


final class APIKeyTests: XCTestCase {
@Suite struct APIKeyTests {

func test_verify() throws {
@Test func verify() throws {
// Ensure verification rejects expired tokens
let s = Signer(secretSigningKey: "secret")
let token = try s.generateToken(for: "foo", expiringOn: .distantPast, contact: "bar", tier: .tier1)
do {
_ = try s.verifyToken(token)
XCTFail("Expected a JWTError.claimVerificationFailure to the thrown")
Issue.record("Expected a JWTError.claimVerificationFailure to the thrown")
} catch let JWTError.claimVerificationFailure(name: name, reason: reason) {
XCTAssertEqual(name, "exp")
XCTAssertEqual(reason, "expired")
#expect(name == "exp")
#expect(reason == "expired")
}
}

func test_isAuthorized() throws {
XCTAssertTrue(APIKey.mock(tier: .internal).isAuthorized(for: .tier1))
XCTAssertTrue(APIKey.mock(tier: .internal).isAuthorized(for: .tier2))
XCTAssertTrue(APIKey.mock(tier: .tier1).isAuthorized(for: .tier1))
XCTAssertFalse(APIKey.mock(tier: .tier1).isAuthorized(for: .tier2))
@Test func isAuthorized() throws {
#expect(APIKey.mock(tier: .internal).isAuthorized(for: .tier1))
#expect(APIKey.mock(tier: .internal).isAuthorized(for: .tier2))
#expect(APIKey.mock(tier: .tier1).isAuthorized(for: .tier1))
#expect(!APIKey.mock(tier: .tier1).isAuthorized(for: .tier2))
}

}
Expand Down
19 changes: 9 additions & 10 deletions Tests/AuthenticationTests/SignerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,32 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import XCTest

@testable import Authentication

import JWTKit
import Testing


final class SignerTests: XCTestCase {
@Suite struct SignerTests {

func test_generateToken_verifyToken() throws {
@Test func generateToken_verifyToken() throws {
// Round trip test
let s = Signer(secretSigningKey: "secret")
let token = try s.generateToken(for: "foo", contact: "bar", tier: .tier1)
XCTAssertTrue(!token.isEmpty)
#expect(!token.isEmpty)
let key = try s.verifyToken(token)
XCTAssertEqual(key.sub, .init(value: "foo"))
XCTAssertEqual(key.contact, "bar")
XCTAssertEqual(key.tier, .tier1)
#expect(key.sub == .init(value: "foo"))
#expect(key.contact == "bar")
#expect(key.tier == .tier1)
}

func test_verifyToken_failure() throws {
@Test func verifyToken_failure() throws {
// Ensure verification requires the correct secret
let token = try Signer(secretSigningKey: "secret").generateToken(for: "foo", contact: "bar", tier: .tier1)
let otherSigner = Signer(secretSigningKey: "other")
do {
_ = try otherSigner.verifyToken(token)
XCTFail("Expected a JWTError.signatureVerifictionFailed to the thrown")
Issue.record("Expected a JWTError.signatureVerifictionFailed to the thrown")
} catch JWTError.signatureVerifictionFailed { }
}

Expand Down
18 changes: 9 additions & 9 deletions Tests/AuthenticationTests/TierTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import XCTest

@testable import Authentication

import Testing


final class TierTests: XCTestCase {
@Suite struct TierTests {

func test_Comparable() throws {
XCTAssertTrue(Tier<V1>.tier1 < Tier<V1>.tier2)
XCTAssertTrue(Tier<V1>.tier2 < Tier<V1>.internal)
@Test func Comparable() throws {
#expect(Tier<V1>.tier1 < Tier<V1>.tier2)
#expect(Tier<V1>.tier2 < Tier<V1>.internal)

XCTAssertFalse(Tier<V1>.tier1 > Tier<V1>.tier2)
#expect(!(Tier<V1>.tier1 > Tier<V1>.tier2))

XCTAssertTrue(Tier<V1>.tier1 <= Tier<V1>.tier1)
XCTAssertTrue(Tier<V1>.tier1 >= Tier<V1>.tier1)
#expect(Tier<V1>.tier1 <= Tier<V1>.tier1)
#expect(Tier<V1>.tier1 >= Tier<V1>.tier1)
}

}
22 changes: 11 additions & 11 deletions Tests/S3StoreTests/S3StoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,36 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import XCTest

@testable import S3Store

import Testing


final class S3StoreTests: XCTestCase {
@Suite struct S3StoreTests {

func test_Key_path() throws {
@Test func Key_path() throws {
do {
let key = S3Store.Key(bucket: "bucket", path: "foo/bar")
XCTAssertEqual(key.path, "foo/bar")
#expect(key.path == "foo/bar")
}
do {
let key = S3Store.Key(bucket: "bucket", path: "/foo/bar")
XCTAssertEqual(key.path, "foo/bar")
#expect(key.path == "foo/bar")
}
do {
let key = S3Store.Key(bucket: "bucket", path: "//foo/bar")
XCTAssertEqual(key.path, "foo/bar")
#expect(key.path == "foo/bar")
}
}

func test_Key_objectUrl() throws {
@Test func Key_objectUrl() throws {
let key = S3Store.Key(bucket: "bucket", path: "foo/bar")
XCTAssertEqual(key.objectUrl, "https://bucket.s3.us-east-2.amazonaws.com/foo/bar")
#expect(key.objectUrl == "https://bucket.s3.us-east-2.amazonaws.com/foo/bar")
}

func test_Key_s3Uri() throws {
@Test func Key_s3Uri() throws {
let key = S3Store.Key(bucket: "bucket", path: "foo/bar")
XCTAssertEqual(key.s3Uri, "s3://bucket/foo/bar")
#expect(key.s3Uri == "s3://bucket/foo/bar")
}

}
Loading