Skip to content

Commit fbdb77b

Browse files
committed
add raw id test
1 parent ce1ca2b commit fbdb77b

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

Sources/WebAuthn/Ceremonies/Registration/RegistrationCredential.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct ParsedCredentialCreationResponse {
8888

8989
// Step 23.
9090
guard rawID.count <= 1023 else {
91-
throw WebAuthnError.credentialRawIDTooBig
91+
throw WebAuthnError.credentialRawIDTooLong
9292
}
9393
}
9494
}

Sources/WebAuthn/WebAuthnError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public enum WebAuthnError: Error, Equatable {
4545
// MARK: ParsedCredentialCreationResponse
4646
case invalidRawID
4747
case invalidCredentialCreationType
48-
case credentialRawIDTooBig
48+
case credentialRawIDTooLong
4949

5050
// MARK: AuthenticatorData
5151
case authDataTooShort

Tests/WebAuthnTests/WebAuthnManagerTests.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,20 @@ final class WebAuthnManagerTests: XCTestCase {
224224
)
225225
}
226226

227+
func testFinishRegistrationFailsIfRawIDIsTooLong() async throws {
228+
try await assertThrowsError(
229+
await finishRegistration(rawID: [UInt8](repeating: 0, count: 1024).base64EncodedString()),
230+
expect: WebAuthnError.credentialRawIDTooLong
231+
)
232+
}
233+
227234
private func finishRegistration(
228235
challenge: EncodedBase64 = "cmFuZG9tU3RyaW5nRnJvbVNlcnZlcg",
229236
id: EncodedBase64 = "4PrJNQUJ9xdI2DeCzK9rTBRixhXHDiVdoTROQIh8j80",
230237
type: String = "public-key",
231238
rawID: EncodedBase64 = "4PrJNQUJ9xdI2DeCzK9rTBRixhXHDiVdoTROQIh8j80",
232239
clientDataJSON: String = "eyJ0eXBlIjoid2ViYXV0aG4uY3JlYXRlIiwiY2hhbGxlbmdlIjoiY21GdVpHOXRVM1J5YVc1blJuSnZiVk5sY25abGNnIiwib3JpZ2luIjoiaHR0cHM6Ly9leGFtcGxlLmNvbSIsImNyb3NzT3JpZ2luIjpmYWxzZSwib3RoZXJfa2V5c19jYW5fYmVfYWRkZWRfaGVyZSI6ImRvIG5vdCBjb21wYXJlIGNsaWVudERhdGFKU09OIGFnYWluc3QgYSB0ZW1wbGF0ZS4gU2VlIGh0dHBzOi8vZ29vLmdsL3lhYlBleCJ9",
233-
attestationObject: String = "o2NmbXRmcGFja2VkZ2F0dFN0bXSiY2FsZyZjc2lnWEcwRQIgNTRtpI_SOOZVzU1pN_4cX-osqUPiHMOW48qqq91DXfUCIQC-MHiaIxt2OdIxgqYnyUDHceevNOMfPibenabQGvXgjGhhdXRoRGF0YVikSZYN5YgOjGh0NBcPZHZgW4_krrmihjLHmVzzuoMdl2NFAAAAAK3OAAI1vMYKZIsLJfHwVQMAIDo-5W3Kur7A7y9Lfw7ijhExfCz3_5coMEQNY_y6p-JrpQECAyYgASFYIJr_yLoYbYWgcf7aQcd7pcjUj-3o8biafWQH28WijQSvIlggPI2KqqRQ26KKuFaJ0yH7nouCBrzHu8qRONW-CPa9VDM",
240+
attestationObject: String = "o2NmbXRkbm9uZWdhdHRTdG10oGhhdXRoRGF0YVg5o3mm9u6vuaVeN4wRgDTidR5oL6ufLTCrE9ISVYbOGUdBAAAAAKN5pvbur7mlXjeMEYA04nUAAQAA",
234241
requireUserVerification: Bool = false,
235242
confirmCredentialIDNotRegisteredYet: (String) async throws -> Bool = { _ in true }
236243
) async throws -> Credential {

0 commit comments

Comments
 (0)