From 41bf170a27259803830bacaec3e1fff37bc22c73 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Fri, 18 Feb 2022 21:08:46 +1100 Subject: [PATCH] fix: parse all transports --- protocol/credential.go | 6 +----- protocol/credential_test.go | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/protocol/credential.go b/protocol/credential.go index 7a6a0de..9967904 100644 --- a/protocol/credential.go +++ b/protocol/credential.go @@ -91,11 +91,7 @@ func ParseCredentialCreationResponseBody(body io.Reader) (*ParsedCredentialCreat pcc.Raw = ccr for _, t := range ccr.Transports { - transport := AuthenticatorTransport(t) - switch transport { - case USB, BLE, NFC, Internal: - pcc.Transports = append(pcc.Transports, transport) - } + pcc.Transports = append(pcc.Transports, AuthenticatorTransport(t)) } parsedAttestationResponse, err := ccr.AttestationResponse.Parse() diff --git a/protocol/credential_test.go b/protocol/credential_test.go index 920d2b7..f80932b 100644 --- a/protocol/credential_test.go +++ b/protocol/credential_test.go @@ -44,7 +44,7 @@ func TestParseCredentialCreationResponse(t *testing.T) { }, RawID: byteID, }, - Transports: []AuthenticatorTransport{USB, NFC}, + Transports: []AuthenticatorTransport{USB, NFC, "fake"}, Response: ParsedAttestationResponse{ CollectedClientData: CollectedClientData{ Type: CeremonyType("webauthn.create"), @@ -80,7 +80,7 @@ func TestParseCredentialCreationResponse(t *testing.T) { }, AttestationObject: byteAttObject, }, - Transports: []string{"usb", "nfc"}, + Transports: []string{"usb", "nfc", "fake"}, }, }, wantErr: false, @@ -95,22 +95,25 @@ func TestParseCredentialCreationResponse(t *testing.T) { return } if !reflect.DeepEqual(got.ClientExtensionResults, tt.want.ClientExtensionResults) { - t.Errorf("Extensions = %v \n want: %v", got, tt.want) + t.Errorf("Extensions = %v \n want: %v", got.ClientExtensionResults, tt.want.ClientExtensionResults) + } + if !reflect.DeepEqual(got.Transports, tt.want.Transports) { + t.Errorf("Transports = %v \n want: %v", got.Transports, tt.want.Transports) } if !reflect.DeepEqual(got.ID, tt.want.ID) { t.Errorf("ID = %v \n want: %v", got, tt.want) } if !reflect.DeepEqual(got.ParsedCredential, tt.want.ParsedCredential) { - t.Errorf("ParsedCredential = %v \n want: %v", got, tt.want) + t.Errorf("ParsedCredential = %v \n want: %v", got.ParsedCredential, tt.want.ParsedCredential) } if !reflect.DeepEqual(got.ParsedPublicKeyCredential, tt.want.ParsedPublicKeyCredential) { - t.Errorf("ParsedPublicKeyCredential = %v \n want: %v", got, tt.want) + t.Errorf("ParsedPublicKeyCredential = %v \n want: %v", got.ParsedPublicKeyCredential, tt.want.ParsedPublicKeyCredential) } if !reflect.DeepEqual(got.Raw, tt.want.Raw) { - t.Errorf("Raw = %v \n want: %v", got, tt.want) + t.Errorf("Raw = %v \n want: %v", got.Raw, tt.want.Raw) } if !reflect.DeepEqual(got.RawID, tt.want.RawID) { - t.Errorf("RawID = %v \n want: %v", got, tt.want) + t.Errorf("RawID = %v \n want: %v", got.RawID, tt.want.RawID) } // Unmarshall CredentialPublicKey var pkWant interface{} @@ -238,7 +241,7 @@ var testCredentialRequestBody = `{ "id":"6xrtBhJQW6QU4tOaB4rrHaS2Ks0yDDL_q8jDC16DEjZ-VLVf4kCRkvl2xp2D71sTPYns-exsHQHTy3G-zJRK8g", "rawId":"6xrtBhJQW6QU4tOaB4rrHaS2Ks0yDDL_q8jDC16DEjZ-VLVf4kCRkvl2xp2D71sTPYns-exsHQHTy3G-zJRK8g", "type":"public-key", - "transports":["usb","nfc"], + "transports":["usb","nfc","fake"], "response":{ "attestationObject":"o2NmbXRkbm9uZWdhdHRTdG10oGhhdXRoRGF0YVjEdKbqkhPJnC90siSSsyDPQCYqlMGpUKA5fyklC2CEHvBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAQOsa7QYSUFukFOLTmgeK6x2ktirNMgwy_6vIwwtegxI2flS1X-JAkZL5dsadg-9bEz2J7PnsbB0B08txvsyUSvKlAQIDJiABIVggLKF5xS0_BntttUIrm2Z2tgZ4uQDwllbdIfrrBMABCNciWCDHwin8Zdkr56iSIh0MrB5qZiEzYLQpEOREhMUkY6q4Vw", "clientDataJSON":"eyJjaGFsbGVuZ2UiOiJXOEd6RlU4cEdqaG9SYldyTERsYW1BZnFfeTRTMUNaRzFWdW9lUkxBUnJFIiwib3JpZ2luIjoiaHR0cHM6Ly93ZWJhdXRobi5pbyIsInR5cGUiOiJ3ZWJhdXRobi5jcmVhdGUifQ"