Skip to content
Open
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
2 changes: 1 addition & 1 deletion webauthn/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (webauthn *WebAuthn) beginLogin(userID []byte, allowedCredentials []protoco
}

session = &SessionData{
Challenge: challenge.String(),
Challenge: assertion.Response.Challenge.String(),
RelyingPartyID: assertion.Response.RelyingPartyID,
UserID: userID,
AllowedCredentialIDs: assertion.Response.GetAllowedCredentialIDs(),
Expand Down
67 changes: 67 additions & 0 deletions webauthn/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,70 @@ func TestWithLoginRelyingPartyID(t *testing.T) {
})
}
}

func TestCustomerChallenge(t *testing.T) {
customerChallenge := "hello world"
nonCustomerChallenge := make(protocol.URLEncodedBase64, 0)
testCases := []struct {
name string
have *Config
opts []LoginOption
expectedChallenge func() protocol.URLEncodedBase64
err string
}{
{
name: "NonCustomerChallenge",
have: &Config{
RPID: "https://example.com",
RPDisplayName: "Test Non-Customer Challenge",
RPOrigins: []string{"https://example.com"},
},
opts: []LoginOption{
func(opt *protocol.PublicKeyCredentialRequestOptions) {
nonCustomerChallenge = opt.Challenge
},
},
expectedChallenge: func() protocol.URLEncodedBase64 {
return nonCustomerChallenge
},
},
{
name: "CustomerChallenge",
have: &Config{
RPID: "https://example.com",
RPDisplayName: "Test Customer Challenge",
RPOrigins: []string{"https://example.com"},
},
opts: []LoginOption{
func(opt *protocol.PublicKeyCredentialRequestOptions) {
opt.Challenge = protocol.URLEncodedBase64(customerChallenge)
},
},
expectedChallenge: func() protocol.URLEncodedBase64 {
return []byte(customerChallenge)
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
w, err := New(tc.have)
assert.NoError(t, err)

user := &defaultUser{
credentials: []Credential{
{},
},
}

creation, _, err := w.BeginLogin(user, tc.opts...)
if tc.err != "" {
assert.EqualError(t, err, tc.err)
} else {
assert.NoError(t, err)
require.NotNil(t, creation)
assert.Equal(t, tc.expectedChallenge(), creation.Response.Challenge)
}
})
}
}