From 51a9f735c70e2c919bc125706b440122bb065e34 Mon Sep 17 00:00:00 2001 From: cbcwestwolf <1004626265@qq.com> Date: Thu, 14 Nov 2024 22:39:28 +0800 Subject: [PATCH] update --- pkg/executor/simple.go | 1 - pkg/parser/ast/misc.go | 1 + .../integrationtest/r/executor/simple.result | 42 ++++++++++++++----- tests/integrationtest/t/executor/simple.test | 30 ++++++++++--- 4 files changed, 58 insertions(+), 16 deletions(-) diff --git a/pkg/executor/simple.go b/pkg/executor/simple.go index 270e31bfec12e..89449b3f22e23 100644 --- a/pkg/executor/simple.go +++ b/pkg/executor/simple.go @@ -2521,7 +2521,6 @@ func (e *SimpleExec) executeSetPwd(ctx context.Context, s *ast.SetPwdStmt) error } authPlugins := extensions.GetAuthPlugins() var pwd string - // FIXME switch authplugin { case mysql.AuthCachingSha2Password, mysql.AuthTiDBSM3Password: pwd = auth.NewHashPassword(s.Password, authplugin) diff --git a/pkg/parser/ast/misc.go b/pkg/parser/ast/misc.go index abd4b8255136e..a36a961a5bb4a 100644 --- a/pkg/parser/ast/misc.go +++ b/pkg/parser/ast/misc.go @@ -1387,6 +1387,7 @@ type UserSpec struct { AuthOpt *AuthOption IsRole bool + // DefaultAuthPlugin is used to store the values of default_authentication_plugin DefaultAuthPlugin string } diff --git a/tests/integrationtest/r/executor/simple.result b/tests/integrationtest/r/executor/simple.result index ca40620c61b44..85e448e705336 100644 --- a/tests/integrationtest/r/executor/simple.result +++ b/tests/integrationtest/r/executor/simple.result @@ -495,20 +495,42 @@ CREATE USER 'default_sha2_user'@'%' IDENTIFIED WITH 'tidb_sm3_password' AS '' RE select plugin from mysql.user where user = 'default_sha2_user'; plugin tidb_sm3_password -alter user default_sha2_user identified with 'authentication_ldap_simple'; -show create user default_sha2_user; -CREATE USER for default_sha2_user@% -CREATE USER 'default_sha2_user'@'%' IDENTIFIED WITH 'authentication_ldap_simple' AS '' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT +drop user default_sha2_user; +create user default_sha2_user identified by '1234'; +set password for default_sha2_user = '12345'; +alter user default_sha2_user identified by '123456'; select plugin from mysql.user where user = 'default_sha2_user'; plugin -authentication_ldap_simple -alter user default_sha2_user identified with 'authentication_ldap_sasl'; -show create user default_sha2_user; -CREATE USER for default_sha2_user@% -CREATE USER 'default_sha2_user'@'%' IDENTIFIED WITH 'authentication_ldap_sasl' AS '' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT +caching_sha2_password +alter user default_sha2_user identified with 'mysql_native_password' by '123456'; select plugin from mysql.user where user = 'default_sha2_user'; plugin -authentication_ldap_sasl +mysql_native_password +alter user default_sha2_user identified with 'caching_sha2_password'; +select plugin from mysql.user where user = 'default_sha2_user'; +plugin +caching_sha2_password +set sql_mode = ''; +select @@sql_mode; +@@sql_mode + +select user, host, plugin from mysql.user where user = 'non_exist_user'; +user host plugin +grant select on test.* to non_exist_user; +select user, host, plugin from mysql.user where user = 'non_exist_user'; +user host plugin +non_exist_user % caching_sha2_password +set @@sql_mode = default; +alter user non_exist_user identified with 'mysql_native_password'; +show create user non_exist_user; +CREATE USER for non_exist_user@% +CREATE USER 'non_exist_user'@'%' IDENTIFIED WITH 'mysql_native_password' AS '' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT +update mysql.user set plugin = '' where user = 'non_exist_user'; +flush privileges; +show create user non_exist_user; +CREATE USER for non_exist_user@% +CREATE USER 'non_exist_user'@'%' IDENTIFIED WITH 'caching_sha2_password' AS '' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT +drop user non_exist_user; drop user default_sm3_user; drop user default_sha2_user; drop user native_plugin_user; diff --git a/tests/integrationtest/t/executor/simple.test b/tests/integrationtest/t/executor/simple.test index 992b9af49e175..cad3035023392 100644 --- a/tests/integrationtest/t/executor/simple.test +++ b/tests/integrationtest/t/executor/simple.test @@ -516,15 +516,35 @@ select plugin from mysql.user where user = 'default_sha2_role'; alter user default_sha2_user identified with 'tidb_sm3_password'; show create user default_sha2_user; select plugin from mysql.user where user = 'default_sha2_user'; +drop user default_sha2_user; -alter user default_sha2_user identified with 'authentication_ldap_simple'; -show create user default_sha2_user; +create user default_sha2_user identified by '1234'; +set password for default_sha2_user = '12345'; +alter user default_sha2_user identified by '123456'; select plugin from mysql.user where user = 'default_sha2_user'; - -alter user default_sha2_user identified with 'authentication_ldap_sasl'; -show create user default_sha2_user; +alter user default_sha2_user identified with 'mysql_native_password' by '123456'; +select plugin from mysql.user where user = 'default_sha2_user'; +alter user default_sha2_user identified with 'caching_sha2_password'; select plugin from mysql.user where user = 'default_sha2_user'; +# test GRANT create default user + +set sql_mode = ''; +select @@sql_mode; +select user, host, plugin from mysql.user where user = 'non_exist_user'; +grant select on test.* to non_exist_user; +select user, host, plugin from mysql.user where user = 'non_exist_user'; +set @@sql_mode = default; + +# test SHOW CREATE USER + +alter user non_exist_user identified with 'mysql_native_password'; +show create user non_exist_user; +update mysql.user set plugin = '' where user = 'non_exist_user'; +flush privileges; +show create user non_exist_user; + +drop user non_exist_user; drop user default_sm3_user; drop user default_sha2_user; drop user native_plugin_user;