mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:57:33 +00:00
feat: provide option to limit (T)OTP checks (#7693)
* feat: provide option to limit (T)OTP checks * fix requests in console * update errors pkg * cleanup * cleanup * improve naming of existing config
This commit is contained in:
@@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
LockoutPolicyTable = "projections.lockout_policies2"
|
||||
LockoutPolicyTable = "projections.lockout_policies3"
|
||||
|
||||
LockoutPolicyIDCol = "id"
|
||||
LockoutPolicyCreationDateCol = "creation_date"
|
||||
@@ -25,8 +25,8 @@ const (
|
||||
LockoutPolicyResourceOwnerCol = "resource_owner"
|
||||
LockoutPolicyInstanceIDCol = "instance_id"
|
||||
LockoutPolicyMaxPasswordAttemptsCol = "max_password_attempts"
|
||||
LockoutPolicyMaxOTPAttemptsCol = "max_otp_attempts"
|
||||
LockoutPolicyShowLockOutFailuresCol = "show_failure"
|
||||
LockoutPolicyOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type lockoutPolicyProjection struct{}
|
||||
@@ -51,11 +51,10 @@ func (*lockoutPolicyProjection) Init() *old_handler.Check {
|
||||
handler.NewColumn(LockoutPolicyResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LockoutPolicyInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LockoutPolicyMaxPasswordAttemptsCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(LockoutPolicyMaxOTPAttemptsCol, handler.ColumnTypeInt64, handler.Default(0)),
|
||||
handler.NewColumn(LockoutPolicyShowLockOutFailuresCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(LockoutPolicyOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
handler.NewPrimaryKey(LockoutPolicyInstanceIDCol, LockoutPolicyIDCol),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{LockoutPolicyOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -125,6 +124,7 @@ func (p *lockoutPolicyProjection) reduceAdded(event eventstore.Event) (*handler.
|
||||
handler.NewCol(LockoutPolicyIDCol, policyEvent.Aggregate().ID),
|
||||
handler.NewCol(LockoutPolicyStateCol, domain.PolicyStateActive),
|
||||
handler.NewCol(LockoutPolicyMaxPasswordAttemptsCol, policyEvent.MaxPasswordAttempts),
|
||||
handler.NewCol(LockoutPolicyMaxOTPAttemptsCol, policyEvent.MaxOTPAttempts),
|
||||
handler.NewCol(LockoutPolicyShowLockOutFailuresCol, policyEvent.ShowLockOutFailures),
|
||||
handler.NewCol(LockoutPolicyIsDefaultCol, isDefault),
|
||||
handler.NewCol(LockoutPolicyResourceOwnerCol, policyEvent.Aggregate().ResourceOwner),
|
||||
@@ -149,6 +149,9 @@ func (p *lockoutPolicyProjection) reduceChanged(event eventstore.Event) (*handle
|
||||
if policyEvent.MaxPasswordAttempts != nil {
|
||||
cols = append(cols, handler.NewCol(LockoutPolicyMaxPasswordAttemptsCol, *policyEvent.MaxPasswordAttempts))
|
||||
}
|
||||
if policyEvent.MaxOTPAttempts != nil {
|
||||
cols = append(cols, handler.NewCol(LockoutPolicyMaxOTPAttemptsCol, *policyEvent.MaxOTPAttempts))
|
||||
}
|
||||
if policyEvent.ShowLockOutFailures != nil {
|
||||
cols = append(cols, handler.NewCol(LockoutPolicyShowLockOutFailuresCol, *policyEvent.ShowLockOutFailures))
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"maxPasswordAttempts": 10,
|
||||
"maxOTPAttempts": 10,
|
||||
"showLockOutFailures": true
|
||||
}`),
|
||||
), org.LockoutPolicyAddedEventMapper),
|
||||
@@ -41,7 +42,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.lockout_policies2 (creation_date, change_date, sequence, id, state, max_password_attempts, show_failure, is_default, resource_owner, instance_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
expectedStmt: "INSERT INTO projections.lockout_policies3 (creation_date, change_date, sequence, id, state, max_password_attempts, max_otp_attempts, show_failure, is_default, resource_owner, instance_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
@@ -49,6 +50,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
"agg-id",
|
||||
domain.PolicyStateActive,
|
||||
uint64(10),
|
||||
uint64(10),
|
||||
true,
|
||||
false,
|
||||
"ro-id",
|
||||
@@ -69,6 +71,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"maxPasswordAttempts": 10,
|
||||
"maxOTPAttempts": 10,
|
||||
"showLockOutFailures": true
|
||||
}`),
|
||||
), org.LockoutPolicyChangedEventMapper),
|
||||
@@ -79,11 +82,12 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.lockout_policies2 SET (change_date, sequence, max_password_attempts, show_failure) = ($1, $2, $3, $4) WHERE (id = $5) AND (instance_id = $6)",
|
||||
expectedStmt: "UPDATE projections.lockout_policies3 SET (change_date, sequence, max_password_attempts, max_otp_attempts, show_failure) = ($1, $2, $3, $4, $5) WHERE (id = $6) AND (instance_id = $7)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
uint64(10),
|
||||
uint64(10),
|
||||
true,
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
@@ -110,7 +114,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM projections.lockout_policies2 WHERE (id = $1) AND (instance_id = $2)",
|
||||
expectedStmt: "DELETE FROM projections.lockout_policies3 WHERE (id = $1) AND (instance_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
@@ -137,7 +141,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM projections.lockout_policies2 WHERE (instance_id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.lockout_policies3 WHERE (instance_id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
@@ -156,6 +160,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"maxPasswordAttempts": 10,
|
||||
"maxOTPAttempts": 10,
|
||||
"showLockOutFailures": true
|
||||
}`),
|
||||
), instance.LockoutPolicyAddedEventMapper),
|
||||
@@ -166,7 +171,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.lockout_policies2 (creation_date, change_date, sequence, id, state, max_password_attempts, show_failure, is_default, resource_owner, instance_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
expectedStmt: "INSERT INTO projections.lockout_policies3 (creation_date, change_date, sequence, id, state, max_password_attempts, max_otp_attempts, show_failure, is_default, resource_owner, instance_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
@@ -174,6 +179,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
"agg-id",
|
||||
domain.PolicyStateActive,
|
||||
uint64(10),
|
||||
uint64(10),
|
||||
true,
|
||||
true,
|
||||
"ro-id",
|
||||
@@ -194,6 +200,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"maxPasswordAttempts": 10,
|
||||
"maxOTPAttempts": 10,
|
||||
"showLockOutFailures": true
|
||||
}`),
|
||||
), instance.LockoutPolicyChangedEventMapper),
|
||||
@@ -204,11 +211,12 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.lockout_policies2 SET (change_date, sequence, max_password_attempts, show_failure) = ($1, $2, $3, $4) WHERE (id = $5) AND (instance_id = $6)",
|
||||
expectedStmt: "UPDATE projections.lockout_policies3 SET (change_date, sequence, max_password_attempts, max_otp_attempts, show_failure) = ($1, $2, $3, $4, $5) WHERE (id = $6) AND (instance_id = $7)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
uint64(10),
|
||||
uint64(10),
|
||||
true,
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
@@ -235,7 +243,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM projections.lockout_policies2 WHERE (instance_id = $1) AND (resource_owner = $2)",
|
||||
expectedStmt: "DELETE FROM projections.lockout_policies3 WHERE (instance_id = $1) AND (resource_owner = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"instance-id",
|
||||
"agg-id",
|
||||
|
Reference in New Issue
Block a user