From 7cc1376f96ceb99df178d01db1210f9b78088ae9 Mon Sep 17 00:00:00 2001 From: James Cor Date: Thu, 19 Sep 2024 13:03:54 -0700 Subject: [PATCH 1/7] problems with declaring variables --- enginetest/queries/script_queries.go | 31 +++++++ sql/expression/function/hash.go | 124 +++++++++++++++++++++++++++ sql/expression/function/hash_test.go | 45 ++++++++++ sql/expression/function/registry.go | 1 + sql/variables/system_variables.go | 32 +++++++ 5 files changed, 233 insertions(+) diff --git a/enginetest/queries/script_queries.go b/enginetest/queries/script_queries.go index 0627bf676c..6d34c5f469 100644 --- a/enginetest/queries/script_queries.go +++ b/enginetest/queries/script_queries.go @@ -7298,6 +7298,37 @@ where }, }, }, + { + Name: "validate_password_strength alter length", + SetUpScript: []string{ + "set @orig = @@global.validate_password.length", + "set @@global.validate_password.length = 0", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "select validate_password_strength('')", + Expected: []sql.Row{ + {0}, + }, + }, + { + Query: "select validate_password_strength('123')", + Expected: []sql.Row{ + {0}, + }, + }, + { + Query: "select validate_password_strength('1234')", + Expected: []sql.Row{ + {50}, + }, + }, + { + SkipResultsCheck: true, + Query: "set @@global.validate_password.length = @orig", + }, + }, + }, } var SpatialScriptTests = []ScriptTest{ diff --git a/sql/expression/function/hash.go b/sql/expression/function/hash.go index 8dc21dfd19..bfec453f3e 100644 --- a/sql/expression/function/hash.go +++ b/sql/expression/function/hash.go @@ -26,6 +26,7 @@ import ( "fmt" "hash" "io" + "unicode" "github.com/dolthub/go-mysql-server/sql" "github.com/dolthub/go-mysql-server/sql/expression" @@ -471,3 +472,126 @@ func (f *UncompressedLength) WithChildren(children ...sql.Expression) (sql.Expre } return NewUncompressedLength(children[0]), nil } + +// ValidatePasswordStrength function returns an integer to indicate how strong the password is. +// https://dev.mysql.com/doc/refman/8.4/en/validate-password.html +type ValidatePasswordStrength struct { + *UnaryFunc +} + +const minPasswordLength = 4 + +var _ sql.FunctionExpression = (*ValidatePasswordStrength)(nil) +var _ sql.CollationCoercible = (*ValidatePasswordStrength)(nil) + +// NewValidatePasswordStrength returns a new ValidatePasswordStrength function expression +func NewValidatePasswordStrength(arg sql.Expression) sql.Expression { + return &ValidatePasswordStrength{NewUnaryFunc(arg, "ValidatePasswordStrength", types.Uint32)} +} + +// Description implements sql.FunctionExpression +func (f *ValidatePasswordStrength) Description() string { + return "returns an integer to indicate how strong the password is." +} + +func (f *ValidatePasswordStrength) Type() sql.Type { + return types.Int32 +} + +// CollationCoercibility implements the interface sql.CollationCoercible. +func (*ValidatePasswordStrength) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) { + return ctx.GetCollation(), 4 +} + +// Eval implements sql.Expression +func (f *ValidatePasswordStrength) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { + arg, err := f.EvalChild(ctx, row) + if err != nil { + return nil, err + } + if arg == nil { + return nil, nil + } + + val, _, err := types.LongText.Convert(arg) + if err != nil { + return nil, nil + } + password := val.(string) + strength := 0 + if len(password) < minPasswordLength { + return strength, nil + } + strength += 25 + + // Requirements for LOW password strength + passLen, err := ctx.GetSessionVariable(ctx, "validate_password_length") + if err != nil { + return nil, err + } + passLenInt, ok := types.CoalesceInt(passLen) + if !ok { + return nil, fmt.Errorf("invalid value for validate_password_length: %v", passLen) + } + if len(password) < passLenInt { + return strength, nil + } + strength += 25 + + // Requirements for MEDIUM password strength + numCount, err := ctx.GetSessionVariable(ctx, "validate_password_number_count") + if err != nil { + return nil, err + } + numCountInt, ok := types.CoalesceInt(numCount) + if !ok { + return nil, fmt.Errorf("invalid value for validate_password.number_count: %v", numCount) + } + mixCaseCount, err := ctx.GetSessionVariable(ctx, "validate_password_mixed_case_count") + if err != nil { + return nil, err + } + mixCaseCountInt, ok := types.CoalesceInt(mixCaseCount) + if !ok { + return nil, fmt.Errorf("invalid value for validate_password.mixed_case_count: %v", mixCaseCount) + } + lowerCount, upperCount := mixCaseCountInt, mixCaseCountInt + specialCharCount, err := ctx.GetSessionVariable(ctx, "validate_password_special_char_count") + if err != nil { + return nil, err + } + specialCharCountInt, ok := types.CoalesceInt(specialCharCount) + if !ok { + return nil, fmt.Errorf("invalid value for validate_password.special_char_count: %v", specialCharCount) + } + for _, c := range password { + if unicode.IsNumber(c) { + numCountInt-- + } else if unicode.IsUpper(c) { + upperCount-- + } else if unicode.IsLower(c) { + lowerCount-- + } else { + specialCharCountInt-- + } + } + if numCountInt > 0 || upperCount > 0 || lowerCount > 0 || specialCharCountInt > 0 { + return strength, nil + } + strength += 25 + + // Requirements for STRONG password strength + // TODO: support dictionary file substring matching + strength += 25 + + return strength, nil +} + +// WithChildren implements sql.Expression +func (f *ValidatePasswordStrength) WithChildren(children ...sql.Expression) (sql.Expression, error) { + if len(children) != 1 { + return nil, sql.ErrInvalidChildrenNumber.New(f, len(children), 1) + } + return NewValidatePasswordStrength(children[0]), nil +} + diff --git a/sql/expression/function/hash_test.go b/sql/expression/function/hash_test.go index 66570e9846..441cf82293 100644 --- a/sql/expression/function/hash_test.go +++ b/sql/expression/function/hash_test.go @@ -437,3 +437,48 @@ func TestUncompressedLength(t *testing.T) { }) } } + +func TestValidatePasswordStrength(t *testing.T) { + tests := []struct { + val sql.Expression + exp interface{} + }{ + { + val: expression.NewLiteral(nil, types.Null), + exp: nil, + }, + { + val: expression.NewLiteral(int64(1), types.Int64), + exp: 0, + }, + { + val: expression.NewLiteral("1", types.Text), + exp: 0, + }, + { + val: expression.NewLiteral("", types.Text), + exp: 0, + }, + { + val: expression.NewLiteral("weak", types.Text), + exp: 25, + }, + { + val: expression.NewLiteral("lessweak$_@123", types.Text), + exp: 50, + }, + { + val: expression.NewLiteral("N0Tweak$_@123!", types.Text), + exp: 100, + }, + } + + for _, test := range tests { + f := NewValidatePasswordStrength(test.val) + t.Run(fmt.Sprintf(f.String()), func(t *testing.T) { + res, err := f.Eval(sql.NewEmptyContext(), nil) + require.NoError(t, err) + require.Equal(t, test.exp, res) + }) + } +} diff --git a/sql/expression/function/registry.go b/sql/expression/function/registry.go index fd59f0e94a..e91f8bcc3c 100644 --- a/sql/expression/function/registry.go +++ b/sql/expression/function/registry.go @@ -308,6 +308,7 @@ var BuiltIns = []sql.Function{ sql.FunctionN{Name: "uuid_to_bin", Fn: NewUUIDToBin}, sql.FunctionN{Name: "week", Fn: NewWeek}, sql.Function1{Name: "values", Fn: NewValues}, + sql.Function1{Name: "validate_password_strength", Fn: NewValidatePasswordStrength}, sql.Function1{Name: "weekday", Fn: NewWeekday}, sql.Function1{Name: "weekofyear", Fn: NewWeekOfYear}, sql.Function1{Name: "year", Fn: NewYear}, diff --git a/sql/variables/system_variables.go b/sql/variables/system_variables.go index 73285bcffd..7613f13b68 100644 --- a/sql/variables/system_variables.go +++ b/sql/variables/system_variables.go @@ -2887,6 +2887,38 @@ var systemVars = map[string]sql.SystemVariable{ Type: types.NewSystemEnumType("use_secondary_engine", "OFF", "ON", "FORCED"), Default: "ON", }, + "validate_password.length": &sql.MysqlSystemVariable{ + Name: "validate_password.length", + Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global), + Dynamic: false, + SetVarHintApplies: false, + Type: types.NewSystemIntType("validate_password.length", 0, 2147483647, false), + Default: int8(8), + }, + "validate_password_number_count": &sql.MysqlSystemVariable{ + Name: "validate_password_number_count", + Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global), + Dynamic: false, + SetVarHintApplies: false, + Type: types.NewSystemIntType("validate_password.number_count", 0, 2147483647, false), + Default: int8(1), + }, + "validate_password_mixed_case_count": &sql.MysqlSystemVariable{ + Name: "validate_password_mixed_case_count", + Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global), + Dynamic: false, + SetVarHintApplies: false, + Type: types.NewSystemIntType("validate_password.mixed_case_count", 0, 2147483647, false), + Default: int8(1), + }, + "validate_password_special_char_count": &sql.MysqlSystemVariable{ + Name: "validate_password_special_char_count", + Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global), + Dynamic: false, + SetVarHintApplies: false, + Type: types.NewSystemIntType("validate_password.special_char_count", 0, 2147483647, false), + Default: int8(1), + }, "validate_user_plugins": &sql.MysqlSystemVariable{ Name: "validate_user_plugins", Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global), From 41fb6bcfc3c4fd826ea475cd6dcede82c72968c5 Mon Sep 17 00:00:00 2001 From: James Cor Date: Thu, 19 Sep 2024 14:29:10 -0700 Subject: [PATCH 2/7] fix --- sql/expression/function/hash.go | 8 ++++---- sql/variables/system_variables.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sql/expression/function/hash.go b/sql/expression/function/hash.go index bfec453f3e..1edef084b0 100644 --- a/sql/expression/function/hash.go +++ b/sql/expression/function/hash.go @@ -525,13 +525,13 @@ func (f *ValidatePasswordStrength) Eval(ctx *sql.Context, row sql.Row) (interfac strength += 25 // Requirements for LOW password strength - passLen, err := ctx.GetSessionVariable(ctx, "validate_password_length") + passLen, err := ctx.GetSessionVariable(ctx, "validate_password.length") if err != nil { return nil, err } passLenInt, ok := types.CoalesceInt(passLen) if !ok { - return nil, fmt.Errorf("invalid value for validate_password_length: %v", passLen) + return nil, fmt.Errorf("invalid value for validate_password.length: %v", passLen) } if len(password) < passLenInt { return strength, nil @@ -539,7 +539,7 @@ func (f *ValidatePasswordStrength) Eval(ctx *sql.Context, row sql.Row) (interfac strength += 25 // Requirements for MEDIUM password strength - numCount, err := ctx.GetSessionVariable(ctx, "validate_password_number_count") + numCount, err := ctx.GetSessionVariable(ctx, "validate_password.number_count") if err != nil { return nil, err } @@ -556,7 +556,7 @@ func (f *ValidatePasswordStrength) Eval(ctx *sql.Context, row sql.Row) (interfac return nil, fmt.Errorf("invalid value for validate_password.mixed_case_count: %v", mixCaseCount) } lowerCount, upperCount := mixCaseCountInt, mixCaseCountInt - specialCharCount, err := ctx.GetSessionVariable(ctx, "validate_password_special_char_count") + specialCharCount, err := ctx.GetSessionVariable(ctx, "validate_password.special_char_count") if err != nil { return nil, err } diff --git a/sql/variables/system_variables.go b/sql/variables/system_variables.go index 7613f13b68..a2f0a3d769 100644 --- a/sql/variables/system_variables.go +++ b/sql/variables/system_variables.go @@ -2890,7 +2890,7 @@ var systemVars = map[string]sql.SystemVariable{ "validate_password.length": &sql.MysqlSystemVariable{ Name: "validate_password.length", Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global), - Dynamic: false, + Dynamic: true, SetVarHintApplies: false, Type: types.NewSystemIntType("validate_password.length", 0, 2147483647, false), Default: int8(8), @@ -2898,7 +2898,7 @@ var systemVars = map[string]sql.SystemVariable{ "validate_password_number_count": &sql.MysqlSystemVariable{ Name: "validate_password_number_count", Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global), - Dynamic: false, + Dynamic: true, SetVarHintApplies: false, Type: types.NewSystemIntType("validate_password.number_count", 0, 2147483647, false), Default: int8(1), @@ -2906,7 +2906,7 @@ var systemVars = map[string]sql.SystemVariable{ "validate_password_mixed_case_count": &sql.MysqlSystemVariable{ Name: "validate_password_mixed_case_count", Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global), - Dynamic: false, + Dynamic: true, SetVarHintApplies: false, Type: types.NewSystemIntType("validate_password.mixed_case_count", 0, 2147483647, false), Default: int8(1), @@ -2914,7 +2914,7 @@ var systemVars = map[string]sql.SystemVariable{ "validate_password_special_char_count": &sql.MysqlSystemVariable{ Name: "validate_password_special_char_count", Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global), - Dynamic: false, + Dynamic: true, SetVarHintApplies: false, Type: types.NewSystemIntType("validate_password.special_char_count", 0, 2147483647, false), Default: int8(1), From 71582a152baa2191b8f109eacf0fa50718374ce1 Mon Sep 17 00:00:00 2001 From: James Cor Date: Thu, 19 Sep 2024 14:53:07 -0700 Subject: [PATCH 3/7] bump --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c7b071a52c..85e899fc0b 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662 github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 - github.com/dolthub/vitess v0.0.0-20240916204416-9d4d4a09b1d9 + github.com/dolthub/vitess v0.0.0-20240919212847-96ea5aac0c9a github.com/go-kit/kit v0.10.0 github.com/go-sql-driver/mysql v1.7.2-0.20231213112541-0004702b931d github.com/gocraft/dbr/v2 v2.7.2 diff --git a/go.sum b/go.sum index de8c63f855..a3f8436716 100644 --- a/go.sum +++ b/go.sum @@ -58,8 +58,8 @@ github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 h1:bMGS25NWAGTE github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71/go.mod h1:2/2zjLQ/JOOSbbSboojeg+cAwcRV0fDLzIiWch/lhqI= github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9XGFa6q5Ap4Z/OhNkAMBaK5YeuEzwJt+NZdhiE= github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY= -github.com/dolthub/vitess v0.0.0-20240916204416-9d4d4a09b1d9 h1:2My8cED5m5/sFay7U4bvLxpECJccKj0cEKCqEA+63yU= -github.com/dolthub/vitess v0.0.0-20240916204416-9d4d4a09b1d9/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM= +github.com/dolthub/vitess v0.0.0-20240919212847-96ea5aac0c9a h1:mec8AiILmZC9eX0zRQpfN/XfTfsiEZESjrNbw/wbW+k= +github.com/dolthub/vitess v0.0.0-20240919212847-96ea5aac0c9a/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= From 9bd725c9ea9fa9b7d19a6836bffc15a0417a725e Mon Sep 17 00:00:00 2001 From: jycor Date: Thu, 19 Sep 2024 21:55:46 +0000 Subject: [PATCH 4/7] [ga-format-pr] Run ./format_repo.sh to fix formatting --- enginetest/queries/script_queries.go | 2 +- sql/expression/function/hash.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/enginetest/queries/script_queries.go b/enginetest/queries/script_queries.go index 6d34c5f469..638b50904c 100644 --- a/enginetest/queries/script_queries.go +++ b/enginetest/queries/script_queries.go @@ -7325,7 +7325,7 @@ where }, { SkipResultsCheck: true, - Query: "set @@global.validate_password.length = @orig", + Query: "set @@global.validate_password.length = @orig", }, }, }, diff --git a/sql/expression/function/hash.go b/sql/expression/function/hash.go index 1edef084b0..ac0af588a9 100644 --- a/sql/expression/function/hash.go +++ b/sql/expression/function/hash.go @@ -594,4 +594,3 @@ func (f *ValidatePasswordStrength) WithChildren(children ...sql.Expression) (sql } return NewValidatePasswordStrength(children[0]), nil } - From 1c63875bf9c02620ac5c98f440f60e9bdbb786b3 Mon Sep 17 00:00:00 2001 From: James Cor Date: Thu, 19 Sep 2024 15:28:14 -0700 Subject: [PATCH 5/7] fix and more tests --- enginetest/queries/script_queries.go | 121 ++++++++++++++++++++++++++- sql/expression/function/hash.go | 22 ++--- sql/variables/system_variables.go | 12 +-- 3 files changed, 137 insertions(+), 18 deletions(-) diff --git a/enginetest/queries/script_queries.go b/enginetest/queries/script_queries.go index 638b50904c..24cfe41523 100644 --- a/enginetest/queries/script_queries.go +++ b/enginetest/queries/script_queries.go @@ -7299,7 +7299,7 @@ where }, }, { - Name: "validate_password_strength alter length", + Name: "validate_password_strength and validate_password.length", SetUpScript: []string{ "set @orig = @@global.validate_password.length", "set @@global.validate_password.length = 0", @@ -7323,12 +7323,131 @@ where {50}, }, }, + { + SkipResultsCheck: true, + Query: "set @@global.validate_password.length = 1000", + }, + { + Query: "select validate_password_strength('ABCabc123!@!#')", + Expected: []sql.Row{ + {25}, + }, + }, + { + Query: "set @@session.validate_password.length = 123", + ExpectedErrStr: "Variable 'validate_password.length' is a GLOBAL variable and should be set with SET GLOBAL", + }, { SkipResultsCheck: true, Query: "set @@global.validate_password.length = @orig", }, }, }, + { + Name: "validate_password_strength and validate_password.number_count", + SetUpScript: []string{ + "set @orig = @@global.validate_password.number_count", + "set @@global.validate_password.number_count = 0", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "select validate_password_strength('ABCabc!@#')", + Expected: []sql.Row{ + {100}, + }, + }, + { + SkipResultsCheck: true, + Query: "set @@global.validate_password.number_count = 1000", + }, + { + Query: "select validate_password_strength('ABCabc!!!!123456789012345678901234567890')", + Expected: []sql.Row{ + {50}, + }, + }, + { + Query: "set @@session.validate_password.number_count = 123", + ExpectedErrStr: "Variable 'validate_password.number_count' is a GLOBAL variable and should be set with SET GLOBAL", + }, + { + SkipResultsCheck: true, + Query: "set @@global.validate_password.number_count = @orig", + }, + }, + }, + { + Name: "validate_password_strength and validate_password.mixed_case_count", + SetUpScript: []string{ + "set @orig = @@global.validate_password.mixed_case_count", + "set @@global.validate_password.mixed_case_count = 0", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "select validate_password_strength('abcabc!@#123')", + Expected: []sql.Row{ + {100}, + }, + }, + { + Query: "select validate_password_strength('ABCABC!@#123')", + Expected: []sql.Row{ + {100}, + }, + }, + { + SkipResultsCheck: true, + Query: "set @@global.validate_password.mixed_case_count = 1000", + }, + { + Query: "select validate_password_strength('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456!?!?!?')", + Expected: []sql.Row{ + {50}, + }, + }, + { + Query: "set @@session.validate_password.mixed_case_count = 123", + ExpectedErrStr: "Variable 'validate_password.mixed_case_count' is a GLOBAL variable and should be set with SET GLOBAL", + }, + { + SkipResultsCheck: true, + Query: "set @@global.validate_password.mixed_case_count = @orig", + }, + }, + }, + { + Name: "validate_password_strength and validate_password.special_char_count", + SetUpScript: []string{ + "set @orig = @@global.validate_password.special_char_count", + "set @@global.validate_password.special_char_count = 0", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "select validate_password_strength('abcABC123')", + Expected: []sql.Row{ + {100}, + }, + }, + { + SkipResultsCheck: true, + Query: "set @@global.validate_password.special_char_count = 1000", + }, + { + Query: "select validate_password_strength('abcABC123!@#$%^&*() ')", + Expected: []sql.Row{ + {50}, + }, + }, + { + Query: "set @@session.validate_password.special_char_count = 123", + ExpectedErrStr: "Variable 'validate_password.special_char_count' is a GLOBAL variable and should be set with SET GLOBAL", + }, + { + SkipResultsCheck: true, + Query: "set @@global.validate_password.special_char_count = @orig", + }, + }, + }, } var SpatialScriptTests = []ScriptTest{ diff --git a/sql/expression/function/hash.go b/sql/expression/function/hash.go index ac0af588a9..abab4363fd 100644 --- a/sql/expression/function/hash.go +++ b/sql/expression/function/hash.go @@ -525,8 +525,8 @@ func (f *ValidatePasswordStrength) Eval(ctx *sql.Context, row sql.Row) (interfac strength += 25 // Requirements for LOW password strength - passLen, err := ctx.GetSessionVariable(ctx, "validate_password.length") - if err != nil { + _, passLen, ok := sql.SystemVariables.GetGlobal("validate_password.length") + if !ok { return nil, err } passLenInt, ok := types.CoalesceInt(passLen) @@ -539,26 +539,26 @@ func (f *ValidatePasswordStrength) Eval(ctx *sql.Context, row sql.Row) (interfac strength += 25 // Requirements for MEDIUM password strength - numCount, err := ctx.GetSessionVariable(ctx, "validate_password.number_count") - if err != nil { - return nil, err + _, numCount, ok := sql.SystemVariables.GetGlobal("validate_password.number_count") + if !ok { + return nil, fmt.Errorf("error: validate_password.number_count variable was not found") } numCountInt, ok := types.CoalesceInt(numCount) if !ok { return nil, fmt.Errorf("invalid value for validate_password.number_count: %v", numCount) } - mixCaseCount, err := ctx.GetSessionVariable(ctx, "validate_password_mixed_case_count") - if err != nil { - return nil, err + _, mixCaseCount, ok := sql.SystemVariables.GetGlobal("validate_password.mixed_case_count") + if !ok { + return nil, fmt.Errorf("error: validate_password.mixed_case_count variable was not found") } mixCaseCountInt, ok := types.CoalesceInt(mixCaseCount) if !ok { return nil, fmt.Errorf("invalid value for validate_password.mixed_case_count: %v", mixCaseCount) } lowerCount, upperCount := mixCaseCountInt, mixCaseCountInt - specialCharCount, err := ctx.GetSessionVariable(ctx, "validate_password.special_char_count") - if err != nil { - return nil, err + _, specialCharCount, ok := sql.SystemVariables.GetGlobal("validate_password.special_char_count") + if !ok { + return nil, fmt.Errorf("error: validate_password.special_char_count variable was not found") } specialCharCountInt, ok := types.CoalesceInt(specialCharCount) if !ok { diff --git a/sql/variables/system_variables.go b/sql/variables/system_variables.go index a2f0a3d769..0df108d8bb 100644 --- a/sql/variables/system_variables.go +++ b/sql/variables/system_variables.go @@ -2895,24 +2895,24 @@ var systemVars = map[string]sql.SystemVariable{ Type: types.NewSystemIntType("validate_password.length", 0, 2147483647, false), Default: int8(8), }, - "validate_password_number_count": &sql.MysqlSystemVariable{ - Name: "validate_password_number_count", + "validate_password.number_count": &sql.MysqlSystemVariable{ + Name: "validate_password.number_count", Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global), Dynamic: true, SetVarHintApplies: false, Type: types.NewSystemIntType("validate_password.number_count", 0, 2147483647, false), Default: int8(1), }, - "validate_password_mixed_case_count": &sql.MysqlSystemVariable{ - Name: "validate_password_mixed_case_count", + "validate_password.mixed_case_count": &sql.MysqlSystemVariable{ + Name: "validate_password.mixed_case_count", Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global), Dynamic: true, SetVarHintApplies: false, Type: types.NewSystemIntType("validate_password.mixed_case_count", 0, 2147483647, false), Default: int8(1), }, - "validate_password_special_char_count": &sql.MysqlSystemVariable{ - Name: "validate_password_special_char_count", + "validate_password.special_char_count": &sql.MysqlSystemVariable{ + Name: "validate_password.special_char_count", Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global), Dynamic: true, SetVarHintApplies: false, From 75e327d6e529cbba32ac11fb186cbcb8d074a8a3 Mon Sep 17 00:00:00 2001 From: jycor Date: Thu, 19 Sep 2024 22:29:34 +0000 Subject: [PATCH 6/7] [ga-format-pr] Run ./format_repo.sh to fix formatting --- enginetest/queries/script_queries.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/enginetest/queries/script_queries.go b/enginetest/queries/script_queries.go index 24cfe41523..51f3592a84 100644 --- a/enginetest/queries/script_queries.go +++ b/enginetest/queries/script_queries.go @@ -7325,7 +7325,7 @@ where }, { SkipResultsCheck: true, - Query: "set @@global.validate_password.length = 1000", + Query: "set @@global.validate_password.length = 1000", }, { Query: "select validate_password_strength('ABCabc123!@!#')", @@ -7334,7 +7334,7 @@ where }, }, { - Query: "set @@session.validate_password.length = 123", + Query: "set @@session.validate_password.length = 123", ExpectedErrStr: "Variable 'validate_password.length' is a GLOBAL variable and should be set with SET GLOBAL", }, { @@ -7358,7 +7358,7 @@ where }, { SkipResultsCheck: true, - Query: "set @@global.validate_password.number_count = 1000", + Query: "set @@global.validate_password.number_count = 1000", }, { Query: "select validate_password_strength('ABCabc!!!!123456789012345678901234567890')", @@ -7397,7 +7397,7 @@ where }, { SkipResultsCheck: true, - Query: "set @@global.validate_password.mixed_case_count = 1000", + Query: "set @@global.validate_password.mixed_case_count = 1000", }, { Query: "select validate_password_strength('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456!?!?!?')", @@ -7430,7 +7430,7 @@ where }, { SkipResultsCheck: true, - Query: "set @@global.validate_password.special_char_count = 1000", + Query: "set @@global.validate_password.special_char_count = 1000", }, { Query: "select validate_password_strength('abcABC123!@#$%^&*() ')", From e395c9045eb8369c9c099a3bedaded473f31e7d2 Mon Sep 17 00:00:00 2001 From: James Cor Date: Thu, 19 Sep 2024 16:08:16 -0700 Subject: [PATCH 7/7] bump --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 85e899fc0b..e7a1dcddba 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662 github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 - github.com/dolthub/vitess v0.0.0-20240919212847-96ea5aac0c9a + github.com/dolthub/vitess v0.0.0-20240919225659-2ad81685e772 github.com/go-kit/kit v0.10.0 github.com/go-sql-driver/mysql v1.7.2-0.20231213112541-0004702b931d github.com/gocraft/dbr/v2 v2.7.2 diff --git a/go.sum b/go.sum index a3f8436716..a703549a96 100644 --- a/go.sum +++ b/go.sum @@ -58,8 +58,8 @@ github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 h1:bMGS25NWAGTE github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71/go.mod h1:2/2zjLQ/JOOSbbSboojeg+cAwcRV0fDLzIiWch/lhqI= github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9XGFa6q5Ap4Z/OhNkAMBaK5YeuEzwJt+NZdhiE= github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY= -github.com/dolthub/vitess v0.0.0-20240919212847-96ea5aac0c9a h1:mec8AiILmZC9eX0zRQpfN/XfTfsiEZESjrNbw/wbW+k= -github.com/dolthub/vitess v0.0.0-20240919212847-96ea5aac0c9a/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM= +github.com/dolthub/vitess v0.0.0-20240919225659-2ad81685e772 h1:vDwBX7Lc8DnA8Zk0iRIu6slCw0GIUfYfFlYDYJQw8GQ= +github.com/dolthub/vitess v0.0.0-20240919225659-2ad81685e772/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=