mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-10 22:53:42 +00:00
c3b97a91a2
# Which Problems Are Solved It is currently not possible to use SAML with the Session API. # How the Problems Are Solved Add SAML service, to get and resolve SAML requests. Add SAML session and SAML request aggregate, which can be linked to the Session to get back a SAMLResponse from the API directly. # Additional Changes Update of dependency zitadel/saml to provide all functionality for handling of SAML requests and responses. # Additional Context Closes #6053 --------- Co-authored-by: Livio Spring <livio.a@gmail.com>
124 lines
3.3 KiB
Go
124 lines
3.3 KiB
Go
package projection
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
|
"github.com/zitadel/zitadel/internal/repository/samlrequest"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
func TestSamlRequestProjection_reduces(t *testing.T) {
|
|
type args struct {
|
|
event func(t *testing.T) eventstore.Event
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
reduce func(event eventstore.Event) (*handler.Statement, error)
|
|
want wantReduce
|
|
}{
|
|
{
|
|
name: "reduceSamlRequestAdded",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
samlrequest.AddedType,
|
|
samlrequest.AggregateType,
|
|
[]byte(`{"login_client": "loginClient", "issuer": "issuer", "acs_url": "acs", "relay_state": "relayState", "binding": "binding"}`),
|
|
), eventstore.GenericEventMapper[samlrequest.AddedEvent]),
|
|
},
|
|
reduce: (&samlRequestProjection{}).reduceSamlRequestAdded,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("saml_request"),
|
|
sequence: 15,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "INSERT INTO projections.saml_requests (id, instance_id, creation_date, change_date, resource_owner, sequence, login_client, issuer, acs, relay_state, binding) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
|
expectedArgs: []interface{}{
|
|
"agg-id",
|
|
"instance-id",
|
|
anyArg{},
|
|
anyArg{},
|
|
"ro-id",
|
|
uint64(15),
|
|
"loginClient",
|
|
"issuer",
|
|
"acs",
|
|
"relayState",
|
|
"binding",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "reduceSamlRequestFailed",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
samlrequest.FailedType,
|
|
samlrequest.AggregateType,
|
|
[]byte(`{"reason": 0}`),
|
|
), eventstore.GenericEventMapper[samlrequest.FailedEvent]),
|
|
},
|
|
reduce: (&samlRequestProjection{}).reduceSamlRequestEnded,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("saml_request"),
|
|
sequence: 15,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "DELETE FROM projections.saml_requests WHERE (id = $1) AND (instance_id = $2)",
|
|
expectedArgs: []interface{}{
|
|
"agg-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "reduceSamlRequestSucceeded",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
samlrequest.SucceededType,
|
|
samlrequest.AggregateType,
|
|
nil,
|
|
), eventstore.GenericEventMapper[samlrequest.SucceededEvent]),
|
|
},
|
|
reduce: (&samlRequestProjection{}).reduceSamlRequestEnded,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("saml_request"),
|
|
sequence: 15,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "DELETE FROM projections.saml_requests WHERE (id = $1) AND (instance_id = $2)",
|
|
expectedArgs: []interface{}{
|
|
"agg-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
event := baseEvent(t)
|
|
got, err := tt.reduce(event)
|
|
if !zerrors.IsErrorInvalidArgument(err) {
|
|
t.Errorf("no wrong event mapping: %v, got: %v", err, got)
|
|
}
|
|
|
|
event = tt.args.event(t)
|
|
got, err = tt.reduce(event)
|
|
assertReduce(t, got, err, SamlRequestsProjectionTable, tt.want)
|
|
})
|
|
}
|
|
}
|