mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 03:57:32 +00:00
fix: features query (#2610)
This commit is contained in:
@@ -7,14 +7,14 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
)
|
||||
|
||||
type Feature struct {
|
||||
type Features struct {
|
||||
AggregateID string
|
||||
CreationDate time.Time
|
||||
ChangeDate time.Time
|
||||
Sequence uint64
|
||||
IsDefault bool
|
||||
@@ -42,91 +42,113 @@ type Feature struct {
|
||||
}
|
||||
|
||||
var (
|
||||
feautureTable = table{
|
||||
featureTable = table{
|
||||
name: projection.FeatureTable,
|
||||
}
|
||||
FeatureColumnAggregateID = Column{
|
||||
name: projection.FeatureAggregateIDCol,
|
||||
}
|
||||
FeatureColumnCreationDate = Column{
|
||||
name: projection.FeatureCreationDateCol,
|
||||
name: projection.FeatureAggregateIDCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureColumnChangeDate = Column{
|
||||
name: projection.FeatureChangeDateCol,
|
||||
name: projection.FeatureChangeDateCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureColumnSequence = Column{
|
||||
name: projection.FeatureSequenceCol,
|
||||
name: projection.FeatureSequenceCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureColumnIsDefault = Column{
|
||||
name: projection.FeatureIsDefaultCol,
|
||||
name: projection.FeatureIsDefaultCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureTierName = Column{
|
||||
name: projection.FeatureTierNameCol,
|
||||
name: projection.FeatureTierNameCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureTierDescription = Column{
|
||||
name: projection.FeatureTierDescriptionCol,
|
||||
name: projection.FeatureTierDescriptionCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureState = Column{
|
||||
name: projection.FeatureStateCol,
|
||||
name: projection.FeatureStateCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureStateDescription = Column{
|
||||
name: projection.FeatureStateDescriptionCol,
|
||||
name: projection.FeatureStateDescriptionCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureAuditLogRetention = Column{
|
||||
name: projection.FeatureAuditLogRetentionCol,
|
||||
name: projection.FeatureAuditLogRetentionCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLoginPolicyFactors = Column{
|
||||
name: projection.FeatureLoginPolicyFactorsCol,
|
||||
name: projection.FeatureLoginPolicyFactorsCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLoginPolicyIDP = Column{
|
||||
name: projection.FeatureLoginPolicyIDPCol,
|
||||
name: projection.FeatureLoginPolicyIDPCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLoginPolicyPasswordless = Column{
|
||||
name: projection.FeatureLoginPolicyPasswordlessCol,
|
||||
name: projection.FeatureLoginPolicyPasswordlessCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLoginPolicyRegistration = Column{
|
||||
name: projection.FeatureLoginPolicyRegistrationCol,
|
||||
name: projection.FeatureLoginPolicyRegistrationCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLoginPolicyUsernameLogin = Column{
|
||||
name: projection.FeatureLoginPolicyUsernameLoginCol,
|
||||
name: projection.FeatureLoginPolicyUsernameLoginCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLoginPolicyPasswordReset = Column{
|
||||
name: projection.FeatureLoginPolicyPasswordResetCol,
|
||||
name: projection.FeatureLoginPolicyPasswordResetCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeaturePasswordComplexityPolicy = Column{
|
||||
name: projection.FeaturePasswordComplexityPolicyCol,
|
||||
name: projection.FeaturePasswordComplexityPolicyCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLabelPolicyPrivateLabel = Column{
|
||||
name: projection.FeatureLabelPolicyPrivateLabelCol,
|
||||
name: projection.FeatureLabelPolicyPrivateLabelCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLabelPolicyWatermark = Column{
|
||||
name: projection.FeatureLabelPolicyWatermarkCol,
|
||||
name: projection.FeatureLabelPolicyWatermarkCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureCustomDomain = Column{
|
||||
name: projection.FeatureCustomDomainCol,
|
||||
name: projection.FeatureCustomDomainCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeaturePrivacyPolicy = Column{
|
||||
name: projection.FeaturePrivacyPolicyCol,
|
||||
name: projection.FeaturePrivacyPolicyCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureMetadataUser = Column{
|
||||
name: projection.FeatureMetadataUserCol,
|
||||
name: projection.FeatureMetadataUserCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureCustomTextMessage = Column{
|
||||
name: projection.FeatureCustomTextMessageCol,
|
||||
name: projection.FeatureCustomTextMessageCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureCustomTextLogin = Column{
|
||||
name: projection.FeatureCustomTextLoginCol,
|
||||
name: projection.FeatureCustomTextLoginCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLockoutPolicy = Column{
|
||||
name: projection.FeatureLockoutPolicyCol,
|
||||
name: projection.FeatureLockoutPolicyCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureActions = Column{
|
||||
name: projection.FeatureActionsCol,
|
||||
name: projection.FeatureActionsCol,
|
||||
table: featureTable,
|
||||
}
|
||||
)
|
||||
|
||||
func (q *Queries) FeatureByID(ctx context.Context, orgID string) (*Feature, error) {
|
||||
query, scan := prepareFeatureQuery()
|
||||
func (q *Queries) FeaturesByOrgID(ctx context.Context, orgID string) (*Features, error) {
|
||||
query, scan := prepareFeaturesQuery()
|
||||
stmt, args, err := query.Where(
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
@@ -146,11 +168,11 @@ func (q *Queries) FeatureByID(ctx context.Context, orgID string) (*Feature, erro
|
||||
return scan(row)
|
||||
}
|
||||
|
||||
func (q *Queries) DefaultFeature(ctx context.Context) (*Feature, error) {
|
||||
query, scan := prepareFeatureQuery()
|
||||
func (q *Queries) DefaultFeatures(ctx context.Context) (*Features, error) {
|
||||
query, scan := prepareFeaturesQuery()
|
||||
stmt, args, err := query.Where(sq.Eq{
|
||||
FeatureColumnAggregateID.identifier(): domain.IAMID,
|
||||
}).OrderBy(FeatureColumnIsDefault.identifier()).ToSql()
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-1Ndlg", "Errors.Query.SQLStatement")
|
||||
}
|
||||
@@ -159,10 +181,9 @@ func (q *Queries) DefaultFeature(ctx context.Context) (*Feature, error) {
|
||||
return scan(row)
|
||||
}
|
||||
|
||||
func prepareFeatureQuery() (sq.SelectBuilder, func(*sql.Row) (*Feature, error)) {
|
||||
func prepareFeaturesQuery() (sq.SelectBuilder, func(*sql.Row) (*Features, error)) {
|
||||
return sq.Select(
|
||||
FeatureColumnAggregateID.identifier(),
|
||||
FeatureColumnCreationDate.identifier(),
|
||||
FeatureColumnChangeDate.identifier(),
|
||||
FeatureColumnSequence.identifier(),
|
||||
FeatureColumnIsDefault.identifier(),
|
||||
@@ -187,25 +208,26 @@ func prepareFeatureQuery() (sq.SelectBuilder, func(*sql.Row) (*Feature, error))
|
||||
FeatureCustomTextLogin.identifier(),
|
||||
FeatureLockoutPolicy.identifier(),
|
||||
FeatureActions.identifier(),
|
||||
).From(loginPolicyTable.identifier()).PlaceholderFormat(sq.Dollar),
|
||||
func(row *sql.Row) (*Feature, error) {
|
||||
p := new(Feature)
|
||||
).From(featureTable.identifier()).PlaceholderFormat(sq.Dollar),
|
||||
func(row *sql.Row) (*Features, error) {
|
||||
p := new(Features)
|
||||
tierName := sql.NullString{}
|
||||
tierDescription := sql.NullString{}
|
||||
stateDescription := sql.NullString{}
|
||||
err := row.Scan(
|
||||
&p.AggregateID,
|
||||
&p.CreationDate,
|
||||
&p.ChangeDate,
|
||||
&p.Sequence,
|
||||
&p.IsDefault,
|
||||
&p.TierName,
|
||||
&p.TierDescription,
|
||||
&tierName,
|
||||
&tierDescription,
|
||||
&p.State,
|
||||
&p.StateDescription,
|
||||
&stateDescription,
|
||||
&p.AuditLogRetention,
|
||||
&p.LoginPolicyFactors,
|
||||
&p.LoginPolicyIDP,
|
||||
&p.LoginPolicyPasswordless,
|
||||
&p.LoginPolicyRegistration,
|
||||
&p.LoginPolicyRegistration,
|
||||
&p.LoginPolicyUsernameLogin,
|
||||
&p.LoginPolicyPasswordReset,
|
||||
&p.PasswordComplexityPolicy,
|
||||
@@ -221,10 +243,66 @@ func prepareFeatureQuery() (sq.SelectBuilder, func(*sql.Row) (*Feature, error))
|
||||
)
|
||||
if err != nil {
|
||||
if errs.Is(err, sql.ErrNoRows) {
|
||||
return nil, errors.ThrowNotFound(err, "QUERY-M9fse", "Errors.Feature.NotFound")
|
||||
return nil, errors.ThrowNotFound(err, "QUERY-M9fse", "Errors.Features.NotFound")
|
||||
}
|
||||
return nil, errors.ThrowInternal(err, "QUERY-3o9gd", "Errors.Internal")
|
||||
}
|
||||
p.TierName = tierName.String
|
||||
p.TierDescription = tierDescription.String
|
||||
p.StateDescription = stateDescription.String
|
||||
return p, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Features) EnabledFeatureTypes() []string {
|
||||
list := make([]string, 0)
|
||||
if f.LoginPolicyFactors {
|
||||
list = append(list, domain.FeatureLoginPolicyFactors)
|
||||
}
|
||||
if f.LoginPolicyIDP {
|
||||
list = append(list, domain.FeatureLoginPolicyIDP)
|
||||
}
|
||||
if f.LoginPolicyPasswordless {
|
||||
list = append(list, domain.FeatureLoginPolicyPasswordless)
|
||||
}
|
||||
if f.LoginPolicyRegistration {
|
||||
list = append(list, domain.FeatureLoginPolicyRegistration)
|
||||
}
|
||||
if f.LoginPolicyUsernameLogin {
|
||||
list = append(list, domain.FeatureLoginPolicyUsernameLogin)
|
||||
}
|
||||
if f.LoginPolicyPasswordReset {
|
||||
list = append(list, domain.FeatureLoginPolicyPasswordReset)
|
||||
}
|
||||
if f.PasswordComplexityPolicy {
|
||||
list = append(list, domain.FeaturePasswordComplexityPolicy)
|
||||
}
|
||||
if f.LabelPolicyPrivateLabel {
|
||||
list = append(list, domain.FeatureLabelPolicyPrivateLabel)
|
||||
}
|
||||
if f.LabelPolicyWatermark {
|
||||
list = append(list, domain.FeatureLabelPolicyWatermark)
|
||||
}
|
||||
if f.CustomDomain {
|
||||
list = append(list, domain.FeatureCustomDomain)
|
||||
}
|
||||
if f.PrivacyPolicy {
|
||||
list = append(list, domain.FeaturePrivacyPolicy)
|
||||
}
|
||||
if f.MetadataUser {
|
||||
list = append(list, domain.FeatureMetadataUser)
|
||||
}
|
||||
if f.CustomTextMessage {
|
||||
list = append(list, domain.FeatureCustomTextMessage)
|
||||
}
|
||||
if f.CustomTextLogin {
|
||||
list = append(list, domain.FeatureCustomTextLogin)
|
||||
}
|
||||
if f.LockoutPolicy {
|
||||
list = append(list, domain.FeatureLockoutPolicy)
|
||||
}
|
||||
if f.Actions {
|
||||
list = append(list, domain.FeatureActions)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
348
internal/query/features_test.go
Normal file
348
internal/query/features_test.go
Normal file
@@ -0,0 +1,348 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
errs "github.com/caos/zitadel/internal/errors"
|
||||
)
|
||||
|
||||
func Test_FeaturesPrepares(t *testing.T) {
|
||||
type want struct {
|
||||
sqlExpectations sqlExpectation
|
||||
err checkErr
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
prepare interface{}
|
||||
want want
|
||||
object interface{}
|
||||
}{
|
||||
{
|
||||
name: "prepareFeaturesQuery no result",
|
||||
prepare: prepareFeaturesQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.features.aggregate_id,`+
|
||||
` zitadel.projections.features.change_date,`+
|
||||
` zitadel.projections.features.sequence,`+
|
||||
` zitadel.projections.features.is_default,`+
|
||||
` zitadel.projections.features.tier_name,`+
|
||||
` zitadel.projections.features.tier_description,`+
|
||||
` zitadel.projections.features.state,`+
|
||||
` zitadel.projections.features.state_description,`+
|
||||
` zitadel.projections.features.audit_log_retention,`+
|
||||
` zitadel.projections.features.login_policy_factors,`+
|
||||
` zitadel.projections.features.login_policy_idp,`+
|
||||
` zitadel.projections.features.login_policy_passwordless,`+
|
||||
` zitadel.projections.features.login_policy_registration,`+
|
||||
` zitadel.projections.features.login_policy_username_login,`+
|
||||
` zitadel.projections.features.login_policy_password_reset,`+
|
||||
` zitadel.projections.features.password_complexity_policy,`+
|
||||
` zitadel.projections.features.label_policy_private_label,`+
|
||||
` zitadel.projections.features.label_policy_watermark,`+
|
||||
` zitadel.projections.features.custom_domain,`+
|
||||
` zitadel.projections.features.privacy_policy,`+
|
||||
` zitadel.projections.features.metadata_user,`+
|
||||
` zitadel.projections.features.custom_text_message,`+
|
||||
` zitadel.projections.features.custom_text_login,`+
|
||||
` zitadel.projections.features.lockout_policy,`+
|
||||
` zitadel.projections.features.actions`+
|
||||
` FROM zitadel.projections.features`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
if !errs.IsNotFound(err) {
|
||||
return fmt.Errorf("err should be zitadel.NotFoundError got: %w", err), false
|
||||
}
|
||||
return nil, true
|
||||
},
|
||||
},
|
||||
object: (*Features)(nil),
|
||||
},
|
||||
{
|
||||
name: "prepareFeaturesQuery found",
|
||||
prepare: prepareFeaturesQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.features.aggregate_id,`+
|
||||
` zitadel.projections.features.change_date,`+
|
||||
` zitadel.projections.features.sequence,`+
|
||||
` zitadel.projections.features.is_default,`+
|
||||
` zitadel.projections.features.tier_name,`+
|
||||
` zitadel.projections.features.tier_description,`+
|
||||
` zitadel.projections.features.state,`+
|
||||
` zitadel.projections.features.state_description,`+
|
||||
` zitadel.projections.features.audit_log_retention,`+
|
||||
` zitadel.projections.features.login_policy_factors,`+
|
||||
` zitadel.projections.features.login_policy_idp,`+
|
||||
` zitadel.projections.features.login_policy_passwordless,`+
|
||||
` zitadel.projections.features.login_policy_registration,`+
|
||||
` zitadel.projections.features.login_policy_username_login,`+
|
||||
` zitadel.projections.features.login_policy_password_reset,`+
|
||||
` zitadel.projections.features.password_complexity_policy,`+
|
||||
` zitadel.projections.features.label_policy_private_label,`+
|
||||
` zitadel.projections.features.label_policy_watermark,`+
|
||||
` zitadel.projections.features.custom_domain,`+
|
||||
` zitadel.projections.features.privacy_policy,`+
|
||||
` zitadel.projections.features.metadata_user,`+
|
||||
` zitadel.projections.features.custom_text_message,`+
|
||||
` zitadel.projections.features.custom_text_login,`+
|
||||
` zitadel.projections.features.lockout_policy,`+
|
||||
` zitadel.projections.features.actions`+
|
||||
` FROM zitadel.projections.features`),
|
||||
[]string{
|
||||
"aggregate_id",
|
||||
"change_date",
|
||||
"sequence",
|
||||
"is_default",
|
||||
"tier_name",
|
||||
"tier_description",
|
||||
"state",
|
||||
"state_description",
|
||||
"audit_log_retention",
|
||||
"login_policy_factors",
|
||||
"login_policy_idp",
|
||||
"login_policy_passwordless",
|
||||
"login_policy_registration",
|
||||
"login_policy_username_login",
|
||||
"login_policy_password_reset",
|
||||
"password_complexity_policy",
|
||||
"label_policy_private_label",
|
||||
"label_policy_watermark",
|
||||
"custom_domain",
|
||||
"privacy_policy",
|
||||
"metadata_user",
|
||||
"custom_text_message",
|
||||
"custom_text_login",
|
||||
"lockout_policy",
|
||||
"actions",
|
||||
},
|
||||
[]driver.Value{
|
||||
"aggregate-id",
|
||||
testNow,
|
||||
uint64(20211115),
|
||||
true,
|
||||
"tier-name",
|
||||
"tier-description",
|
||||
1,
|
||||
"state-description",
|
||||
uint(604800000000000), // 7days in nanoseconds
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
},
|
||||
),
|
||||
},
|
||||
object: &Features{
|
||||
AggregateID: "aggregate-id",
|
||||
ChangeDate: testNow,
|
||||
Sequence: 20211115,
|
||||
IsDefault: true,
|
||||
TierName: "tier-name",
|
||||
TierDescription: "tier-description",
|
||||
State: domain.FeaturesStateActive,
|
||||
StateDescription: "state-description",
|
||||
AuditLogRetention: 7 * 24 * time.Hour,
|
||||
LoginPolicyFactors: true,
|
||||
LoginPolicyIDP: true,
|
||||
LoginPolicyPasswordless: true,
|
||||
LoginPolicyRegistration: true,
|
||||
LoginPolicyUsernameLogin: true,
|
||||
LoginPolicyPasswordReset: true,
|
||||
PasswordComplexityPolicy: true,
|
||||
LabelPolicyPrivateLabel: true,
|
||||
LabelPolicyWatermark: true,
|
||||
CustomDomain: true,
|
||||
PrivacyPolicy: true,
|
||||
MetadataUser: true,
|
||||
CustomTextMessage: true,
|
||||
CustomTextLogin: true,
|
||||
LockoutPolicy: true,
|
||||
Actions: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "prepareFeaturesQuery found with empty",
|
||||
prepare: prepareFeaturesQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.features.aggregate_id,`+
|
||||
` zitadel.projections.features.change_date,`+
|
||||
` zitadel.projections.features.sequence,`+
|
||||
` zitadel.projections.features.is_default,`+
|
||||
` zitadel.projections.features.tier_name,`+
|
||||
` zitadel.projections.features.tier_description,`+
|
||||
` zitadel.projections.features.state,`+
|
||||
` zitadel.projections.features.state_description,`+
|
||||
` zitadel.projections.features.audit_log_retention,`+
|
||||
` zitadel.projections.features.login_policy_factors,`+
|
||||
` zitadel.projections.features.login_policy_idp,`+
|
||||
` zitadel.projections.features.login_policy_passwordless,`+
|
||||
` zitadel.projections.features.login_policy_registration,`+
|
||||
` zitadel.projections.features.login_policy_username_login,`+
|
||||
` zitadel.projections.features.login_policy_password_reset,`+
|
||||
` zitadel.projections.features.password_complexity_policy,`+
|
||||
` zitadel.projections.features.label_policy_private_label,`+
|
||||
` zitadel.projections.features.label_policy_watermark,`+
|
||||
` zitadel.projections.features.custom_domain,`+
|
||||
` zitadel.projections.features.privacy_policy,`+
|
||||
` zitadel.projections.features.metadata_user,`+
|
||||
` zitadel.projections.features.custom_text_message,`+
|
||||
` zitadel.projections.features.custom_text_login,`+
|
||||
` zitadel.projections.features.lockout_policy,`+
|
||||
` zitadel.projections.features.actions`+
|
||||
` FROM zitadel.projections.features`),
|
||||
[]string{
|
||||
"aggregate_id",
|
||||
"change_date",
|
||||
"sequence",
|
||||
"is_default",
|
||||
"tier_name",
|
||||
"tier_description",
|
||||
"state",
|
||||
"state_description",
|
||||
"audit_log_retention",
|
||||
"login_policy_factors",
|
||||
"login_policy_idp",
|
||||
"login_policy_passwordless",
|
||||
"login_policy_registration",
|
||||
"login_policy_username_login",
|
||||
"login_policy_password_reset",
|
||||
"password_complexity_policy",
|
||||
"label_policy_private_label",
|
||||
"label_policy_watermark",
|
||||
"custom_domain",
|
||||
"privacy_policy",
|
||||
"metadata_user",
|
||||
"custom_text_message",
|
||||
"custom_text_login",
|
||||
"lockout_policy",
|
||||
"actions",
|
||||
},
|
||||
[]driver.Value{
|
||||
"aggregate-id",
|
||||
testNow,
|
||||
uint64(20211115),
|
||||
true,
|
||||
nil,
|
||||
nil,
|
||||
1,
|
||||
nil,
|
||||
uint(604800000000000), // 7days in nanoseconds
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
},
|
||||
),
|
||||
},
|
||||
object: &Features{
|
||||
AggregateID: "aggregate-id",
|
||||
ChangeDate: testNow,
|
||||
Sequence: 20211115,
|
||||
IsDefault: true,
|
||||
TierName: "",
|
||||
TierDescription: "",
|
||||
State: domain.FeaturesStateActive,
|
||||
StateDescription: "",
|
||||
AuditLogRetention: 7 * 24 * time.Hour,
|
||||
LoginPolicyFactors: true,
|
||||
LoginPolicyIDP: true,
|
||||
LoginPolicyPasswordless: true,
|
||||
LoginPolicyRegistration: true,
|
||||
LoginPolicyUsernameLogin: true,
|
||||
LoginPolicyPasswordReset: true,
|
||||
PasswordComplexityPolicy: true,
|
||||
LabelPolicyPrivateLabel: true,
|
||||
LabelPolicyWatermark: true,
|
||||
CustomDomain: true,
|
||||
PrivacyPolicy: true,
|
||||
MetadataUser: true,
|
||||
CustomTextMessage: true,
|
||||
CustomTextLogin: true,
|
||||
LockoutPolicy: true,
|
||||
Actions: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "prepareFeaturesQuery sql err",
|
||||
prepare: prepareFeaturesQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.features.aggregate_id,`+
|
||||
` zitadel.projections.features.change_date,`+
|
||||
` zitadel.projections.features.sequence,`+
|
||||
` zitadel.projections.features.is_default,`+
|
||||
` zitadel.projections.features.tier_name,`+
|
||||
` zitadel.projections.features.tier_description,`+
|
||||
` zitadel.projections.features.state,`+
|
||||
` zitadel.projections.features.state_description,`+
|
||||
` zitadel.projections.features.audit_log_retention,`+
|
||||
` zitadel.projections.features.login_policy_factors,`+
|
||||
` zitadel.projections.features.login_policy_idp,`+
|
||||
` zitadel.projections.features.login_policy_passwordless,`+
|
||||
` zitadel.projections.features.login_policy_registration,`+
|
||||
` zitadel.projections.features.login_policy_username_login,`+
|
||||
` zitadel.projections.features.login_policy_password_reset,`+
|
||||
` zitadel.projections.features.password_complexity_policy,`+
|
||||
` zitadel.projections.features.label_policy_private_label,`+
|
||||
` zitadel.projections.features.label_policy_watermark,`+
|
||||
` zitadel.projections.features.custom_domain,`+
|
||||
` zitadel.projections.features.privacy_policy,`+
|
||||
` zitadel.projections.features.metadata_user,`+
|
||||
` zitadel.projections.features.custom_text_message,`+
|
||||
` zitadel.projections.features.custom_text_login,`+
|
||||
` zitadel.projections.features.lockout_policy,`+
|
||||
` zitadel.projections.features.actions`+
|
||||
` FROM zitadel.projections.features`),
|
||||
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: 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)
|
||||
})
|
||||
}
|
||||
}
|
@@ -4,12 +4,12 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/caos/zitadel/internal/repository/features"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/handler"
|
||||
"github.com/caos/zitadel/internal/eventstore/handler/crdb"
|
||||
"github.com/caos/zitadel/internal/repository/features"
|
||||
"github.com/caos/zitadel/internal/repository/iam"
|
||||
"github.com/caos/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -59,7 +59,6 @@ func (p *FeatureProjection) reducers() []handler.AggregateReducer {
|
||||
|
||||
const (
|
||||
FeatureAggregateIDCol = "aggregate_id"
|
||||
FeatureCreationDateCol = "creation_date"
|
||||
FeatureChangeDateCol = "change_date"
|
||||
FeatureSequenceCol = "sequence"
|
||||
FeatureIsDefaultCol = "is_default"
|
||||
@@ -103,7 +102,6 @@ func (p *FeatureProjection) reduceFeatureSet(event eventstore.EventReader) (*han
|
||||
|
||||
cols := []handler.Column{
|
||||
handler.NewCol(FeatureAggregateIDCol, featureEvent.Aggregate().ID),
|
||||
handler.NewCol(FeatureCreationDateCol, featureEvent.CreationDate()),
|
||||
handler.NewCol(FeatureChangeDateCol, featureEvent.CreationDate()),
|
||||
handler.NewCol(FeatureSequenceCol, featureEvent.Sequence()),
|
||||
handler.NewCol(FeatureIsDefaultCol, isDefault),
|
||||
|
@@ -63,11 +63,10 @@ func TestFeatureProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.features (aggregate_id, creation_date, change_date, sequence, is_default, tier_name, tier_description, state, state_description, audit_log_retention, login_policy_factors, login_policy_idp, login_policy_passwordless, login_policy_registration, login_policy_username_login, login_policy_password_reset, password_complexity_policy, label_policy_private_label, label_policy_watermark, custom_domain, privacy_policy, metadata_user, custom_text_message, custom_text_login, lockout_policy, actions) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)",
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.features (aggregate_id, change_date, sequence, is_default, tier_name, tier_description, state, state_description, audit_log_retention, login_policy_factors, login_policy_idp, login_policy_passwordless, login_policy_registration, login_policy_username_login, login_policy_password_reset, password_complexity_policy, label_policy_private_label, label_policy_watermark, custom_domain, privacy_policy, metadata_user, custom_text_message, custom_text_login, lockout_policy, actions) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
false,
|
||||
"TierName",
|
||||
@@ -97,6 +96,36 @@ func TestFeatureProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "org.reduceFeatureSet required values only",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.FeaturesSetEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.FeaturesSetEventMapper),
|
||||
},
|
||||
reduce: (&FeatureProjection{}).reduceFeatureSet,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
projection: FeatureTable,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.features (aggregate_id, change_date, sequence, is_default) VALUES ($1, $2, $3, $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "org.reduceFeatureRemoved",
|
||||
reduce: (&FeatureProjection{}).reduceFeatureRemoved,
|
||||
@@ -164,11 +193,10 @@ func TestFeatureProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.features (aggregate_id, creation_date, change_date, sequence, is_default, tier_name, tier_description, state, state_description, audit_log_retention, login_policy_factors, login_policy_idp, login_policy_passwordless, login_policy_registration, login_policy_username_login, login_policy_password_reset, password_complexity_policy, label_policy_private_label, label_policy_watermark, custom_domain, privacy_policy, metadata_user, custom_text_message, custom_text_login, lockout_policy, actions) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)",
|
||||
expectedStmt: "UPSERT INTO zitadel.projections.features (aggregate_id, change_date, sequence, is_default, tier_name, tier_description, state, state_description, audit_log_retention, login_policy_factors, login_policy_idp, login_policy_passwordless, login_policy_registration, login_policy_username_login, login_policy_password_reset, password_complexity_policy, label_policy_private_label, label_policy_watermark, custom_domain, privacy_policy, metadata_user, custom_text_message, custom_text_login, lockout_policy, actions) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
true,
|
||||
"TierName",
|
||||
@@ -203,7 +231,7 @@ func TestFeatureProjection_reduces(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
event := baseEvent(t)
|
||||
got, err := tt.reduce(event)
|
||||
if _, ok := err.(errors.InvalidArgument); !ok {
|
||||
if !errors.IsErrorInvalidArgument(err) {
|
||||
t.Errorf("no wrong event mapping: %v, got: %v", err, got)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user