Skip to content

Commit 3429ad9

Browse files
committed
refactor tests
1 parent ef5dbf7 commit 3429ad9

File tree

7 files changed

+125
-267
lines changed

7 files changed

+125
-267
lines changed

Sources/WebAuthn/Ceremonies/Registration/AuthenticatorAttestationResponse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import SwiftCBOR
1818
/// The response from the authenticator device for the creation of a new public key credential.
1919
public struct AuthenticatorAttestationResponse: Codable {
2020
public let clientDataJSON: URLEncodedBase64
21-
public let attestationObject: String
21+
public let attestationObject: URLEncodedBase64
2222
}
2323

2424
/// A parsed version of `AuthenticatorAttestationResponse`

Sources/WebAuthn/WebAuthnError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
public enum WebAuthnError: Error {
15+
public enum WebAuthnError: Error, Equatable {
1616
// MARK: Shared
1717
case invalidClientDataJSON
1818
case attestedCredentialDataMissing

Tests/WebAuthnTests/Ceremonies/Registration/ParsedAuthenticatorAttestationResponseTests.swift

Lines changed: 0 additions & 116 deletions
This file was deleted.

Tests/WebAuthnTests/Ceremonies/Registration/ParsedCredentialCreationResponseTests.swift

Lines changed: 0 additions & 42 deletions
This file was deleted.

Tests/WebAuthnTests/Ceremonies/Shared/AuthenticatorDataTests.swift

Lines changed: 0 additions & 96 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import XCTest
2+
import WebAuthn
3+
4+
func assertThrowsError<T, E: Error>(
5+
_ expression: @autoclosure () async throws -> T,
6+
_ message: @autoclosure () -> String = "",
7+
file: StaticString = #filePath,
8+
line: UInt = #line,
9+
_ errorHandler: (_ error: E) -> Void = { _ in }
10+
) async {
11+
do {
12+
_ = try await expression()
13+
XCTFail(message(), file: file, line: line)
14+
} catch {
15+
guard let error = error as? E else {
16+
XCTFail("Error was thrown, but didn't match expected type '\(E.self)'. Got: '\(type(of: error))'")
17+
return
18+
}
19+
errorHandler(error)
20+
}
21+
}
22+
23+
func assertThrowsError<T, E: Error & Equatable>(
24+
_ expression: @autoclosure () async throws -> T,
25+
_ message: @autoclosure () -> String = "",
26+
file: StaticString = #filePath,
27+
line: UInt = #line,
28+
expect: E
29+
) async {
30+
try await assertThrowsError(await expression(), message(), file: file, line: line) { error in
31+
XCTAssertEqual(error, expect, message(), file: file, line: line)
32+
}
33+
}

0 commit comments

Comments
 (0)