mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-05 02:18:48 +00:00
+6








07ce3b6905
This PR summarizes multiple changes specifically only available with ZITADEL v3: - feat: Web Keys management (https://github.com/zitadel/zitadel/pull/9526) - fix(cmd): ensure proper working of mirror (https://github.com/zitadel/zitadel/pull/9509) - feat(Authz): system user support for permission check v2 (https://github.com/zitadel/zitadel/pull/9640) - chore(license): change from Apache to AGPL (https://github.com/zitadel/zitadel/pull/9597) - feat(console): list v2 sessions (https://github.com/zitadel/zitadel/pull/9539) - fix(console): add loginV2 feature flag (https://github.com/zitadel/zitadel/pull/9682) - fix(feature flags): allow reading "own" flags (https://github.com/zitadel/zitadel/pull/9649) - feat(console): add Actions V2 UI (https://github.com/zitadel/zitadel/pull/9591) BREAKING CHANGE - feat(webkey): migrate to v2beta API (https://github.com/zitadel/zitadel/pull/9445) - chore!: remove CockroachDB Support (https://github.com/zitadel/zitadel/pull/9444) - feat(actions): migrate to v2beta API (https://github.com/zitadel/zitadel/pull/9489) --------- Co-authored-by: Livio Spring <[email protected]> Co-authored-by: Stefan Benz <[email protected]> Co-authored-by: Silvan <[email protected]> Co-authored-by: Ramon <[email protected]> Co-authored-by: Elio Bischof <[email protected]> Co-authored-by: Kenta Yamaguchi <[email protected]> Co-authored-by: Harsha Reddy <[email protected]> Co-authored-by: Livio Spring <[email protected]> Co-authored-by: Max Peintner <[email protected]> Co-authored-by: Iraq <[email protected]> Co-authored-by: Florian Forster <[email protected]> Co-authored-by: Tim Möhlmann <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Max Peintner <[email protected]>
170 lines
4.7 KiB
Go
170 lines
4.7 KiB
Go
package query
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"database/sql/driver"
|
|
"errors"
|
|
"fmt"
|
|
"reflect"
|
|
"regexp"
|
|
"testing"
|
|
|
|
sq "github.com/Masterminds/squirrel"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
)
|
|
|
|
var (
|
|
loginPolicyIDPLinksQuery = regexp.QuoteMeta(`SELECT projections.idp_login_policy_links5.idp_id,` +
|
|
` projections.idp_templates6.name,` +
|
|
` projections.idp_templates6.type,` +
|
|
` projections.idp_templates6.owner_type,` +
|
|
` projections.idp_templates6.is_creation_allowed,` +
|
|
` projections.idp_templates6.is_linking_allowed,` +
|
|
` projections.idp_templates6.is_auto_creation,` +
|
|
` projections.idp_templates6.is_auto_update,` +
|
|
` projections.idp_templates6.auto_linking,` +
|
|
` COUNT(*) OVER ()` +
|
|
` FROM projections.idp_login_policy_links5` +
|
|
` LEFT JOIN projections.idp_templates6 ON projections.idp_login_policy_links5.idp_id = projections.idp_templates6.id AND projections.idp_login_policy_links5.instance_id = projections.idp_templates6.instance_id` +
|
|
` RIGHT JOIN (SELECT login_policy_owner.aggregate_id, login_policy_owner.instance_id, login_policy_owner.owner_removed FROM projections.login_policies5 AS login_policy_owner` +
|
|
` WHERE (login_policy_owner.instance_id = $1 AND (login_policy_owner.aggregate_id = $2 OR login_policy_owner.aggregate_id = $3)) ORDER BY login_policy_owner.is_default LIMIT 1) AS login_policy_owner` +
|
|
` ON login_policy_owner.aggregate_id = projections.idp_login_policy_links5.resource_owner AND login_policy_owner.instance_id = projections.idp_login_policy_links5.instance_id`)
|
|
loginPolicyIDPLinksCols = []string{
|
|
"idp_id",
|
|
"name",
|
|
"type",
|
|
"owner_type",
|
|
"is_creation_allowed",
|
|
"is_linking_allowed",
|
|
"is_auto_creation",
|
|
"is_auto_update",
|
|
"auto_linking",
|
|
"count",
|
|
}
|
|
)
|
|
|
|
func Test_IDPLoginPolicyLinkPrepares(t *testing.T) {
|
|
type want struct {
|
|
sqlExpectations sqlExpectation
|
|
err checkErr
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
prepare any
|
|
want want
|
|
object any
|
|
}{
|
|
{
|
|
name: "prepareIDPsQuery found",
|
|
prepare: func(ctx context.Context) (sq.SelectBuilder, func(*sql.Rows) (*IDPLoginPolicyLinks, error)) {
|
|
return prepareIDPLoginPolicyLinksQuery(ctx, "resourceOwner")
|
|
},
|
|
want: want{
|
|
sqlExpectations: mockQueries(
|
|
loginPolicyIDPLinksQuery,
|
|
loginPolicyIDPLinksCols,
|
|
[][]driver.Value{
|
|
{
|
|
"idp-id",
|
|
"idp-name",
|
|
domain.IDPTypeJWT,
|
|
domain.IdentityProviderTypeSystem,
|
|
true,
|
|
true,
|
|
true,
|
|
true,
|
|
domain.AutoLinkingOptionUsername,
|
|
},
|
|
},
|
|
),
|
|
},
|
|
object: &IDPLoginPolicyLinks{
|
|
SearchResponse: SearchResponse{
|
|
Count: 1,
|
|
},
|
|
Links: []*IDPLoginPolicyLink{
|
|
{
|
|
IDPID: "idp-id",
|
|
IDPName: "idp-name",
|
|
IDPType: domain.IDPTypeJWT,
|
|
OwnerType: domain.IdentityProviderTypeSystem,
|
|
IsCreationAllowed: true,
|
|
IsLinkingAllowed: true,
|
|
IsAutoCreation: true,
|
|
IsAutoUpdate: true,
|
|
AutoLinking: domain.AutoLinkingOptionUsername,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "prepareIDPsQuery no idp",
|
|
prepare: func(ctx context.Context) (sq.SelectBuilder, func(*sql.Rows) (*IDPLoginPolicyLinks, error)) {
|
|
return prepareIDPLoginPolicyLinksQuery(ctx, "resourceOwner")
|
|
},
|
|
want: want{
|
|
sqlExpectations: mockQueries(
|
|
loginPolicyIDPLinksQuery,
|
|
loginPolicyIDPLinksCols,
|
|
[][]driver.Value{
|
|
{
|
|
"idp-id",
|
|
nil,
|
|
nil,
|
|
nil,
|
|
false,
|
|
false,
|
|
false,
|
|
false,
|
|
0,
|
|
},
|
|
},
|
|
),
|
|
},
|
|
object: &IDPLoginPolicyLinks{
|
|
SearchResponse: SearchResponse{
|
|
Count: 1,
|
|
},
|
|
Links: []*IDPLoginPolicyLink{
|
|
{
|
|
IDPID: "idp-id",
|
|
IDPName: "",
|
|
IDPType: domain.IDPTypeUnspecified,
|
|
IsCreationAllowed: false,
|
|
IsLinkingAllowed: false,
|
|
IsAutoCreation: false,
|
|
IsAutoUpdate: false,
|
|
AutoLinking: domain.AutoLinkingOptionUnspecified,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "prepareIDPsQuery sql err",
|
|
prepare: func(ctx context.Context) (sq.SelectBuilder, func(*sql.Rows) (*IDPLoginPolicyLinks, error)) {
|
|
return prepareIDPLoginPolicyLinksQuery(ctx, "resourceOwner")
|
|
},
|
|
want: want{
|
|
sqlExpectations: mockQueryErr(
|
|
loginPolicyIDPLinksQuery,
|
|
sql.ErrConnDone,
|
|
),
|
|
err: func(err error) (error, bool) {
|
|
if !errors.Is(err, sql.ErrConnDone) {
|
|
return fmt.Errorf("err should be sql.ErrConnDone got: %w", err), false
|
|
}
|
|
return nil, true
|
|
},
|
|
},
|
|
object: (*IDPs)(nil),
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assertPrepare(t, tt.prepare, tt.object, tt.want.sqlExpectations, tt.want.err, reflect.ValueOf(context.Background()))
|
|
})
|
|
}
|
|
}
|