mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-19 03:35:12 +00:00
feat(session): Passkey Check API with relation tables (#11858)
# Which Problems Are Solved As part of #11035 , this PR implements the Passkey check logic for session validation # How the Problems Are Solved - Refactor webauth FinishLogin to support new domain model - Add webauth config to defaults - Implement passkey check logic and tests - Manual transaction management to avoid stalling the DB while FinishLogin callback is executed - Update passkey Type condition to allow passing a text operation (equal, contains, etc..) # Additional Context This is a cherry-picked PR + minor changes, coming from https://github.com/zitadel/zitadel/pull/11164 - Relates to #11035 --------- Co-authored-by: Fabienne Bühler <[email protected]> Co-authored-by: Gayathri Vijayan <[email protected]>
This commit is contained in:
co-authored by
Fabienne Bühler
Gayathri Vijayan
parent
ec7a6d5526
commit
022bf74060
@@ -0,0 +1,15 @@
|
||||
package convert
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
session_grpc "github.com/zitadel/zitadel/pkg/grpc/session/v2"
|
||||
)
|
||||
|
||||
func CheckPasskeyGRPCToDomain(checkPasskey *session_grpc.CheckWebAuthN) ([]byte, error) {
|
||||
if checkPasskey == nil || checkPasskey.GetCredentialAssertionData() == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return json.Marshal(checkPasskey.GetCredentialAssertionData())
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package convert
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
|
||||
session_grpc "github.com/zitadel/zitadel/pkg/grpc/session/v2"
|
||||
)
|
||||
|
||||
func TestCheckPasskeyGRPCToDomain(t *testing.T) {
|
||||
t.Parallel()
|
||||
tt := []struct {
|
||||
testName string
|
||||
input *session_grpc.CheckWebAuthN
|
||||
expectedBytes []byte
|
||||
expectedError error
|
||||
}{
|
||||
{
|
||||
testName: "when input is nil should return nil bytes and nil error",
|
||||
input: nil,
|
||||
expectedBytes: nil,
|
||||
expectedError: nil,
|
||||
},
|
||||
{
|
||||
testName: "when credential assertion data is nil should return nil bytes and nil error",
|
||||
input: &session_grpc.CheckWebAuthN{
|
||||
CredentialAssertionData: nil,
|
||||
},
|
||||
expectedBytes: nil,
|
||||
expectedError: nil,
|
||||
},
|
||||
{
|
||||
testName: "when credential assertion data is empty should return empty JSON bytes",
|
||||
input: &session_grpc.CheckWebAuthN{
|
||||
CredentialAssertionData: &structpb.Struct{},
|
||||
},
|
||||
expectedBytes: []byte("{}"),
|
||||
expectedError: nil,
|
||||
},
|
||||
{
|
||||
testName: "when credential assertion data is populated should return marshaled JSON bytes",
|
||||
input: &session_grpc.CheckWebAuthN{
|
||||
CredentialAssertionData: &structpb.Struct{
|
||||
Fields: map[string]*structpb.Value{
|
||||
"publicKeyCredentialRequestOptions": {
|
||||
Kind: &structpb.Value_StructValue{
|
||||
StructValue: &structpb.Struct{
|
||||
Fields: map[string]*structpb.Value{
|
||||
"challenge": structpb.NewStringValue("Y2hhbGxlbmdl"),
|
||||
"rpId": structpb.NewStringValue("example.com"),
|
||||
"timeout": structpb.NewNumberValue(5000),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedBytes: []byte(`{"publicKeyCredentialRequestOptions":{"challenge":"Y2hhbGxlbmdl","rpId":"example.com","timeout":5000}}`),
|
||||
expectedError: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.testName, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Test
|
||||
result, err := CheckPasskeyGRPCToDomain(tc.input)
|
||||
|
||||
// Verify
|
||||
assert.Equal(t, tc.expectedBytes, result)
|
||||
assert.Equal(t, tc.expectedError, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user