Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Commit

Permalink
fix: parse all transports
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-elliott committed Feb 18, 2022
1 parent ada74b6 commit 41bf170
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
6 changes: 1 addition & 5 deletions protocol/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 11 additions & 8 deletions protocol/credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestParseCredentialCreationResponse(t *testing.T) {
},
AttestationObject: byteAttObject,
},
Transports: []string{"usb", "nfc"},
Transports: []string{"usb", "nfc", "fake"},
},
},
wantErr: false,
Expand All @@ -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{}
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 41bf170

Please sign in to comment.