Skip to content

Commit

Permalink
modified: executor/showtest/show_test.go
Browse files Browse the repository at this point in the history
	modified:   executor/simple.go
	modified:   session/bootstrap.go
	modified:   sessionctx/variable/tidb_vars.go
  • Loading branch information
keeplearning20221 committed Dec 2, 2022
1 parent 6f10ebf commit 53eac1e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions executor/showtest/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ func TestShowCreateUser(t *testing.T) {
tk1.MustQuery("show create user current_user").
Check(testkit.Rows("CREATE USER 'check_priv'@'127.0.0.1' IDENTIFIED WITH 'mysql_native_password' AS '' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY DEFALUT PASSWORD REUSE INTERVAL DEFALUT"))

// Creating users with `IDENTIFIED WITH 'caching_sha2_password'`
// Creating users with `IDENTIFIED WITH 'caching_sha2_password'`.
tk.MustExec("CREATE USER 'sha_test'@'%' IDENTIFIED WITH 'caching_sha2_password' BY 'temp_passwd'")

// Compare only the start of the output as the salt changes every time.
Expand All @@ -1110,24 +1110,24 @@ func TestShowCreateUser(t *testing.T) {
rows = tk.MustQuery("SHOW CREATE USER 'sock2'@'%'")
require.Equal(t, "CREATE USER 'sock2'@'%' IDENTIFIED WITH 'auth_socket' AS 'sock3' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY DEFALUT PASSWORD REUSE INTERVAL DEFALUT", rows.Rows()[0][0].(string))

// Test ACCOUNT LOCK/UNLOCK
// Test ACCOUNT LOCK/UNLOCK.
tk.MustExec("CREATE USER 'lockness'@'%' IDENTIFIED BY 'monster' ACCOUNT LOCK")
rows = tk.MustQuery("SHOW CREATE USER 'lockness'@'%'")
require.Equal(t, "CREATE USER 'lockness'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*BC05309E7FE12AFD4EBB9FFE7E488A6320F12FF3' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT LOCK PASSWORD HISTORY DEFALUT PASSWORD REUSE INTERVAL DEFALUT", rows.Rows()[0][0].(string))

// Test COMMENT and ATTRIBUTE
// Test COMMENT and ATTRIBUTE.
tk.MustExec("CREATE USER commentUser COMMENT '1234'")
tk.MustQuery("SHOW CREATE USER commentUser").Check(testkit.Rows(`CREATE USER 'commentUser'@'%' IDENTIFIED WITH 'mysql_native_password' AS '' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK ATTRIBUTE {"comment": "1234"} PASSWORD HISTORY DEFALUT PASSWORD REUSE INTERVAL DEFALUT`))
tk.MustExec(`CREATE USER attributeUser attribute '{"name": "Tom", "age": 19}'`)
tk.MustQuery("SHOW CREATE USER attributeUser").Check(testkit.Rows(`CREATE USER 'attributeUser'@'%' IDENTIFIED WITH 'mysql_native_password' AS '' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK ATTRIBUTE {"age": 19, "name": "Tom"} PASSWORD HISTORY DEFALUT PASSWORD REUSE INTERVAL DEFALUT`))

// Creating users with 'IDENTIFIED WITH 'tidb_auth_token''
// Creating users with IDENTIFIED WITH 'tidb_auth_token'.
tk.MustExec(`CREATE USER 'token_user'@'%' IDENTIFIED WITH 'tidb_auth_token' ATTRIBUTE '{"email": "[email protected]"}'`)
tk.MustQuery("SHOW CREATE USER token_user").Check(testkit.Rows(`CREATE USER 'token_user'@'%' IDENTIFIED WITH 'tidb_auth_token' AS '' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK ATTRIBUTE {"email": "[email protected]"} PASSWORD HISTORY DEFALUT PASSWORD REUSE INTERVAL DEFALUT`))
tk.MustExec(`ALTER USER 'token_user'@'%' REQUIRE token_issuer 'issuer-ABC'`)
tk.MustQuery("SHOW CREATE USER token_user").Check(testkit.Rows(`CREATE USER 'token_user'@'%' IDENTIFIED WITH 'tidb_auth_token' AS '' REQUIRE NONE token_issuer issuer-ABC PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK ATTRIBUTE {"email": "[email protected]"} PASSWORD HISTORY DEFALUT PASSWORD REUSE INTERVAL DEFALUT`))

// create users with password reuse
// create users with password reuse.
tk.MustExec(`CREATE USER 'reuse_user'@'%' IDENTIFIED WITH 'tidb_auth_token' PASSWORD HISTORY 5 PASSWORD REUSE INTERVAL 3 DAY`)
tk.MustQuery("SHOW CREATE USER reuse_user").Check(testkit.Rows(`CREATE USER 'reuse_user'@'%' IDENTIFIED WITH 'tidb_auth_token' AS '' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY 5 PASSWORD REUSE INTERVAL 3 DAY`))
tk.MustExec(`ALTER USER 'reuse_user'@'%' PASSWORD HISTORY 50`)
Expand Down
14 changes: 7 additions & 7 deletions executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ func (e *baseExecutor) releaseSysSession(ctx context.Context, sctx sessionctx.Co
sysSessionPool.Put(sctx.(pools.Resource))
}

// clearSysSession close the session does not return the session
// Since the environment variables in the session are changed, the session object is not returned
// clearSysSession close the session does not return the session.
// Since the environment variables in the session are changed, the session object is not returned.
func clearSysSession(ctx context.Context, sctx sessionctx.Context) {
if sctx == nil {
return
Expand Down Expand Up @@ -1298,12 +1298,12 @@ func passwordVerification(ctx context.Context, sqlExecutor sqlexec.SQLExecutor,
}

func checkPasswordReusePolicy(ctx context.Context, sqlExecutor sqlexec.SQLExecutor, userDetail *userInfo, sctx sessionctx.Context) error {
// read password reuse info from mysql.user and global variables
// read password reuse info from mysql.user and global variables.
passwdReuseInfo, err := getUserPasswordLimit(ctx, sqlExecutor, userDetail.user, userDetail.host, userDetail.pLI)
if err != nil {
return err
}
// check whether password can be used
// check whether password can be used.
res, maxDelNum, err := passwordVerification(ctx, sqlExecutor, userDetail, passwdReuseInfo, sctx)
if err != nil {
return err
Expand Down Expand Up @@ -1736,7 +1736,7 @@ func (e *SimpleExec) executeRenameUser(s *ast.RenameUserStmt) error {
break
}

// rename passwordhistory from PasswordHistoryTable
// rename passwordhistory from PasswordHistoryTable.
if err = renameUserHostInSystemTable(sqlExecutor, mysql.PasswordHistoryTable, "USER", "HOST", userToUser); err != nil {
failedUser = oldUser.String() + " TO " + newUser.String() + " " + mysql.PasswordHistoryTable + " error"
break
Expand Down Expand Up @@ -1846,7 +1846,7 @@ func (e *SimpleExec) executeDropUser(ctx context.Context, s *ast.DropUserStmt) e
break
}

// delete password history from mysql.password_history
// delete password history from mysql.password_history.
sql.Reset()
sqlexec.MustFormatSQL(sql, `DELETE FROM %n.%n WHERE Host = %? and User = %?;`, mysql.SystemDB, mysql.PasswordHistoryTable, strings.ToLower(user.Hostname), user.Username)
if _, err = sqlExecutor.ExecuteInternal(internalCtx, sql.String()); err != nil {
Expand Down Expand Up @@ -2066,7 +2066,7 @@ func (e *SimpleExec) executeSetPwd(ctx context.Context, s *ast.SetPwdStmt) error
pwd = auth.EncodePassword(s.Password)
}

// for Support Password Reuse Policy
// for Support Password Reuse Policy.
passwdlockinfo :=
&passwordLockInfo{lockAccount: "", passwordHistory: notSpecified,
passwordReuseInterval: notSpecified, passwordHistoryFlag: false,
Expand Down
6 changes: 3 additions & 3 deletions session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ const (
version bigint(64) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (table_id));`

// CreatePasswordHistory is a table save history passwd
// CreatePasswordHistory is a table save history passwd.
CreatePasswordHistory = `CREATE TABLE IF NOT EXISTS mysql.password_history (
Host char(255) NOT NULL DEFAULT '',
User char(32) NOT NULL DEFAULT '',
Expand Down Expand Up @@ -703,7 +703,7 @@ const (
// version105 insert "tidb_cost_model_version|1" to mysql.GLOBAL_VARIABLES if there is no tidb_cost_model_version.
// This will only happens when we upgrade a cluster before 6.0.
version105 = 105
// version106 add mysql.password_history, and Password_reuse_history, Password_reuse_time into mysql.user
// version106 add mysql.password_history, and Password_reuse_history, Password_reuse_time into mysql.user.
version106 = 106
)

Expand Down Expand Up @@ -2180,7 +2180,7 @@ func doDDLWorks(s Session) {
mustExecute(s, "CREATE DATABASE IF NOT EXISTS %n", mysql.SystemDB)
// Create user table.
mustExecute(s, CreateUserTable)
// Create password history
// Create password history.
mustExecute(s, CreatePasswordHistory)
// Create privilege tables.
mustExecute(s, CreateGlobalPrivTable)
Expand Down
4 changes: 2 additions & 2 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,9 +868,9 @@ const (
TiDBGOGCTunerThreshold = "tidb_gogc_tuner_threshold"
// TiDBExternalTS is the ts to read through when the `TiDBEnableExternalTsRead` is on
TiDBExternalTS = "tidb_external_ts"
// PasswordReuseHistory limit a few passwords to reuse
// PasswordReuseHistory limit a few passwords to reuse.
PasswordReuseHistory = "password_history"
// PasswordReuseTime limit how long passwords can be reused
// PasswordReuseTime limit how long passwords can be reused.
PasswordReuseTime = "password_reuse_interval"
)

Expand Down

0 comments on commit 53eac1e

Please sign in to comment.