mirror of
https://github.com/zitadel/zitadel.git
synced 2025-02-28 21:27:22 +00:00
test(queries): policies prepare funcs (#2651)
* chore(queries): test suite for prepare stmt funcs * test(queries): prepare project funcs * refactor: add comments * test: simlify expected sql, added possibility to add args to expected queries * test(queries): prepare funcs in org * chore(backend): correct modules * test(queries): org domain prepare funcs * test: correct name * refactor: file name * refactor: add table to login policy columns * chore(prepare_test): only add row to result if columns * test(queries): login policy prepare funcs * chore: add comments for configs * test(queries): prepare idp funcs * fix(queries): add table to password complexity policy cols * test(queries): password complexity policy prepare funcs * fix(queries): add table to password age policy cols * test(queries): password age policy prepare func * fix(queries): set cols on lockout policy * test(queries): lockout policy prepare funs * fix(queries): set table on privacy policy cols * test(queries): privacy policy prepare funcs * fix(queries): set table on org iam policy cols * fix(queries): correct table in org iam policy cols * test(queries): org iam policy prepare funcs
This commit is contained in:
parent
e5532238d8
commit
ed547ee1d4
@ -31,31 +31,40 @@ var (
|
||||
name: projection.LockoutPolicyTable,
|
||||
}
|
||||
LockoutColID = Column{
|
||||
name: projection.LockoutPolicyIDCol,
|
||||
name: projection.LockoutPolicyIDCol,
|
||||
table: lockoutTable,
|
||||
}
|
||||
LockoutColSequence = Column{
|
||||
name: projection.LockoutPolicySequenceCol,
|
||||
name: projection.LockoutPolicySequenceCol,
|
||||
table: lockoutTable,
|
||||
}
|
||||
LockoutColCreationDate = Column{
|
||||
name: projection.LockoutPolicyCreationDateCol,
|
||||
name: projection.LockoutPolicyCreationDateCol,
|
||||
table: lockoutTable,
|
||||
}
|
||||
LockoutColChangeDate = Column{
|
||||
name: projection.LockoutPolicyChangeDateCol,
|
||||
name: projection.LockoutPolicyChangeDateCol,
|
||||
table: lockoutTable,
|
||||
}
|
||||
LockoutColResourceOwner = Column{
|
||||
name: projection.LockoutPolicyResourceOwnerCol,
|
||||
name: projection.LockoutPolicyResourceOwnerCol,
|
||||
table: lockoutTable,
|
||||
}
|
||||
LockoutColShowFailures = Column{
|
||||
name: projection.LockoutPolicyShowLockOutFailuresCol,
|
||||
name: projection.LockoutPolicyShowLockOutFailuresCol,
|
||||
table: lockoutTable,
|
||||
}
|
||||
LockoutColMaxPasswordAttempts = Column{
|
||||
name: projection.LockoutPolicyMaxPasswordAttemptsCol,
|
||||
name: projection.LockoutPolicyMaxPasswordAttemptsCol,
|
||||
table: lockoutTable,
|
||||
}
|
||||
LockoutColIsDefault = Column{
|
||||
name: projection.LockoutPolicyIsDefaultCol,
|
||||
name: projection.LockoutPolicyIsDefaultCol,
|
||||
table: lockoutTable,
|
||||
}
|
||||
LockoutColState = Column{
|
||||
name: projection.LockoutPolicyStateCol,
|
||||
name: projection.LockoutPolicyStateCol,
|
||||
table: lockoutTable,
|
||||
}
|
||||
)
|
||||
|
||||
|
136
internal/query/lockout_policy_test.go
Normal file
136
internal/query/lockout_policy_test.go
Normal file
@ -0,0 +1,136 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
errs "github.com/caos/zitadel/internal/errors"
|
||||
)
|
||||
|
||||
func Test_LockoutPolicyPrepares(t *testing.T) {
|
||||
type want struct {
|
||||
sqlExpectations sqlExpectation
|
||||
err checkErr
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
prepare interface{}
|
||||
want want
|
||||
object interface{}
|
||||
}{
|
||||
{
|
||||
name: "prepareLockoutPolicyQuery no result",
|
||||
prepare: prepareLockoutPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.lockout_policies.id,`+
|
||||
` zitadel.projections.lockout_policies.sequence,`+
|
||||
` zitadel.projections.lockout_policies.creation_date,`+
|
||||
` zitadel.projections.lockout_policies.change_date,`+
|
||||
` zitadel.projections.lockout_policies.resource_owner,`+
|
||||
` zitadel.projections.lockout_policies.show_failure,`+
|
||||
` zitadel.projections.lockout_policies.max_password_attempts,`+
|
||||
` zitadel.projections.lockout_policies.is_default,`+
|
||||
` zitadel.projections.lockout_policies.state`+
|
||||
` FROM zitadel.projections.lockout_policies`),
|
||||
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: (*LockoutPolicy)(nil),
|
||||
},
|
||||
{
|
||||
name: "prepareLockoutPolicyQuery found",
|
||||
prepare: prepareLockoutPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.lockout_policies.id,`+
|
||||
` zitadel.projections.lockout_policies.sequence,`+
|
||||
` zitadel.projections.lockout_policies.creation_date,`+
|
||||
` zitadel.projections.lockout_policies.change_date,`+
|
||||
` zitadel.projections.lockout_policies.resource_owner,`+
|
||||
` zitadel.projections.lockout_policies.show_failure,`+
|
||||
` zitadel.projections.lockout_policies.max_password_attempts,`+
|
||||
` zitadel.projections.lockout_policies.is_default,`+
|
||||
` zitadel.projections.lockout_policies.state`+
|
||||
` FROM zitadel.projections.lockout_policies`),
|
||||
[]string{
|
||||
"id",
|
||||
"sequence",
|
||||
"creation_date",
|
||||
"change_date",
|
||||
"resource_owner",
|
||||
"show_failure",
|
||||
"max_password_attempts",
|
||||
"is_default",
|
||||
"state",
|
||||
},
|
||||
[]driver.Value{
|
||||
"pol-id",
|
||||
uint64(20211109),
|
||||
testNow,
|
||||
testNow,
|
||||
"ro",
|
||||
true,
|
||||
20,
|
||||
true,
|
||||
domain.PolicyStateActive,
|
||||
},
|
||||
),
|
||||
},
|
||||
object: &LockoutPolicy{
|
||||
ID: "pol-id",
|
||||
CreationDate: testNow,
|
||||
ChangeDate: testNow,
|
||||
Sequence: 20211109,
|
||||
ResourceOwner: "ro",
|
||||
State: domain.PolicyStateActive,
|
||||
ShowFailures: true,
|
||||
MaxPasswordAttempts: 20,
|
||||
IsDefault: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "prepareLockoutPolicyQuery sql err",
|
||||
prepare: prepareLockoutPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.lockout_policies.id,`+
|
||||
` zitadel.projections.lockout_policies.sequence,`+
|
||||
` zitadel.projections.lockout_policies.creation_date,`+
|
||||
` zitadel.projections.lockout_policies.change_date,`+
|
||||
` zitadel.projections.lockout_policies.resource_owner,`+
|
||||
` zitadel.projections.lockout_policies.show_failure,`+
|
||||
` zitadel.projections.lockout_policies.max_password_attempts,`+
|
||||
` zitadel.projections.lockout_policies.is_default,`+
|
||||
` zitadel.projections.lockout_policies.state`+
|
||||
` FROM zitadel.projections.lockout_policies`),
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
@ -30,28 +30,36 @@ var (
|
||||
name: projection.OrgIAMPolicyTable,
|
||||
}
|
||||
OrgIAMColID = Column{
|
||||
name: projection.OrgIAMPolicyIDCol,
|
||||
name: projection.OrgIAMPolicyIDCol,
|
||||
table: orgIAMTable,
|
||||
}
|
||||
OrgIAMColSequence = Column{
|
||||
name: projection.OrgIAMPolicySequenceCol,
|
||||
name: projection.OrgIAMPolicySequenceCol,
|
||||
table: orgIAMTable,
|
||||
}
|
||||
OrgIAMColCreationDate = Column{
|
||||
name: projection.OrgIAMPolicyCreationDateCol,
|
||||
name: projection.OrgIAMPolicyCreationDateCol,
|
||||
table: orgIAMTable,
|
||||
}
|
||||
OrgIAMColChangeDate = Column{
|
||||
name: projection.OrgIAMPolicyChangeDateCol,
|
||||
name: projection.OrgIAMPolicyChangeDateCol,
|
||||
table: orgIAMTable,
|
||||
}
|
||||
OrgIAMColResourceOwner = Column{
|
||||
name: projection.OrgIAMPolicyResourceOwnerCol,
|
||||
name: projection.OrgIAMPolicyResourceOwnerCol,
|
||||
table: orgIAMTable,
|
||||
}
|
||||
OrgIAMColUserLoginMustBeDomain = Column{
|
||||
name: projection.OrgIAMPolicyUserLoginMustBeDomainCol,
|
||||
name: projection.OrgIAMPolicyUserLoginMustBeDomainCol,
|
||||
table: orgIAMTable,
|
||||
}
|
||||
OrgIAMColIsDefault = Column{
|
||||
name: projection.OrgIAMPolicyIsDefaultCol,
|
||||
name: projection.OrgIAMPolicyIsDefaultCol,
|
||||
table: orgIAMTable,
|
||||
}
|
||||
OrgIAMColState = Column{
|
||||
name: projection.OrgIAMPolicyStateCol,
|
||||
name: projection.OrgIAMPolicyStateCol,
|
||||
table: orgIAMTable,
|
||||
}
|
||||
)
|
||||
|
||||
|
130
internal/query/org_iam_policy_test.go
Normal file
130
internal/query/org_iam_policy_test.go
Normal file
@ -0,0 +1,130 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
errs "github.com/caos/zitadel/internal/errors"
|
||||
)
|
||||
|
||||
func Test_OrgIAMPolicyPrepares(t *testing.T) {
|
||||
type want struct {
|
||||
sqlExpectations sqlExpectation
|
||||
err checkErr
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
prepare interface{}
|
||||
want want
|
||||
object interface{}
|
||||
}{
|
||||
{
|
||||
name: "prepareOrgIAMPolicyQuery no result",
|
||||
prepare: prepareOrgIAMPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.org_iam_policies.id,`+
|
||||
` zitadel.projections.org_iam_policies.sequence,`+
|
||||
` zitadel.projections.org_iam_policies.creation_date,`+
|
||||
` zitadel.projections.org_iam_policies.change_date,`+
|
||||
` zitadel.projections.org_iam_policies.resource_owner,`+
|
||||
` zitadel.projections.org_iam_policies.user_login_must_be_domain,`+
|
||||
` zitadel.projections.org_iam_policies.is_default,`+
|
||||
` zitadel.projections.org_iam_policies.state`+
|
||||
` FROM zitadel.projections.org_iam_policies`),
|
||||
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: (*OrgIAMPolicy)(nil),
|
||||
},
|
||||
{
|
||||
name: "prepareOrgIAMPolicyQuery found",
|
||||
prepare: prepareOrgIAMPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.org_iam_policies.id,`+
|
||||
` zitadel.projections.org_iam_policies.sequence,`+
|
||||
` zitadel.projections.org_iam_policies.creation_date,`+
|
||||
` zitadel.projections.org_iam_policies.change_date,`+
|
||||
` zitadel.projections.org_iam_policies.resource_owner,`+
|
||||
` zitadel.projections.org_iam_policies.user_login_must_be_domain,`+
|
||||
` zitadel.projections.org_iam_policies.is_default,`+
|
||||
` zitadel.projections.org_iam_policies.state`+
|
||||
` FROM zitadel.projections.org_iam_policies`),
|
||||
[]string{
|
||||
"id",
|
||||
"sequence",
|
||||
"creation_date",
|
||||
"change_date",
|
||||
"resource_owner",
|
||||
"user_login_must_be_domain",
|
||||
"is_default",
|
||||
"state",
|
||||
},
|
||||
[]driver.Value{
|
||||
"pol-id",
|
||||
uint64(20211109),
|
||||
testNow,
|
||||
testNow,
|
||||
"ro",
|
||||
true,
|
||||
true,
|
||||
domain.PolicyStateActive,
|
||||
},
|
||||
),
|
||||
},
|
||||
object: &OrgIAMPolicy{
|
||||
ID: "pol-id",
|
||||
CreationDate: testNow,
|
||||
ChangeDate: testNow,
|
||||
Sequence: 20211109,
|
||||
ResourceOwner: "ro",
|
||||
State: domain.PolicyStateActive,
|
||||
UserLoginMustBeDomain: true,
|
||||
IsDefault: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "prepareOrgIAMPolicyQuery sql err",
|
||||
prepare: prepareOrgIAMPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.org_iam_policies.id,`+
|
||||
` zitadel.projections.org_iam_policies.sequence,`+
|
||||
` zitadel.projections.org_iam_policies.creation_date,`+
|
||||
` zitadel.projections.org_iam_policies.change_date,`+
|
||||
` zitadel.projections.org_iam_policies.resource_owner,`+
|
||||
` zitadel.projections.org_iam_policies.user_login_must_be_domain,`+
|
||||
` zitadel.projections.org_iam_policies.is_default,`+
|
||||
` zitadel.projections.org_iam_policies.state`+
|
||||
` FROM zitadel.projections.org_iam_policies`),
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
@ -31,31 +31,40 @@ var (
|
||||
name: projection.PasswordAgeTable,
|
||||
}
|
||||
PasswordAgeColID = Column{
|
||||
name: projection.AgePolicyIDCol,
|
||||
name: projection.AgePolicyIDCol,
|
||||
table: passwordAgeTable,
|
||||
}
|
||||
PasswordAgeColSequence = Column{
|
||||
name: projection.AgePolicySequenceCol,
|
||||
name: projection.AgePolicySequenceCol,
|
||||
table: passwordAgeTable,
|
||||
}
|
||||
PasswordAgeColCreationDate = Column{
|
||||
name: projection.AgePolicyCreationDateCol,
|
||||
name: projection.AgePolicyCreationDateCol,
|
||||
table: passwordAgeTable,
|
||||
}
|
||||
PasswordAgeColChangeDate = Column{
|
||||
name: projection.AgePolicyChangeDateCol,
|
||||
name: projection.AgePolicyChangeDateCol,
|
||||
table: passwordAgeTable,
|
||||
}
|
||||
PasswordAgeColResourceOwner = Column{
|
||||
name: projection.AgePolicyResourceOwnerCol,
|
||||
name: projection.AgePolicyResourceOwnerCol,
|
||||
table: passwordAgeTable,
|
||||
}
|
||||
PasswordAgeColWarnDays = Column{
|
||||
name: projection.AgePolicyExpireWarnDaysCol,
|
||||
name: projection.AgePolicyExpireWarnDaysCol,
|
||||
table: passwordAgeTable,
|
||||
}
|
||||
PasswordAgeColMaxAge = Column{
|
||||
name: projection.AgePolicyMaxAgeDaysCol,
|
||||
name: projection.AgePolicyMaxAgeDaysCol,
|
||||
table: passwordAgeTable,
|
||||
}
|
||||
PasswordAgeColIsDefault = Column{
|
||||
name: projection.AgePolicyIsDefaultCol,
|
||||
name: projection.AgePolicyIsDefaultCol,
|
||||
table: passwordAgeTable,
|
||||
}
|
||||
PasswordAgeColState = Column{
|
||||
name: projection.AgePolicyStateCol,
|
||||
name: projection.AgePolicyStateCol,
|
||||
table: passwordAgeTable,
|
||||
}
|
||||
)
|
||||
|
||||
|
136
internal/query/password_age_policy_test.go
Normal file
136
internal/query/password_age_policy_test.go
Normal file
@ -0,0 +1,136 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
errs "github.com/caos/zitadel/internal/errors"
|
||||
)
|
||||
|
||||
func Test_PasswordAgePolicyPrepares(t *testing.T) {
|
||||
type want struct {
|
||||
sqlExpectations sqlExpectation
|
||||
err checkErr
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
prepare interface{}
|
||||
want want
|
||||
object interface{}
|
||||
}{
|
||||
{
|
||||
name: "preparePasswordAgePolicyQuery no result",
|
||||
prepare: preparePasswordAgePolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.password_age_policies.id,`+
|
||||
` zitadel.projections.password_age_policies.sequence,`+
|
||||
` zitadel.projections.password_age_policies.creation_date,`+
|
||||
` zitadel.projections.password_age_policies.change_date,`+
|
||||
` zitadel.projections.password_age_policies.resource_owner,`+
|
||||
` zitadel.projections.password_age_policies.expire_warn_days,`+
|
||||
` zitadel.projections.password_age_policies.max_age_days,`+
|
||||
` zitadel.projections.password_age_policies.is_default,`+
|
||||
` zitadel.projections.password_age_policies.state`+
|
||||
` FROM zitadel.projections.password_age_policies`),
|
||||
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: (*PasswordAgePolicy)(nil),
|
||||
},
|
||||
{
|
||||
name: "preparePasswordAgePolicyQuery found",
|
||||
prepare: preparePasswordAgePolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.password_age_policies.id,`+
|
||||
` zitadel.projections.password_age_policies.sequence,`+
|
||||
` zitadel.projections.password_age_policies.creation_date,`+
|
||||
` zitadel.projections.password_age_policies.change_date,`+
|
||||
` zitadel.projections.password_age_policies.resource_owner,`+
|
||||
` zitadel.projections.password_age_policies.expire_warn_days,`+
|
||||
` zitadel.projections.password_age_policies.max_age_days,`+
|
||||
` zitadel.projections.password_age_policies.is_default,`+
|
||||
` zitadel.projections.password_age_policies.state`+
|
||||
` FROM zitadel.projections.password_age_policies`),
|
||||
[]string{
|
||||
"id",
|
||||
"sequence",
|
||||
"creation_date",
|
||||
"change_date",
|
||||
"resource_owner",
|
||||
"expire_warn_days",
|
||||
"max_age_days",
|
||||
"is_default",
|
||||
"state",
|
||||
},
|
||||
[]driver.Value{
|
||||
"pol-id",
|
||||
uint64(20211109),
|
||||
testNow,
|
||||
testNow,
|
||||
"ro",
|
||||
10,
|
||||
20,
|
||||
true,
|
||||
domain.PolicyStateActive,
|
||||
},
|
||||
),
|
||||
},
|
||||
object: &PasswordAgePolicy{
|
||||
ID: "pol-id",
|
||||
CreationDate: testNow,
|
||||
ChangeDate: testNow,
|
||||
Sequence: 20211109,
|
||||
ResourceOwner: "ro",
|
||||
State: domain.PolicyStateActive,
|
||||
ExpireWarnDays: 10,
|
||||
MaxAgeDays: 20,
|
||||
IsDefault: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "preparePasswordAgePolicyQuery sql err",
|
||||
prepare: preparePasswordAgePolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.password_age_policies.id,`+
|
||||
` zitadel.projections.password_age_policies.sequence,`+
|
||||
` zitadel.projections.password_age_policies.creation_date,`+
|
||||
` zitadel.projections.password_age_policies.change_date,`+
|
||||
` zitadel.projections.password_age_policies.resource_owner,`+
|
||||
` zitadel.projections.password_age_policies.expire_warn_days,`+
|
||||
` zitadel.projections.password_age_policies.max_age_days,`+
|
||||
` zitadel.projections.password_age_policies.is_default,`+
|
||||
` zitadel.projections.password_age_policies.state`+
|
||||
` FROM zitadel.projections.password_age_policies`),
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
@ -70,40 +70,52 @@ var (
|
||||
name: projection.PasswordComplexityTable,
|
||||
}
|
||||
PasswordComplexityColID = Column{
|
||||
name: projection.ComplexityPolicyIDCol,
|
||||
name: projection.ComplexityPolicyIDCol,
|
||||
table: passwordComplexityTable,
|
||||
}
|
||||
PasswordComplexityColSequence = Column{
|
||||
name: projection.ComplexityPolicySequenceCol,
|
||||
name: projection.ComplexityPolicySequenceCol,
|
||||
table: passwordComplexityTable,
|
||||
}
|
||||
PasswordComplexityColCreationDate = Column{
|
||||
name: projection.ComplexityPolicyCreationDateCol,
|
||||
name: projection.ComplexityPolicyCreationDateCol,
|
||||
table: passwordComplexityTable,
|
||||
}
|
||||
PasswordComplexityColChangeDate = Column{
|
||||
name: projection.ComplexityPolicyChangeDateCol,
|
||||
name: projection.ComplexityPolicyChangeDateCol,
|
||||
table: passwordComplexityTable,
|
||||
}
|
||||
PasswordComplexityColResourceOwner = Column{
|
||||
name: projection.ComplexityPolicyResourceOwnerCol,
|
||||
name: projection.ComplexityPolicyResourceOwnerCol,
|
||||
table: passwordComplexityTable,
|
||||
}
|
||||
PasswordComplexityColMinLength = Column{
|
||||
name: projection.ComplexityPolicyMinLengthCol,
|
||||
name: projection.ComplexityPolicyMinLengthCol,
|
||||
table: passwordComplexityTable,
|
||||
}
|
||||
PasswordComplexityColHasLowercase = Column{
|
||||
name: projection.ComplexityPolicyHasLowercaseCol,
|
||||
name: projection.ComplexityPolicyHasLowercaseCol,
|
||||
table: passwordComplexityTable,
|
||||
}
|
||||
PasswordComplexityColHasUpperCase = Column{
|
||||
name: projection.ComplexityPolicyHasUppercaseCol,
|
||||
name: projection.ComplexityPolicyHasUppercaseCol,
|
||||
table: passwordComplexityTable,
|
||||
}
|
||||
PasswordComplexityColHasNumber = Column{
|
||||
name: projection.ComplexityPolicyHasNumberCol,
|
||||
name: projection.ComplexityPolicyHasNumberCol,
|
||||
table: passwordComplexityTable,
|
||||
}
|
||||
PasswordComplexityColHasSymbol = Column{
|
||||
name: projection.ComplexityPolicyHasSymbolCol,
|
||||
name: projection.ComplexityPolicyHasSymbolCol,
|
||||
table: passwordComplexityTable,
|
||||
}
|
||||
PasswordComplexityColIsDefault = Column{
|
||||
name: projection.ComplexityPolicyIsDefaultCol,
|
||||
name: projection.ComplexityPolicyIsDefaultCol,
|
||||
table: passwordComplexityTable,
|
||||
}
|
||||
PasswordComplexityColState = Column{
|
||||
name: projection.ComplexityPolicyStateCol,
|
||||
name: projection.ComplexityPolicyStateCol,
|
||||
table: passwordComplexityTable,
|
||||
}
|
||||
)
|
||||
|
||||
|
154
internal/query/password_complexity_policy_test.go
Normal file
154
internal/query/password_complexity_policy_test.go
Normal file
@ -0,0 +1,154 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
errs "github.com/caos/zitadel/internal/errors"
|
||||
)
|
||||
|
||||
func Test_PasswordComplexityPolicyPrepares(t *testing.T) {
|
||||
type want struct {
|
||||
sqlExpectations sqlExpectation
|
||||
err checkErr
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
prepare interface{}
|
||||
want want
|
||||
object interface{}
|
||||
}{
|
||||
{
|
||||
name: "preparePasswordComplexityPolicyQuery no result",
|
||||
prepare: preparePasswordComplexityPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.password_complexity_policies.id,`+
|
||||
` zitadel.projections.password_complexity_policies.sequence,`+
|
||||
` zitadel.projections.password_complexity_policies.creation_date,`+
|
||||
` zitadel.projections.password_complexity_policies.change_date,`+
|
||||
` zitadel.projections.password_complexity_policies.resource_owner,`+
|
||||
` zitadel.projections.password_complexity_policies.min_length,`+
|
||||
` zitadel.projections.password_complexity_policies.has_lowercase,`+
|
||||
` zitadel.projections.password_complexity_policies.has_uppercase,`+
|
||||
` zitadel.projections.password_complexity_policies.has_number,`+
|
||||
` zitadel.projections.password_complexity_policies.has_symbol,`+
|
||||
` zitadel.projections.password_complexity_policies.is_default,`+
|
||||
` zitadel.projections.password_complexity_policies.state`+
|
||||
` FROM zitadel.projections.password_complexity_policies`),
|
||||
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: (*PasswordComplexityPolicy)(nil),
|
||||
},
|
||||
{
|
||||
name: "preparePasswordComplexityPolicyQuery found",
|
||||
prepare: preparePasswordComplexityPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.password_complexity_policies.id,`+
|
||||
` zitadel.projections.password_complexity_policies.sequence,`+
|
||||
` zitadel.projections.password_complexity_policies.creation_date,`+
|
||||
` zitadel.projections.password_complexity_policies.change_date,`+
|
||||
` zitadel.projections.password_complexity_policies.resource_owner,`+
|
||||
` zitadel.projections.password_complexity_policies.min_length,`+
|
||||
` zitadel.projections.password_complexity_policies.has_lowercase,`+
|
||||
` zitadel.projections.password_complexity_policies.has_uppercase,`+
|
||||
` zitadel.projections.password_complexity_policies.has_number,`+
|
||||
` zitadel.projections.password_complexity_policies.has_symbol,`+
|
||||
` zitadel.projections.password_complexity_policies.is_default,`+
|
||||
` zitadel.projections.password_complexity_policies.state`+
|
||||
` FROM zitadel.projections.password_complexity_policies`),
|
||||
[]string{
|
||||
"id",
|
||||
"sequence",
|
||||
"creation_date",
|
||||
"change_date",
|
||||
"resource_owner",
|
||||
"min_length",
|
||||
"has_lowercase",
|
||||
"has_uppercase",
|
||||
"has_number",
|
||||
"has_symbol",
|
||||
"is_default",
|
||||
"state",
|
||||
},
|
||||
[]driver.Value{
|
||||
"pol-id",
|
||||
uint64(20211109),
|
||||
testNow,
|
||||
testNow,
|
||||
"ro",
|
||||
8,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
domain.PolicyStateActive,
|
||||
},
|
||||
),
|
||||
},
|
||||
object: &PasswordComplexityPolicy{
|
||||
ID: "pol-id",
|
||||
CreationDate: testNow,
|
||||
ChangeDate: testNow,
|
||||
Sequence: 20211109,
|
||||
ResourceOwner: "ro",
|
||||
State: domain.PolicyStateActive,
|
||||
MinLength: 8,
|
||||
HasLowercase: true,
|
||||
HasUppercase: true,
|
||||
HasNumber: true,
|
||||
HasSymbol: true,
|
||||
IsDefault: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "preparePasswordComplexityPolicyQuery sql err",
|
||||
prepare: preparePasswordComplexityPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.password_complexity_policies.id,`+
|
||||
` zitadel.projections.password_complexity_policies.sequence,`+
|
||||
` zitadel.projections.password_complexity_policies.creation_date,`+
|
||||
` zitadel.projections.password_complexity_policies.change_date,`+
|
||||
` zitadel.projections.password_complexity_policies.resource_owner,`+
|
||||
` zitadel.projections.password_complexity_policies.min_length,`+
|
||||
` zitadel.projections.password_complexity_policies.has_lowercase,`+
|
||||
` zitadel.projections.password_complexity_policies.has_uppercase,`+
|
||||
` zitadel.projections.password_complexity_policies.has_number,`+
|
||||
` zitadel.projections.password_complexity_policies.has_symbol,`+
|
||||
` zitadel.projections.password_complexity_policies.is_default,`+
|
||||
` zitadel.projections.password_complexity_policies.state`+
|
||||
` FROM zitadel.projections.password_complexity_policies`),
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
@ -31,31 +31,40 @@ var (
|
||||
name: projection.PrivacyPolicyTable,
|
||||
}
|
||||
PrivacyColID = Column{
|
||||
name: projection.PrivacyPolicyIDCol,
|
||||
name: projection.PrivacyPolicyIDCol,
|
||||
table: privacyTable,
|
||||
}
|
||||
PrivacyColSequence = Column{
|
||||
name: projection.PrivacyPolicySequenceCol,
|
||||
name: projection.PrivacyPolicySequenceCol,
|
||||
table: privacyTable,
|
||||
}
|
||||
PrivacyColCreationDate = Column{
|
||||
name: projection.PrivacyPolicyCreationDateCol,
|
||||
name: projection.PrivacyPolicyCreationDateCol,
|
||||
table: privacyTable,
|
||||
}
|
||||
PrivacyColChangeDate = Column{
|
||||
name: projection.PrivacyPolicyChangeDateCol,
|
||||
name: projection.PrivacyPolicyChangeDateCol,
|
||||
table: privacyTable,
|
||||
}
|
||||
PrivacyColResourceOwner = Column{
|
||||
name: projection.PrivacyPolicyResourceOwnerCol,
|
||||
name: projection.PrivacyPolicyResourceOwnerCol,
|
||||
table: privacyTable,
|
||||
}
|
||||
PrivacyColPrivacyLink = Column{
|
||||
name: projection.PrivacyPolicyPrivacyLinkCol,
|
||||
name: projection.PrivacyPolicyPrivacyLinkCol,
|
||||
table: privacyTable,
|
||||
}
|
||||
PrivacyColTOSLink = Column{
|
||||
name: projection.PrivacyPolicyTOSLinkCol,
|
||||
name: projection.PrivacyPolicyTOSLinkCol,
|
||||
table: privacyTable,
|
||||
}
|
||||
PrivacyColIsDefault = Column{
|
||||
name: projection.PrivacyPolicyIsDefaultCol,
|
||||
name: projection.PrivacyPolicyIsDefaultCol,
|
||||
table: privacyTable,
|
||||
}
|
||||
PrivacyColState = Column{
|
||||
name: projection.PrivacyPolicyStateCol,
|
||||
name: projection.PrivacyPolicyStateCol,
|
||||
table: privacyTable,
|
||||
}
|
||||
)
|
||||
|
||||
|
136
internal/query/privacy_policy_test.go
Normal file
136
internal/query/privacy_policy_test.go
Normal file
@ -0,0 +1,136 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
errs "github.com/caos/zitadel/internal/errors"
|
||||
)
|
||||
|
||||
func Test_PrivacyPolicyPrepares(t *testing.T) {
|
||||
type want struct {
|
||||
sqlExpectations sqlExpectation
|
||||
err checkErr
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
prepare interface{}
|
||||
want want
|
||||
object interface{}
|
||||
}{
|
||||
{
|
||||
name: "preparePrivacyPolicyQuery no result",
|
||||
prepare: preparePrivacyPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.privacy_policies.id,`+
|
||||
` zitadel.projections.privacy_policies.sequence,`+
|
||||
` zitadel.projections.privacy_policies.creation_date,`+
|
||||
` zitadel.projections.privacy_policies.change_date,`+
|
||||
` zitadel.projections.privacy_policies.resource_owner,`+
|
||||
` zitadel.projections.privacy_policies.privacy_link,`+
|
||||
` zitadel.projections.privacy_policies.tos_link,`+
|
||||
` zitadel.projections.privacy_policies.is_default,`+
|
||||
` zitadel.projections.privacy_policies.state`+
|
||||
` FROM zitadel.projections.privacy_policies`),
|
||||
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: (*PrivacyPolicy)(nil),
|
||||
},
|
||||
{
|
||||
name: "preparePrivacyPolicyQuery found",
|
||||
prepare: preparePrivacyPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.privacy_policies.id,`+
|
||||
` zitadel.projections.privacy_policies.sequence,`+
|
||||
` zitadel.projections.privacy_policies.creation_date,`+
|
||||
` zitadel.projections.privacy_policies.change_date,`+
|
||||
` zitadel.projections.privacy_policies.resource_owner,`+
|
||||
` zitadel.projections.privacy_policies.privacy_link,`+
|
||||
` zitadel.projections.privacy_policies.tos_link,`+
|
||||
` zitadel.projections.privacy_policies.is_default,`+
|
||||
` zitadel.projections.privacy_policies.state`+
|
||||
` FROM zitadel.projections.privacy_policies`),
|
||||
[]string{
|
||||
"id",
|
||||
"sequence",
|
||||
"creation_date",
|
||||
"change_date",
|
||||
"resource_owner",
|
||||
"privacy_link",
|
||||
"tos_link",
|
||||
"is_default",
|
||||
"state",
|
||||
},
|
||||
[]driver.Value{
|
||||
"pol-id",
|
||||
uint64(20211109),
|
||||
testNow,
|
||||
testNow,
|
||||
"ro",
|
||||
"privacy.ch",
|
||||
"tos.ch",
|
||||
true,
|
||||
domain.PolicyStateActive,
|
||||
},
|
||||
),
|
||||
},
|
||||
object: &PrivacyPolicy{
|
||||
ID: "pol-id",
|
||||
CreationDate: testNow,
|
||||
ChangeDate: testNow,
|
||||
Sequence: 20211109,
|
||||
ResourceOwner: "ro",
|
||||
State: domain.PolicyStateActive,
|
||||
PrivacyLink: "privacy.ch",
|
||||
TOSLink: "tos.ch",
|
||||
IsDefault: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "preparePrivacyPolicyQuery sql err",
|
||||
prepare: preparePrivacyPolicyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT zitadel.projections.privacy_policies.id,`+
|
||||
` zitadel.projections.privacy_policies.sequence,`+
|
||||
` zitadel.projections.privacy_policies.creation_date,`+
|
||||
` zitadel.projections.privacy_policies.change_date,`+
|
||||
` zitadel.projections.privacy_policies.resource_owner,`+
|
||||
` zitadel.projections.privacy_policies.privacy_link,`+
|
||||
` zitadel.projections.privacy_policies.tos_link,`+
|
||||
` zitadel.projections.privacy_policies.is_default,`+
|
||||
` zitadel.projections.privacy_policies.state`+
|
||||
` FROM zitadel.projections.privacy_policies`),
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user