From 5d7d8505cf179cbd4774ee518274f4c1fe6aefd5 Mon Sep 17 00:00:00 2001 From: Yang Keao Date: Sat, 6 May 2023 18:09:56 +0800 Subject: [PATCH] fix test grammar Signed-off-by: Yang Keao --- bindinfo/bind_test.go | 4 +- bindinfo/capture_test.go | 38 +++--- bindinfo/session_handle_test.go | 4 +- ddl/db_cache_test.go | 2 +- ddl/db_test.go | 2 +- ddl/fktest/foreign_key_test.go | 4 +- ddl/sequence_test.go | 10 +- ddl/tiflash_replica_test.go | 2 +- domain/extract_test.go | 2 +- executor/cluster_table_test.go | 14 +- executor/executor_test.go | 4 +- executor/explain_test.go | 4 +- executor/explainfor_test.go | 6 +- executor/grant_test.go | 6 +- executor/infoschema_cluster_table_test.go | 6 +- executor/infoschema_reader_test.go | 18 +-- executor/prepared_test.go | 4 +- executor/recover_test.go | 6 +- executor/show_placement_test.go | 6 +- executor/simple_test.go | 6 +- executor/slow_query_sql_test.go | 2 +- executor/test/fktest/foreign_key_test.go | 4 +- .../test/issuetest/executor_issue_test.go | 2 +- .../passwordtest/password_management_test.go | 126 +++++++++--------- executor/test/showtest/show_test.go | 42 +++--- executor/test/simpletest/simple_test.go | 28 ++-- extension/function_test.go | 22 +-- extension/registry_test.go | 8 +- infoschema/cluster_tables_test.go | 36 ++--- infoschema/tables_test.go | 20 +-- planner/core/binary_plan_test.go | 10 +- planner/core/integration_partition_test.go | 4 +- planner/core/integration_test.go | 2 +- planner/core/prepare_test.go | 4 +- .../privileges/ldap/mock_ldap_server_test.go | 1 - session/bootstrap_test.go | 6 +- session/sessiontest/session_test.go | 22 +-- sessiontxn/staleread/externalts_test.go | 6 +- table/tables/cache_test.go | 2 +- table/tables/tables_test.go | 4 +- .../pessimistictest/pessimistic_test.go | 4 +- util/stmtsummary/v2/tests/table_test.go | 8 +- 42 files changed, 255 insertions(+), 256 deletions(-) diff --git a/bindinfo/bind_test.go b/bindinfo/bind_test.go index cb8e62687df8f..44713331b43c1 100644 --- a/bindinfo/bind_test.go +++ b/bindinfo/bind_test.go @@ -762,11 +762,11 @@ func TestPrivileges(t *testing.T) { tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int, b int, index idx(a))") tk.MustExec("create global binding for select * from t using select * from t use index(idx)") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) rows := tk.MustQuery("show global bindings").Rows() require.Len(t, rows, 1) tk.MustExec("create user test@'%'") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "test", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "test", Hostname: "%"}, nil, nil, nil)) rows = tk.MustQuery("show global bindings").Rows() require.Len(t, rows, 0) } diff --git a/bindinfo/capture_test.go b/bindinfo/capture_test.go index 21b31c883e582..dc0215203b255 100644 --- a/bindinfo/capture_test.go +++ b/bindinfo/capture_test.go @@ -64,7 +64,7 @@ func TestDMLCapturePlanBaseline(t *testing.T) { rows := tk.MustQuery("show global bindings").Rows() require.Len(t, rows, 0) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("delete from t where b = 1 and c > 1") tk.MustExec("delete from t where b = 1 and c > 1") tk.MustExec("update t set a = 1 where b = 1 and c > 1") @@ -111,7 +111,7 @@ func TestCapturePlanBaseline(t *testing.T) { rows := tk.MustQuery("show global bindings").Rows() require.Len(t, rows, 0) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("select * from t where a > 10") tk.MustExec("select * from t where a > 10") tk.MustExec("admin capture bindings") @@ -143,7 +143,7 @@ func TestCapturePlanBaseline4DisabledStatus(t *testing.T) { rows := tk.MustQuery("show global bindings").Rows() require.Len(t, rows, 0) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("select * from t where a > 10") tk.MustExec("select * from t where a > 10") tk.MustExec("admin capture bindings") @@ -191,7 +191,7 @@ func TestCaptureDBCaseSensitivity(t *testing.T) { tk.MustExec("use SPM") tk.MustExec("create table t(a int, b int, key(b))") tk.MustExec("create global binding for select * from t using select /*+ use_index(t) */ * from t") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("select /*+ use_index(t,b) */ * from t") tk.MustExec("select /*+ use_index(t,b) */ * from t") tk.MustExec("admin capture bindings") @@ -217,7 +217,7 @@ func TestCaptureBaselinesDefaultDB(t *testing.T) { tk.MustExec("drop database if exists spm") tk.MustExec("create database spm") tk.MustExec("create table spm.t(a int, index idx_a(a))") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("select * from spm.t ignore index(idx_a) where a > 10") tk.MustExec("select * from spm.t ignore index(idx_a) where a > 10") tk.MustExec("admin capture bindings") @@ -244,7 +244,7 @@ func TestCapturePreparedStmt(t *testing.T) { tk := testkit.NewTestKit(t, store) stmtsummary.StmtSummaryByDigestMap.Clear() - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int, b int, c int, key idx_b(b), key idx_c(c))") @@ -279,7 +279,7 @@ func TestCapturePlanBaselineIgnoreTiFlash(t *testing.T) { tk.MustExec("use test") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int, b int, key(a), key(b))") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("select * from t") tk.MustExec("select * from t") // Create virtual tiflash replica info. @@ -354,7 +354,7 @@ func TestBindingSource(t *testing.T) { tk.MustExec("SET GLOBAL tidb_capture_plan_baselines = off") }() tk.MustExec("use test") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("select * from t ignore index(idx_a) where a < 10") tk.MustExec("select * from t ignore index(idx_a) where a < 10") tk.MustExec("admin capture bindings") @@ -374,7 +374,7 @@ func TestCapturedBindingCharset(t *testing.T) { tk := testkit.NewTestKit(t, store) stmtsummary.StmtSummaryByDigestMap.Clear() - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("create table t(name varchar(25), index idx(name))") @@ -407,7 +407,7 @@ func TestConcurrentCapture(t *testing.T) { tk.MustExec("use test") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int, b int)") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("select * from t") tk.MustExec("select * from t") tk.MustExec("admin capture bindings") @@ -427,7 +427,7 @@ func TestUpdateSubqueryCapture(t *testing.T) { tk.MustExec("create table t1(a int, b int, c int, key idx_b(b))") tk.MustExec("create table t2(a int, b int)") stmtsummary.StmtSummaryByDigestMap.Clear() - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("update t1 set b = 1 where b = 2 and (a in (select a from t2 where b = 1) or c in (select a from t2 where b = 1))") tk.MustExec("update t1 set b = 1 where b = 2 and (a in (select a from t2 where b = 1) or c in (select a from t2 where b = 1))") tk.MustExec("admin capture bindings") @@ -481,7 +481,7 @@ func TestIssue20417(t *testing.T) { stmtsummary.StmtSummaryByDigestMap.Clear() tk.MustExec("SET GLOBAL tidb_capture_plan_baselines = on") dom.BindHandle().CaptureBaselines() - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("select * from t where b=2 and c=213124") tk.MustExec("select * from t where b=2 and c=213124") tk.MustExec("admin capture bindings") @@ -526,7 +526,7 @@ func TestCaptureWithZeroSlowLogThreshold(t *testing.T) { tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int)") stmtsummary.StmtSummaryByDigestMap.Clear() - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("set tidb_slow_log_threshold = 0") tk.MustExec("select * from t") tk.MustExec("select * from t") @@ -552,7 +552,7 @@ func TestIssue25505(t *testing.T) { tk.MustExec("create table t (a int(11) default null,b int(11) default null,key b (b),key ba (b))") tk.MustExec("create table t1 (a int(11) default null,b int(11) default null,key idx_ab (a,b),key idx_a (a),key idx_b (b))") tk.MustExec("create table t2 (a int(11) default null,b int(11) default null,key idx_ab (a,b),key idx_a (a),key idx_b (b))") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) spmMap := map[string]string{} spmMap["with recursive `cte` ( `a` ) as ( select ? union select `a` + ? from `test` . `t1` where `a` < ? ) select * from `cte`"] = @@ -619,7 +619,7 @@ func TestCaptureUserFilter(t *testing.T) { tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int)") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("select * from t where a > 10") tk.MustExec("select * from t where a > 10") tk.MustExec("admin capture bindings") @@ -642,7 +642,7 @@ func TestCaptureUserFilter(t *testing.T) { tk.MustExec(`grant all on *.* to usr1 with grant option`) tk2 := testkit.NewTestKit(t, store) tk2.MustExec("use test") - require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{Username: "usr1", Hostname: "%"}, nil, nil)) + require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{Username: "usr1", Hostname: "%"}, nil, nil, nil)) tk2.MustExec("select * from t where a > 10") tk2.MustExec("select * from t where a > 10") tk2.MustExec("admin capture bindings") @@ -707,7 +707,7 @@ func TestCaptureWildcardFilter(t *testing.T) { tk.MustExec("SET GLOBAL tidb_capture_plan_baselines = off") }() - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) dbs := []string{"db11", "db12", "db2"} tbls := []string{"t11", "t12", "t2"} for _, db := range dbs { @@ -813,7 +813,7 @@ func TestCaptureFilter(t *testing.T) { tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int)") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("select * from t where a > 10") tk.MustExec("select * from t where a > 10") tk.MustExec("admin capture bindings") @@ -965,7 +965,7 @@ func TestCaptureHints(t *testing.T) { tk.MustExec("use test") tk.MustExec("drop table if exists t") tk.MustExec("create table t(pk int primary key, a int, b int, key(a), key(b))") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) captureCases := []struct { query string diff --git a/bindinfo/session_handle_test.go b/bindinfo/session_handle_test.go index a9b05c03eda18..1da00a925247c 100644 --- a/bindinfo/session_handle_test.go +++ b/bindinfo/session_handle_test.go @@ -179,7 +179,7 @@ func TestBaselineDBLowerCase(t *testing.T) { tk.MustExec("create database SPM") tk.MustExec("use SPM") tk.MustExec("create table t(a int, b int)") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("update t set a = a + 1") tk.MustExec("update t set a = a + 1") tk.MustExec("admin capture bindings") @@ -269,7 +269,7 @@ func TestShowGlobalBindings(t *testing.T) { tk.MustExec("use SPM") tk.MustExec("create table t(a int, b int, key(a))") tk.MustExec("create table t0(a int, b int, key(a))") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) rows := tk.MustQuery("show global bindings").Rows() require.Len(t, rows, 0) // Simulate existing bindings in the mysql.bind_info. diff --git a/ddl/db_cache_test.go b/ddl/db_cache_test.go index 012ac09ac7375..be2f37e3eb159 100644 --- a/ddl/db_cache_test.go +++ b/ddl/db_cache_test.go @@ -264,7 +264,7 @@ func TestIssue34069(t *testing.T) { defer sem.Disable() tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test;") tk.MustExec("create table t_34069 (t int);") // No error when SEM is enabled. diff --git a/ddl/db_test.go b/ddl/db_test.go index d155a98d2a79c..d40f57b7e3143 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -804,7 +804,7 @@ func TestForbidCacheTableForSystemTable(t *testing.T) { memOrSysDB := []string{"MySQL", "INFORMATION_SCHEMA", "PERFORMANCE_SCHEMA", "METRICS_SCHEMA"} for _, db := range memOrSysDB { tk.MustExec("use " + db) - tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil) + tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil) rows := tk.MustQuery("show tables").Rows() for i := 0; i < len(rows); i++ { sysTables = append(sysTables, rows[i][0].(string)) diff --git a/ddl/fktest/foreign_key_test.go b/ddl/fktest/foreign_key_test.go index 90b94a4e75dbb..b3af6a87050e7 100644 --- a/ddl/fktest/foreign_key_test.go +++ b/ddl/fktest/foreign_key_test.go @@ -305,7 +305,7 @@ func TestCreateTableWithForeignKeyPrivilegeCheck(t *testing.T) { tk2 := testkit.NewTestKit(t, store) tk2.MustExec("use test") - tk2.Session().Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost", CurrentUser: true, AuthUsername: "u1", AuthHostname: "%"}, nil, []byte("012345678901234567890")) + tk2.Session().Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost", CurrentUser: true, AuthUsername: "u1", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) err := tk2.ExecToErr("create table t2 (a int, foreign key fk(a) references t1(id));") require.Error(t, err) require.Equal(t, "[planner:1142]REFERENCES command denied to user 'u1'@'%' for table 't1'", err.Error()) @@ -330,7 +330,7 @@ func TestAlterTableWithForeignKeyPrivilegeCheck(t *testing.T) { tk.MustExec("create table t1 (id int key);") tk2 := testkit.NewTestKit(t, store) tk2.MustExec("use test") - tk2.Session().Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost", CurrentUser: true, AuthUsername: "u1", AuthHostname: "%"}, nil, []byte("012345678901234567890")) + tk2.Session().Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost", CurrentUser: true, AuthUsername: "u1", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) tk2.MustExec("create table t2 (a int)") err := tk2.ExecToErr("alter table t2 add foreign key (a) references t1 (id) on update cascade") require.Error(t, err) diff --git a/ddl/sequence_test.go b/ddl/sequence_test.go index 9b798c9f45eea..d704626792c0c 100644 --- a/ddl/sequence_test.go +++ b/ddl/sequence_test.go @@ -82,7 +82,7 @@ func TestCreateSequence(t *testing.T) { tk1 := testkit.NewTestKit(t, store) se, err := session.CreateSession4Test(store) require.NoError(t, err) - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "myuser", Hostname: "localhost"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "myuser", Hostname: "localhost"}, nil, nil, nil)) tk1.SetSession(se) // grant the myuser the access to database test. @@ -162,7 +162,7 @@ func TestDropSequence(t *testing.T) { tk1 := testkit.NewTestKit(t, store) se, err := session.CreateSession4Test(store) require.NoError(t, err) - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "myuser", Hostname: "localhost"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "myuser", Hostname: "localhost"}, nil, nil, nil)) tk1.SetSession(se) // grant the myuser the access to database test. @@ -196,7 +196,7 @@ func TestShowCreateSequence(t *testing.T) { tk1 := testkit.NewTestKit(t, store) se, err := session.CreateSession4Test(store) require.NoError(t, err) - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "myuser", Hostname: "localhost"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "myuser", Hostname: "localhost"}, nil, nil, nil)) tk1.SetSession(se) // Grant the myuser the access to table t in database test, but sequence seq. @@ -909,7 +909,7 @@ func TestSequenceFunctionPrivilege(t *testing.T) { tk1 := testkit.NewTestKit(t, store) se, err := session.CreateSession4Test(store) require.NoError(t, err) - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "myuser", Hostname: "localhost"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "myuser", Hostname: "localhost"}, nil, nil, nil)) tk1.SetSession(se) // grant the myuser the create access to the sequence. @@ -1102,7 +1102,7 @@ func TestAlterSequencePrivilege(t *testing.T) { tk1 := testkit.NewTestKit(t, store) se, err := session.CreateSession4Test(store) require.NoError(t, err) - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "myuser", Hostname: "localhost"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "myuser", Hostname: "localhost"}, nil, nil, nil)) tk1.SetSession(se) // grant the myuser the access to database test. diff --git a/ddl/tiflash_replica_test.go b/ddl/tiflash_replica_test.go index abd7275e4669b..eb7dc2be8336e 100644 --- a/ddl/tiflash_replica_test.go +++ b/ddl/tiflash_replica_test.go @@ -218,7 +218,7 @@ func TestSetTableFlashReplicaForSystemTable(t *testing.T) { memOrSysDB := []string{"MySQL", "INFORMATION_SCHEMA", "PERFORMANCE_SCHEMA", "METRICS_SCHEMA"} for _, db := range memOrSysDB { tk.MustExec("use " + db) - tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil) + tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil) rows := tk.MustQuery("show tables").Rows() for i := 0; i < len(rows); i++ { sysTables = append(sysTables, rows[i][0].(string)) diff --git a/domain/extract_test.go b/domain/extract_test.go index d6777380d97ee..c543972ef0c6f 100644 --- a/domain/extract_test.go +++ b/domain/extract_test.go @@ -104,6 +104,6 @@ func newTestKit(t *testing.T, store kv.Storage) *testkit.TestKit { func newTestKitWithRoot(t *testing.T, store kv.Storage) *testkit.TestKit { tk := newTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) return tk } diff --git a/executor/cluster_table_test.go b/executor/cluster_table_test.go index f7497898d54b2..0653a0ad68fc5 100644 --- a/executor/cluster_table_test.go +++ b/executor/cluster_table_test.go @@ -291,7 +291,7 @@ func TestSQLDigestTextRetriever(t *testing.T) { tk := testkit.NewTestKit(t, store) tk.MustExec("use test") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("insert into test_sql_digest_text_retriever values (1, 1)") insertNormalized, insertDigest := parser.NormalizeDigest("insert into test_sql_digest_text_retriever values (1, 1)") @@ -315,7 +315,7 @@ func TestFunctionDecodeSQLDigests(t *testing.T) { tk := testkit.NewTestKit(t, store) tk.MustExec("use test") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("set global tidb_enable_stmt_summary = 1") tk.MustQuery("select @@global.tidb_enable_stmt_summary").Check(testkit.Rows("1")) tk.MustExec("drop table if exists test_func_decode_sql_digests") @@ -374,21 +374,21 @@ func TestFunctionDecodeSQLDigestsPrivilege(t *testing.T) { defer srv.Stop() dropUserTk := testkit.NewTestKit(t, store) - require.NoError(t, dropUserTk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, dropUserTk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("create user 'testuser'@'localhost'") defer dropUserTk.MustExec("drop user 'testuser'@'localhost'") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "testuser", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "testuser", Hostname: "localhost"}, nil, nil, nil)) tk.MustGetErrMsg("select tidb_decode_sql_digests('[\"aa\"]')", "[expression:1227]Access denied; you need (at least one of) the PROCESS privilege(s) for this operation") tk = testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("create user 'testuser2'@'localhost'") defer dropUserTk.MustExec("drop user 'testuser2'@'localhost'") tk.MustExec("grant process on *.* to 'testuser2'@'localhost'") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "testuser2", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "testuser2", Hostname: "localhost"}, nil, nil, nil)) tk.MustExec("select tidb_decode_sql_digests('[\"aa\"]')") } diff --git a/executor/executor_test.go b/executor/executor_test.go index c4606ae09d849..431ec312e57e5 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -6108,7 +6108,7 @@ func TestSummaryFailedUpdate(t *testing.T) { tk.MustQuery("select variable_value from mysql.GLOBAL_VARIABLES where variable_name = 'tidb_mem_oom_action'").Check(testkit.Rows("LOG")) tk.MustExec("SET GLOBAL tidb_mem_oom_action='CANCEL'") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("set @@tidb_mem_quota_query=1") tk.MustMatchErrMsg("update t set t.a = t.a - 1 where t.a in (select a from t where a < 4)", memory.PanicMemoryExceedWarnMsg) tk.MustExec("set @@tidb_mem_quota_query=1000000000") @@ -6213,7 +6213,7 @@ func TestTableLockPrivilege(t *testing.T) { tk.MustExec("use test") tk.MustExec("create table t(a int)") tk.MustExec("create user 'testuser'@'localhost'") - require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{Username: "testuser", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{Username: "testuser", Hostname: "localhost"}, nil, nil, nil)) tk2.MustGetErrMsg("LOCK TABLE test.t WRITE", "[planner:1044]Access denied for user 'testuser'@'localhost' to database 'test'") tk.MustExec("GRANT LOCK TABLES ON test.* to 'testuser'@'localhost'") tk2.MustGetErrMsg("LOCK TABLE test.t WRITE", "[planner:1142]SELECT command denied to user 'testuser'@'localhost' for table 't'") diff --git a/executor/explain_test.go b/executor/explain_test.go index d5e609d821fa5..aacc852f53582 100644 --- a/executor/explain_test.go +++ b/executor/explain_test.go @@ -38,7 +38,7 @@ func TestExplainPrivileges(t *testing.T) { store := testkit.CreateMockStore(t) se, err := session.CreateSession4Test(store) require.NoError(t, err) - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk := testkit.NewTestKit(t, store) tk.SetSession(se) @@ -51,7 +51,7 @@ func TestExplainPrivileges(t *testing.T) { tk1 := testkit.NewTestKit(t, store) se, err = session.CreateSession4Test(store) require.NoError(t, err) - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "explain", Hostname: "%"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "explain", Hostname: "%"}, nil, nil, nil)) tk1.SetSession(se) tk.MustExec(`grant select on explaindatabase.v to 'explain'@'%'`) diff --git a/executor/explainfor_test.go b/executor/explainfor_test.go index 11271a12698d8..a50b7b988996e 100644 --- a/executor/explainfor_test.go +++ b/executor/explainfor_test.go @@ -40,8 +40,8 @@ func TestExplainFor(t *testing.T) { tkRoot.MustExec("create table t1(c1 int, c2 int)") tkRoot.MustExec("create table t2(c1 int, c2 int)") tkRoot.MustExec("create user tu@'%'") - tkRoot.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost", CurrentUser: true, AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890")) - tkUser.Session().Auth(&auth.UserIdentity{Username: "tu", Hostname: "localhost", CurrentUser: true, AuthUsername: "tu", AuthHostname: "%"}, nil, []byte("012345678901234567890")) + tkRoot.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost", CurrentUser: true, AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) + tkUser.Session().Auth(&auth.UserIdentity{Username: "tu", Hostname: "localhost", CurrentUser: true, AuthUsername: "tu", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) tkRoot.MustExec("set @@tidb_enable_collect_execution_info=0;") tkRoot.MustQuery("select * from t1;") @@ -441,7 +441,7 @@ func TestPointGetUserVarPlanCache(t *testing.T) { tmp := testkit.NewTestKit(t, store) tmp.MustExec("set tidb_enable_prepared_plan_cache=ON") tk := testkit.NewTestKit(t, store) - tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost", CurrentUser: true, AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890")) + tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost", CurrentUser: true, AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) tk.MustExec("use test") tk.MustExec("set tidb_cost_model_version=2") diff --git a/executor/grant_test.go b/executor/grant_test.go index 8a5a774ce0a3e..d0e413a0d2aab 100644 --- a/executor/grant_test.go +++ b/executor/grant_test.go @@ -471,7 +471,7 @@ func TestGrantOnNonExistTable(t *testing.T) { tk.MustExec("GRANT CREATE, DROP, INSERT ON t29268 TO u29268") // check privilege - tk.Session().Auth(&auth.UserIdentity{Username: "u29268", Hostname: "localhost"}, nil, nil) + tk.Session().Auth(&auth.UserIdentity{Username: "u29268", Hostname: "localhost"}, nil, nil, nil) tk.MustExec("USE d29268") tk.MustExec("CREATE TABLE t29268 (c1 int)") tk.MustExec("INSERT INTO t29268 VALUES (1), (2)") @@ -479,7 +479,7 @@ func TestGrantOnNonExistTable(t *testing.T) { tk.MustExec("DROP TABLE t29268") // check grant all - tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil) + tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil, nil) tk.MustExec("GRANT ALL ON t29268 TO u29268") } @@ -505,7 +505,7 @@ func TestPerformanceSchemaPrivGrant(t *testing.T) { defer func() { tk.MustExec("drop user issue27867;") }() - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil, nil)) tk.MustGetErrCode("grant all on performance_schema.* to issue27867;", errno.ErrDBaccessDenied) // Check case insensitivity tk.MustGetErrCode("grant all on PERFormanCE_scHemA.* to issue27867;", errno.ErrDBaccessDenied) diff --git a/executor/infoschema_cluster_table_test.go b/executor/infoschema_cluster_table_test.go index 57dd1a65969dd..7e1d9bb01d07c 100644 --- a/executor/infoschema_cluster_table_test.go +++ b/executor/infoschema_cluster_table_test.go @@ -307,7 +307,7 @@ func TestTableStorageStats(t *testing.T) { require.NoError(t, tk.Session().Auth(&auth.UserIdentity{ Username: "testuser", Hostname: "localhost", - }, nil, nil)) + }, nil, nil, nil)) // User has no access to this schema, so the result set is empty. tk.MustQuery("select count(1) from information_schema.TABLE_STORAGE_STATS where TABLE_SCHEMA = 'mysql'").Check(testkit.Rows("0")) @@ -315,14 +315,14 @@ func TestTableStorageStats(t *testing.T) { require.NoError(t, tk.Session().Auth(&auth.UserIdentity{ Username: "testuser2", Hostname: "localhost", - }, nil, nil)) + }, nil, nil, nil)) tk.MustQuery("select count(1) from information_schema.TABLE_STORAGE_STATS where TABLE_SCHEMA = 'mysql'").Check(testkit.Rows(strconv.Itoa(result))) require.NoError(t, tk.Session().Auth(&auth.UserIdentity{ Username: "testuser3", Hostname: "localhost", - }, nil, nil)) + }, nil, nil, nil)) tk.MustQuery("select count(1) from information_schema.TABLE_STORAGE_STATS where TABLE_SCHEMA = 'mysql'").Check(testkit.Rows(strconv.Itoa(result))) } diff --git a/executor/infoschema_reader_test.go b/executor/infoschema_reader_test.go index 407ae2800cbf8..ceb4c55593d19 100644 --- a/executor/infoschema_reader_test.go +++ b/executor/infoschema_reader_test.go @@ -102,7 +102,7 @@ func TestSchemataTables(t *testing.T) { require.NoError(t, schemataTester.Session().Auth(&auth.UserIdentity{ Username: "schemata_tester", Hostname: "127.0.0.1", - }, nil, nil)) + }, nil, nil, nil)) schemataTester.MustQuery("select count(*) from information_schema.SCHEMATA;").Check(testkit.Rows("1")) schemataTester.MustQuery("select * from information_schema.SCHEMATA where schema_name='mysql';").Check( [][]interface{}{}) @@ -247,7 +247,7 @@ func TestDDLJobs(t *testing.T) { require.NoError(t, DDLJobsTester.Session().Auth(&auth.UserIdentity{ Username: "DDL_JOBS_tester", Hostname: "127.0.0.1", - }, nil, nil)) + }, nil, nil, nil)) // Test the privilege of user for information_schema.ddl_jobs. DDLJobsTester.MustQuery("select DB_NAME, TABLE_NAME from information_schema.DDL_JOBS where DB_NAME = 'test_ddl_jobs' and TABLE_NAME = 't';").Check( @@ -279,7 +279,7 @@ func TestKeyColumnUsage(t *testing.T) { require.NoError(t, keyColumnTester.Session().Auth(&auth.UserIdentity{ Username: "key_column_tester", Hostname: "127.0.0.1", - }, nil, nil)) + }, nil, nil, nil)) keyColumnTester.MustQuery("select * from information_schema.KEY_COLUMN_USAGE where TABLE_NAME != 'CLUSTER_SLOW_QUERY';").Check([][]interface{}{}) // test the privilege of user with privilege of mysql.gc_delete_range for information_schema.table_constraints @@ -301,7 +301,7 @@ func TestUserPrivileges(t *testing.T) { require.NoError(t, constraintsTester.Session().Auth(&auth.UserIdentity{ Username: "constraints_tester", Hostname: "127.0.0.1", - }, nil, nil)) + }, nil, nil, nil)) constraintsTester.MustQuery("select * from information_schema.TABLE_CONSTRAINTS WHERE TABLE_NAME != 'CLUSTER_SLOW_QUERY';").Check([][]interface{}{}) // test the privilege of user with privilege of mysql.gc_delete_range for information_schema.table_constraints @@ -320,7 +320,7 @@ func TestUserPrivileges(t *testing.T) { require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{ Username: "tester1", Hostname: "127.0.0.1", - }, nil, nil)) + }, nil, nil, nil)) tk1.MustQuery("select * from information_schema.STATISTICS WHERE TABLE_NAME != 'CLUSTER_SLOW_QUERY';").Check([][]interface{}{}) // test the privilege of user with some privilege for information_schema @@ -333,7 +333,7 @@ func TestUserPrivileges(t *testing.T) { require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{ Username: "tester2", Hostname: "127.0.0.1", - }, nil, nil)) + }, nil, nil, nil)) tk2.MustExec("set role r_columns_priv") rows = tk2.MustQuery("select * from information_schema.STATISTICS where TABLE_NAME='columns_priv' and COLUMN_NAME='Host';").Rows() require.Greater(t, len(rows), 0) @@ -350,7 +350,7 @@ func TestUserPrivileges(t *testing.T) { require.NoError(t, tk3.Session().Auth(&auth.UserIdentity{ Username: "tester3", Hostname: "127.0.0.1", - }, nil, nil)) + }, nil, nil, nil)) tk3.MustExec("set role r_all_priv") rows = tk3.MustQuery("select * from information_schema.STATISTICS where TABLE_NAME='columns_priv' and COLUMN_NAME='Host';").Rows() require.Greater(t, len(rows), 0) @@ -368,7 +368,7 @@ func TestUserPrivilegesTable(t *testing.T) { require.NoError(t, tk.Session().Auth(&auth.UserIdentity{ Username: "usageuser", Hostname: "127.0.0.1", - }, nil, nil)) + }, nil, nil, nil)) tk.MustQuery(`SELECT * FROM information_schema.user_privileges WHERE grantee="'usageuser'@'%'"`).Check(testkit.Rows("'usageuser'@'%' def USAGE NO")) // the usage row disappears when there is a non-dynamic privilege added tk1.MustExec("GRANT SELECT ON *.* to usageuser") @@ -590,7 +590,7 @@ func TestForAnalyzeStatus(t *testing.T) { require.NoError(t, analyzeTester.Session().Auth(&auth.UserIdentity{ Username: "analyze_tester", Hostname: "127.0.0.1", - }, nil, nil)) + }, nil, nil, nil)) analyzeTester.MustQuery("show analyze status").Check([][]interface{}{}) analyzeTester.MustQuery("select * from information_schema.ANALYZE_STATUS;").Check([][]interface{}{}) diff --git a/executor/prepared_test.go b/executor/prepared_test.go index 079e06e56b5e0..89692bb1f99f2 100644 --- a/executor/prepared_test.go +++ b/executor/prepared_test.go @@ -1169,7 +1169,7 @@ func TestPrepareStmtAfterIsolationReadChange(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store) tk.MustExec(`set tidb_enable_prepared_plan_cache=0`) - tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost", CurrentUser: true, AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890")) + tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost", CurrentUser: true, AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) tk.MustExec("use test") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int)") @@ -1216,7 +1216,7 @@ func TestPreparePC4Binding(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec(`set tidb_enable_prepared_plan_cache=1`) - tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost", CurrentUser: true, AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890")) + tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost", CurrentUser: true, AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) tk.MustExec("use test") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int)") diff --git a/executor/recover_test.go b/executor/recover_test.go index 92aa83ec99d3e..6fd3426f9c7b6 100644 --- a/executor/recover_test.go +++ b/executor/recover_test.go @@ -314,7 +314,7 @@ func TestRecoverTablePrivilege(t *testing.T) { // Recover without drop/create privilege. tk.MustExec("CREATE USER 'testrecovertable'@'localhost';") newTk := testkit.NewTestKit(t, store) - require.NoError(t, newTk.Session().Auth(&auth.UserIdentity{Username: "testrecovertable", Hostname: "localhost"}, nil, nil)) + require.NoError(t, newTk.Session().Auth(&auth.UserIdentity{Username: "testrecovertable", Hostname: "localhost"}, nil, nil, nil)) newTk.MustGetErrCode("recover table t_recover", errno.ErrTableaccessDenied) newTk.MustGetErrCode("flashback table t_recover", errno.ErrTableaccessDenied) @@ -363,7 +363,7 @@ func TestRecoverClusterMeetError(t *testing.T) { // Flashback without super privilege. tk.MustExec("CREATE USER 'testflashback'@'localhost';") newTk := testkit.NewTestKit(t, store) - require.NoError(t, newTk.Session().Auth(&auth.UserIdentity{Username: "testflashback", Hostname: "localhost"}, nil, nil)) + require.NoError(t, newTk.Session().Auth(&auth.UserIdentity{Username: "testflashback", Hostname: "localhost"}, nil, nil, nil)) newTk.MustGetErrCode(fmt.Sprintf("flashback cluster to timestamp '%s'", time.Now().Add(0-30*time.Second)), errno.ErrPrivilegeCheckFail) tk.MustExec("drop user 'testflashback'@'localhost';") @@ -544,7 +544,7 @@ func TestFlashbackSchema(t *testing.T) { // Recover without drop/create privilege. tk.MustExec("CREATE USER 'testflashbackschema'@'localhost';") newTk := testkit.NewTestKit(t, store) - require.NoError(t, newTk.Session().Auth(&auth.UserIdentity{Username: "testflashbackschema", Hostname: "localhost"}, nil, nil)) + require.NoError(t, newTk.Session().Auth(&auth.UserIdentity{Username: "testflashbackschema", Hostname: "localhost"}, nil, nil, nil)) newTk.MustGetErrCode("flashback database t_recover", errno.ErrDBaccessDenied) // Got drop privilege, still failed. diff --git a/executor/show_placement_test.go b/executor/show_placement_test.go index f03b09cb63d04..db5b35fb8e0c5 100644 --- a/executor/show_placement_test.go +++ b/executor/show_placement_test.go @@ -151,7 +151,7 @@ func TestShowPlacementPrivilege(t *testing.T) { defer tk.MustExec("drop table if exists db2.t3") tk1 := testkit.NewTestKit(t, store) - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "user1", Hostname: "%"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "user1", Hostname: "%"}, nil, nil, nil)) // before grant tk1.MustQuery("show placement").Check(testkit.Rows( @@ -308,7 +308,7 @@ func TestShowPlacementForDBPrivilege(t *testing.T) { defer tk.MustExec("drop table db2.t1") tk1 := testkit.NewTestKit(t, store) - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "user1", Hostname: "%"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "user1", Hostname: "%"}, nil, nil, nil)) privs := []string{ "all privileges on db2.*", @@ -400,7 +400,7 @@ func TestShowPlacementForTableAndPartitionPrivilege(t *testing.T) { defer tk.MustExec("drop table if exists db2.t1") tk1 := testkit.NewTestKit(t, store) - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "user1", Hostname: "%"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "user1", Hostname: "%"}, nil, nil, nil)) // before grant err := tk1.ExecToErr("show placement for table test.t1") diff --git a/executor/simple_test.go b/executor/simple_test.go index 7b4d340bc6a84..b0bda248bb5ba 100644 --- a/executor/simple_test.go +++ b/executor/simple_test.go @@ -119,7 +119,7 @@ func TestUserAttributes(t *testing.T) { // Non-root users could access COMMENT or ATTRIBUTE of all users via the view, // but not via the mysql.user table. tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "testuser1"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "testuser1"}, nil, nil, nil)) tk.MustQueryWithContext(ctx, `SELECT user, host, attribute FROM information_schema.user_attributes ORDER BY user`).Check( testkit.Rows("root % ", "testuser % {\"comment\": \"1234\"}", "testuser1 % {\"age\": 20, \"name\": \"Tom\"}", "testuser2 % ")) tk.MustGetErrCode(`SELECT user, host, user_attributes FROM mysql.user ORDER BY user`, mysql.ErrTableaccessDenied) @@ -145,7 +145,7 @@ func TestSetResourceGroup(t *testing.T) { tk.MustExec("CREATE RESOURCE GROUP rg1 ru_per_sec = 100") tk.MustExec("ALTER USER `root` RESOURCE GROUP `rg1`") tk.MustQuery("SELECT CURRENT_RESOURCE_GROUP()").Check(testkit.Rows("")) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustQuery("SELECT CURRENT_RESOURCE_GROUP()").Check(testkit.Rows("rg1")) tk.MustExec("CREATE RESOURCE GROUP rg2 ru_per_sec = 200") @@ -155,6 +155,6 @@ func TestSetResourceGroup(t *testing.T) { tk.MustQuery("SELECT CURRENT_RESOURCE_GROUP()").Check(testkit.Rows("")) tk.RefreshSession() - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustQuery("SELECT CURRENT_RESOURCE_GROUP()").Check(testkit.Rows("rg1")) } diff --git a/executor/slow_query_sql_test.go b/executor/slow_query_sql_test.go index b7a8d3b3a957d..fb84bbb394bd8 100644 --- a/executor/slow_query_sql_test.go +++ b/executor/slow_query_sql_test.go @@ -266,7 +266,7 @@ func TestIssue37066(t *testing.T) { require.NoError(t, logutil.InitLogger(newCfg.Log.ToLogConfig())) store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec(fmt.Sprintf("set @@tidb_slow_query_file='%v'", f.Name())) tk.MustExec("set tidb_slow_log_threshold=0;") defer func() { diff --git a/executor/test/fktest/foreign_key_test.go b/executor/test/fktest/foreign_key_test.go index a24be95c33d4b..4b0a21e0308d0 100644 --- a/executor/test/fktest/foreign_key_test.go +++ b/executor/test/fktest/foreign_key_test.go @@ -2491,7 +2491,7 @@ func TestPrivilegeCheckInForeignKeyCascade(t *testing.T) { for _, sql := range ca.prepares { tk.MustExec(sql) } - err := tk2.Session().Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost", CurrentUser: true, AuthUsername: "u1", AuthHostname: "%"}, nil, []byte("012345678901234567890")) + err := tk2.Session().Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost", CurrentUser: true, AuthUsername: "u1", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) require.NoError(t, err) if ca.err == nil { tk2.MustExec(ca.sql) @@ -2542,7 +2542,7 @@ func TestForeignKeyIssue39732(t *testing.T) { tk.MustExec("use test") tk.MustExec("create user 'u1'@'%' identified by '';") tk.MustExec("GRANT ALL PRIVILEGES ON *.* TO 'u1'@'%'") - err := tk.Session().Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost", CurrentUser: true, AuthUsername: "u1", AuthHostname: "%"}, nil, []byte("012345678901234567890")) + err := tk.Session().Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost", CurrentUser: true, AuthUsername: "u1", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) require.NoError(t, err) tk.MustExec("create table t1 (id int key, leader int, index(leader), foreign key (leader) references t1(id) ON DELETE CASCADE);") tk.MustExec("insert into t1 values (1, null), (10, 1), (11, 1), (20, 10)") diff --git a/executor/test/issuetest/executor_issue_test.go b/executor/test/issuetest/executor_issue_test.go index 3a7cc9318965c..f874a2d8021f8 100644 --- a/executor/test/issuetest/executor_issue_test.go +++ b/executor/test/issuetest/executor_issue_test.go @@ -478,7 +478,7 @@ func TestIndexJoin31494(t *testing.T) { dom.ExpensiveQueryHandle().SetSessionManager(sm) defer tk.MustExec("SET GLOBAL tidb_mem_oom_action = DEFAULT") tk.MustExec("SET GLOBAL tidb_mem_oom_action='CANCEL'") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("set @@tidb_mem_quota_query=2097152;") // This bug will be reproduced in 10 times. for i := 0; i < 10; i++ { diff --git a/executor/test/passwordtest/password_management_test.go b/executor/test/passwordtest/password_management_test.go index b817a8facb965..ec15e0a140474 100644 --- a/executor/test/passwordtest/password_management_test.go +++ b/executor/test/passwordtest/password_management_test.go @@ -40,11 +40,11 @@ func TestValidatePassword(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) subtk := testkit.NewTestKit(t, store) - err := tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil) + err := tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil) require.NoError(t, err) tk.MustExec("CREATE USER ''@'localhost'") tk.MustExec("GRANT ALL PRIVILEGES ON mysql.* TO ''@'localhost';") - err = subtk.Session().Auth(&auth.UserIdentity{Hostname: "localhost"}, nil, nil) + err = subtk.Session().Auth(&auth.UserIdentity{Hostname: "localhost"}, nil, nil, nil) require.NoError(t, err) authPlugins := []string{mysql.AuthNativePassword, mysql.AuthCachingSha2Password, mysql.AuthTiDBSM3Password} @@ -280,7 +280,7 @@ func TestPasswordManagement(t *testing.T) { result = rootTK.MustQuery(`Select authentication_string from mysql.user where user = 'u2' and host = '%'`) result.Check(testkit.Rows(auth.EncodePassword("Uu3@22222"))) // Auto-lock in effect. - err := tk.Session().Auth(&auth.UserIdentity{Username: "u2", Hostname: "%"}, sha1Password(""), nil) + err := tk.Session().Auth(&auth.UserIdentity{Username: "u2", Hostname: "%"}, sha1Password(""), nil, nil) require.ErrorContains(t, err, "Account is blocked for 1 day(s) (1 day(s) remaining) due to 1 consecutive failed logins.") result = rootTK.MustQuery(`SELECT JSON_UNQUOTE(JSON_EXTRACT(user_attributes, '$.Password_locking.failed_login_count')), @@ -299,10 +299,10 @@ func TestPasswordManagement(t *testing.T) { err = domain.GetDomain(rootTK.Session()).NotifyUpdatePrivilege() require.NoError(t, err) // Password expires and takes effect. - err = tk.Session().Auth(&auth.UserIdentity{Username: "u2", Hostname: "%"}, sha1Password("Uu3@22222"), nil) + err = tk.Session().Auth(&auth.UserIdentity{Username: "u2", Hostname: "%"}, sha1Password("Uu3@22222"), nil, nil) require.ErrorContains(t, err, "Your password has expired.") variable.IsSandBoxModeEnabled.Store(true) - err = tk.Session().Auth(&auth.UserIdentity{Username: "u2", Hostname: "%"}, sha1Password("Uu3@22222"), nil) + err = tk.Session().Auth(&auth.UserIdentity{Username: "u2", Hostname: "%"}, sha1Password("Uu3@22222"), nil, nil) require.NoError(t, err) require.True(t, tk.Session().InSandBoxMode()) @@ -321,7 +321,7 @@ func TestPasswordManagement(t *testing.T) { result = rootTK.MustQuery(`Select authentication_string from mysql.user where user = 'u2' and host = '%'`) result.Check(testkit.Rows(auth.EncodePassword("Uu3@22223"))) tk = testkit.NewTestKit(t, store) - err = tk.Session().Auth(&auth.UserIdentity{Username: "u2", Hostname: "%"}, sha1Password("Uu3@22223"), nil) + err = tk.Session().Auth(&auth.UserIdentity{Username: "u2", Hostname: "%"}, sha1Password("Uu3@22223"), nil, nil) require.NoError(t, err) } @@ -749,43 +749,43 @@ func TestFailedLoginTracking(t *testing.T) { // Set FAILED_LOGIN_ATTEMPTS to 1, and check error messages after login failure once. createAndCheck(tk, "CREATE USER 'testu1'@'localhost' IDENTIFIED BY 'testu1' FAILED_LOGIN_ATTEMPTS 1 PASSWORD_LOCK_TIME 1", "{\"Password_locking\": {\"failed_login_attempts\": 1, \"password_lock_time_days\": 1}}", "testu1") - err := tk.Session().Auth(&auth.UserIdentity{Username: "testu1", Hostname: "localhost"}, sha1Password("password"), nil) + err := tk.Session().Auth(&auth.UserIdentity{Username: "testu1", Hostname: "localhost"}, sha1Password("password"), nil, nil) lds := strconv.FormatInt(1, 10) errTarget := privileges.GenerateAccountAutoLockErr(1, "testu1", "localhost", lds, lds) require.Equal(t, err.Error(), errTarget.Error()) checkAuthUser(t, tk, "testu1", 1, "Y") // Check the login error message after the account is locked. - err = tk.Session().Auth(&auth.UserIdentity{Username: "testu1", Hostname: "localhost"}, sha1Password("password"), nil) + err = tk.Session().Auth(&auth.UserIdentity{Username: "testu1", Hostname: "localhost"}, sha1Password("password"), nil, nil) require.Equal(t, err.Error(), errTarget.Error()) checkAuthUser(t, tk, "testu1", 1, "Y") // Set FAILED_LOGIN_ATTEMPTS to 1 and PASSWORD_LOCK_TIME to UNBOUNDED. Check error messages after failed login once. createAndCheck(tk, "CREATE USER 'testu2'@'localhost' IDENTIFIED BY 'testu2' FAILED_LOGIN_ATTEMPTS 1 PASSWORD_LOCK_TIME UNBOUNDED", "{\"Password_locking\": {\"failed_login_attempts\": 1, \"password_lock_time_days\": -1}}", "testu2") - err = tk.Session().Auth(&auth.UserIdentity{Username: "testu2", Hostname: "localhost"}, sha1Password("password"), nil) + err = tk.Session().Auth(&auth.UserIdentity{Username: "testu2", Hostname: "localhost"}, sha1Password("password"), nil, nil) errTarget = privileges.GenerateAccountAutoLockErr(1, "testu2", "localhost", "unlimited", "unlimited") require.Equal(t, err.Error(), errTarget.Error()) checkAuthUser(t, tk, "testu2", 1, "Y") // Check the login error message after the account is locked. - err = tk.Session().Auth(&auth.UserIdentity{Username: "testu2", Hostname: "localhost"}, sha1Password("password"), nil) + err = tk.Session().Auth(&auth.UserIdentity{Username: "testu2", Hostname: "localhost"}, sha1Password("password"), nil, nil) require.Equal(t, err.Error(), errTarget.Error()) checkAuthUser(t, tk, "testu2", 1, "Y") // Set FAILED_LOGIN_ATTEMPTS to 0 or PASSWORD_LOCK_TIME to 0. Check error messages after failed login once. createAndCheck(tk, "CREATE USER 'testu3'@'localhost' IDENTIFIED BY 'testu3' FAILED_LOGIN_ATTEMPTS 0 PASSWORD_LOCK_TIME UNBOUNDED", "{\"Password_locking\": {\"failed_login_attempts\": 0, \"password_lock_time_days\": -1}}", "testu3") - err = tk.Session().Auth(&auth.UserIdentity{Username: "testu3", Hostname: "localhost"}, sha1Password("password"), nil) + err = tk.Session().Auth(&auth.UserIdentity{Username: "testu3", Hostname: "localhost"}, sha1Password("password"), nil, nil) require.ErrorContains(t, err, "Access denied for user 'testu3'@'localhost' (using password: YES)") checkAuthUser(t, tk, "testu3", 0, "") createAndCheck(tk, "CREATE USER 'testu4'@'localhost' IDENTIFIED BY 'testu4' FAILED_LOGIN_ATTEMPTS 1 PASSWORD_LOCK_TIME 0", "{\"Password_locking\": {\"failed_login_attempts\": 1, \"password_lock_time_days\": 0}}", "testu4") - err = tk.Session().Auth(&auth.UserIdentity{Username: "testu4", Hostname: "localhost"}, sha1Password("password"), nil) + err = tk.Session().Auth(&auth.UserIdentity{Username: "testu4", Hostname: "localhost"}, sha1Password("password"), nil, nil) require.ErrorContains(t, err, "Access denied for user 'testu4'@'localhost' (using password: YES)") checkAuthUser(t, tk, "testu4", 0, "") tk.MustExec("CREATE USER 'testu5'@'localhost' IDENTIFIED BY 'testu5' FAILED_LOGIN_ATTEMPTS 0 PASSWORD_LOCK_TIME 0") - err = tk.Session().Auth(&auth.UserIdentity{Username: "testu5", Hostname: "localhost"}, sha1Password("password"), nil) + err = tk.Session().Auth(&auth.UserIdentity{Username: "testu5", Hostname: "localhost"}, sha1Password("password"), nil, nil) require.ErrorContains(t, err, "Access denied for user 'testu5'@'localhost' (using password: YES)") tk.MustQuery("select user_attributes from mysql.user where user= 'testu5' and host = 'localhost'").Check(testkit.Rows("{}")) @@ -819,12 +819,12 @@ func TestFailedLoginTracking(t *testing.T) { // Confirm the user_attributes value after login failure once. require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "testu5", Hostname: "localhost"}, - sha1Password("password"), nil)) + sha1Password("password"), nil, nil)) checkUserUserAttributes(tk, "testu5", "localhost", "2 \"N\" 1 1 {\"comment\": \"testcomment\"}") // After the number of failed login attempts reaches FAILED_LOGIN_ATTEMPTS, check the account lock status. require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "testu5", Hostname: "localhost"}, - sha1Password("password"), nil)) + sha1Password("password"), nil, nil)) checkUserUserAttributes(tk, "testu5", "localhost", "2 \"Y\" 2 1 {\"comment\": \"testcomment\"}") // After the account is locked, manually unlock the account and check the user_attributes value. tk.MustExec("alter user testu5@'localhost' account unlock") @@ -836,19 +836,19 @@ func TestFailedLoginTracking(t *testing.T) { "comment 'testcomment'") // Confirm the user_attributes value after login failure once. require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "testu6", Hostname: "localhost"}, - sha1Password("password"), nil)) + sha1Password("password"), nil, nil)) checkUserUserAttributes(tk, "testu6", "localhost", "2 \"N\" 1 1 {\"comment\": \"testcomment\"}") // After the number of failed login attempts reaches FAILED_LOGIN_ATTEMPTS, check the account lock status. require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "testu6", Hostname: "localhost"}, - sha1Password("password"), nil)) + sha1Password("password"), nil, nil)) checkUserUserAttributes(tk, "testu6", "localhost", "2 \"Y\" 2 1 {\"comment\": \"testcomment\"}") // After the account is automatically locked, change the lock time and check // the user_attributes value after logging in successfully. changeAutoLockedLastChanged(tk, "-72h1s", "testu6") sk1 := testkit.NewTestKit(t, store) - require.NoError(t, sk1.Session().Auth(&auth.UserIdentity{Username: "testu6", Hostname: "localhost"}, nil, nil)) + require.NoError(t, sk1.Session().Auth(&auth.UserIdentity{Username: "testu6", Hostname: "localhost"}, nil, nil, nil)) checkUserUserAttributes(tk, "testu6", "localhost", "3 \"N\" 0 3 {\"comment\": \"testcomment\"}") // Create user specified attributes, FAILED_LOGIN_ATTEMPTS, and PASSWORD_LOCK_TIME, @@ -859,12 +859,12 @@ func TestFailedLoginTracking(t *testing.T) { // Confirm the user_attributes value after login failure once. require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "testu7", Hostname: "localhost"}, - sha1Password("password"), nil)) + sha1Password("password"), nil, nil)) checkUserUserAttributes(tk, "testu7", "localhost", "2 \"N\" 1 1 {\"attribute\": \"testattribute\"}") // After the number of failed login attempts reaches FAILED_LOGIN_ATTEMPTS, check the account lock status. require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "testu7", Hostname: "localhost"}, - sha1Password("password"), nil)) + sha1Password("password"), nil, nil)) checkUserUserAttributes(tk, "testu7", "localhost", "2 \"Y\" 2 1 {\"attribute\": \"testattribute\"}") // After the account is locked, manually unlock the account and check the user_attributes value. @@ -875,19 +875,19 @@ func TestFailedLoginTracking(t *testing.T) { " ATTRIBUTE '{\"attribute\":\"testattribute\"}'") // Confirm the user_attributes value after login failure once. require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "testu8", Hostname: "localhost"}, - sha1Password("password"), nil)) + sha1Password("password"), nil, nil)) checkUserUserAttributes(tk, "testu8", "localhost", "2 \"N\" 1 1 {\"attribute\": \"testattribute\"}") // After the number of failed login attempts reaches FAILED_LOGIN_ATTEMPTS, check the account lock status. require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "testu8", Hostname: "localhost"}, - sha1Password("password"), nil)) + sha1Password("password"), nil, nil)) checkUserUserAttributes(tk, "testu8", "localhost", "2 \"Y\" 2 1 {\"attribute\": \"testattribute\"}") // After the account is automatically locked, change the lock time and check // the user_attributes value after logging in successfully. changeAutoLockedLastChanged(tk, "-72h1s", "testu8") sk2 := testkit.NewTestKit(t, store) - require.NoError(t, sk2.Session().Auth(&auth.UserIdentity{Username: "testu8", Hostname: "localhost"}, nil, nil)) + require.NoError(t, sk2.Session().Auth(&auth.UserIdentity{Username: "testu8", Hostname: "localhost"}, nil, nil, nil)) checkUserUserAttributes(tk, "testu8", "localhost", "3 \"N\" 0 3 {\"attribute\": \"testattribute\"}") // FAILED_LOGIN_ATTEMPTS is set to 2 . check user_attributes value after @@ -895,24 +895,24 @@ func TestFailedLoginTracking(t *testing.T) { tk.MustExec("create user testu9@'localhost' identified by '' FAILED_LOGIN_ATTEMPTS 2 PASSWORD_LOCK_TIME 1" + " comment 'testcomment'") require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "testu9", Hostname: "localhost"}, - sha1Password("password"), nil)) + sha1Password("password"), nil, nil)) checkUserUserAttributes(tk, "testu9", "localhost", "2 \"N\" 1 1 {\"comment\": \"testcomment\"}") sk3 := testkit.NewTestKit(t, store) require.NoError(t, sk3.Session().Auth(&auth.UserIdentity{Username: "testu9", Hostname: "localhost"}, - nil, nil)) + nil, nil, nil)) checkUserUserAttributes(tk, "testu9", "localhost", "2 \"N\" 0 1 {\"comment\": \"testcomment\"}") // FAILED_LOGIN_ATTEMPTS or PASSWORD_LOCK_TIME is set to 0. Check user_attributes value after login fail. tk.MustExec("create user testu10@'localhost' identified by '' FAILED_LOGIN_ATTEMPTS 2 PASSWORD_LOCK_TIME 0 " + "comment 'testcomment'") require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "testu10", Hostname: "localhost"}, - sha1Password("password"), nil)) + sha1Password("password"), nil, nil)) checkUserUserAttributes(tk, "testu10", "localhost", "2 0 {\"comment\": \"testcomment\"}") tk.MustExec("create user testu11@'localhost' identified by '' FAILED_LOGIN_ATTEMPTS 0 PASSWORD_LOCK_TIME 2 " + "comment 'testcomment'") require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "testu11", Hostname: "localhost"}, - sha1Password("password"), nil)) + sha1Password("password"), nil, nil)) checkUserUserAttributes(tk, "testu11", "localhost", "0 2 {\"comment\": \"testcomment\"}") // The account is automatically locked after the user specifies FAILED_LOGIN_ATTEMPTS and PASSWORD_LOCK_TIME. @@ -920,15 +920,15 @@ func TestFailedLoginTracking(t *testing.T) { tk.MustExec("create user testu12@'localhost' identified by '' FAILED_LOGIN_ATTEMPTS 2 PASSWORD_LOCK_TIME 1 " + "comment 'testcomment'") require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "testu12", Hostname: "localhost"}, - sha1Password("password"), nil)) + sha1Password("password"), nil, nil)) require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "testu12", Hostname: "localhost"}, - sha1Password("password"), nil)) + sha1Password("password"), nil, nil)) checkUserUserAttributes(tk, "testu12", "localhost", "2 \"Y\" 2 1 {\"comment\": \"testcomment\"}") tk.MustExec("alter user testu12@'localhost' FAILED_LOGIN_ATTEMPTS 0") checkUserUserAttributes(tk, "testu12", "localhost", "0 \"Y\" 2 1 {\"comment\": \"testcomment\"}") sk4 := testkit.NewTestKit(t, store) require.NoError(t, sk4.Session().Auth(&auth.UserIdentity{Username: "testu12", Hostname: "localhost"}, - nil, nil)) + nil, nil, nil)) rootk := testkit.NewTestKit(t, store) createAndCheck(tk, "CREATE USER 'u6'@'localhost' IDENTIFIED BY '' FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 3", @@ -936,59 +936,59 @@ func TestFailedLoginTracking(t *testing.T) { createAndCheck(tk, "CREATE USER 'u5'@'localhost' IDENTIFIED BY '' FAILED_LOGIN_ATTEMPTS 60 PASSWORD_LOCK_TIME 3", "{\"Password_locking\": {\"failed_login_attempts\": 60, \"password_lock_time_days\": 3}}", "u5") - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil, nil)) checkAuthUser(t, rootk, "u6", 1, "N") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, nil, nil, nil)) checkAuthUser(t, rootk, "u6", 0, "N") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil, nil)) - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil, nil)) checkAuthUser(t, rootk, "u6", 1, "N") - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil, nil)) checkAuthUser(t, rootk, "u6", 2, "N") - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil, nil)) checkAuthUser(t, rootk, "u6", 3, "Y") changeAutoLockedLastChanged(rootk, "-72h1s", "u6") loadUser(t, tk, 1, rootk) checkAuthUser(t, rootk, "u6", 3, "Y") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, nil, nil, nil)) checkAuthUser(t, rootk, "u6", 0, "N") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil, nil)) - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil, nil)) checkAuthUser(t, rootk, "u6", 1, "N") - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil, nil)) checkAuthUser(t, rootk, "u6", 2, "N") - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil, nil)) checkAuthUser(t, rootk, "u6", 3, "Y") alterAndCheck(t, rootk, "ALTER USER 'u6'@'localhost' ACCOUNT UNLOCK;", "u6", 3, 3, 0) loadUser(t, tk, 2, rootk) checkAuthUser(t, rootk, "u6", 0, "N") - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil, nil)) checkAuthUser(t, rootk, "u6", 1, "N") alterAndCheck(t, rootk, "ALTER USER 'u6'@'localhost' ACCOUNT UNLOCK;", "u6", 3, 3, 0) checkAuthUser(t, rootk, "u6", 0, "N") - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil, nil)) checkAuthUser(t, rootk, "u6", 1, "N") - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil, nil)) checkAuthUser(t, rootk, "u6", 2, "N") - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil, nil)) checkAuthUser(t, rootk, "u6", 3, "Y") changeAutoLockedLastChanged(rootk, "-72h1s", "u6") loadUser(t, tk, 3, rootk) checkAuthUser(t, rootk, "u6", 3, "Y") - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil, nil)) checkAuthUser(t, rootk, "u6", 1, "N") createAndCheck(rootk, "CREATE USER 'u1'@'localhost' IDENTIFIED BY '' FAILED_LOGIN_ATTEMPTS 3", "{\"Password_locking\": {\"failed_login_attempts\": 3, \"password_lock_time_days\": 0}}", "u1") - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u6", Hostname: "localhost"}, sha1Password("password"), nil, nil)) checkAuthUser(t, rootk, "u1", 0, "") alterAndCheck(t, rootk, "ALTER USER 'u1'@'localhost' PASSWORD_LOCK_TIME 6;", "u1", 3, 6, 0) - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost"}, sha1Password("password"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost"}, sha1Password("password"), nil, nil)) checkAuthUser(t, rootk, "u1", 1, "N") } @@ -1061,7 +1061,7 @@ func TestFailedLoginTrackingAlterUser(t *testing.T) { tk.MustExec("CREATE USER 'testu7'@'localhost' IDENTIFIED BY 'testu7' FAILED_LOGIN_ATTEMPTS 1 " + "PASSWORD_LOCK_TIME 1 comment 'testcomment'") require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "testu7", Hostname: "localhost"}, - sha1Password("password"), nil)) + sha1Password("password"), nil, nil)) checkUserUserAttributes(tk, "testu7", "localhost", "1 \"Y\" 1 1 {\"comment\": \"testcomment\"}") tk.MustExec("alter user 'testu7'@'localhost' FAILED_LOGIN_ATTEMPTS 0 PASSWORD_LOCK_TIME 0") tk.MustQuery("select JSON_EXTRACT(user_attributes, '$.Password_locking'),JSON_EXTRACT(user_attributes,'$.metadata') " + @@ -1116,12 +1116,12 @@ func TestFailedLoginTrackingAlterUser(t *testing.T) { err := domain.GetDomain(rootTK.Session()).NotifyUpdatePrivilege() require.NoError(t, err) rootTK.MustExec(`CREATE USER test1 IDENTIFIED BY '1234' FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 3 COMMENT 'test'`) - err = tk.Session().Auth(&auth.UserIdentity{Username: "test1", Hostname: "%"}, sha1Password("1234"), nil) + err = tk.Session().Auth(&auth.UserIdentity{Username: "test1", Hostname: "%"}, sha1Password("1234"), nil, nil) require.NoError(t, err) sqlexec.MustFormatSQL(sql, checkUserAttributes, "test1", "%") rootTK.MustQuery(sql.String()).Check(testkit.Rows(`3 3 {"comment": "test"}`)) tk = testkit.NewTestKit(t, store) - err = tk.Session().Auth(&auth.UserIdentity{Username: "test1", Hostname: "%"}, sha1Password(""), nil) + err = tk.Session().Auth(&auth.UserIdentity{Username: "test1", Hostname: "%"}, sha1Password(""), nil, nil) require.Error(t, err) rootTK.MustQuery(sql.String()).Check(testkit.Rows(`3 "N" 1 3 {"comment": "test"}`)) @@ -1134,9 +1134,9 @@ func TestFailedLoginTrackingAlterUser(t *testing.T) { rootTK.MustExec(`Alter user test1 FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 3 COMMENT 'test'`) rootTK.MustQuery(sql.String()).Check(testkit.Rows(`3 "N" 1 3 {"comment": "test"}`)) - err = tk.Session().Auth(&auth.UserIdentity{Username: "test1", Hostname: "%"}, sha1Password(""), nil) + err = tk.Session().Auth(&auth.UserIdentity{Username: "test1", Hostname: "%"}, sha1Password(""), nil, nil) require.Error(t, err) - err = tk.Session().Auth(&auth.UserIdentity{Username: "test1", Hostname: "%"}, sha1Password(""), nil) + err = tk.Session().Auth(&auth.UserIdentity{Username: "test1", Hostname: "%"}, sha1Password(""), nil, nil) require.Error(t, err) rootTK.MustQuery(sql.String()).Check(testkit.Rows(`3 "Y" 3 3 {"comment": "test"}`)) rootTK.MustExec(`Alter user test1 FAILED_LOGIN_ATTEMPTS 4 `) @@ -1166,7 +1166,7 @@ func TestFailedLoginTrackingCheckPrivilges(t *testing.T) { tk := testkit.NewTestKit(t, store) createAndCheck(tk, "CREATE USER 'testu1'@'localhost' IDENTIFIED BY '' FAILED_LOGIN_ATTEMPTS 1 PASSWORD_LOCK_TIME 1", "{\"Password_locking\": {\"failed_login_attempts\": 1, \"password_lock_time_days\": 1}}", "testu1") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "testu1", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "testu1", Hostname: "localhost"}, nil, nil, nil)) // Specify FAILED_LOGIN_ATTEMPTS and PASSWORD_LOCK_TIME attributes when creating user , // Check user privileges after successful login. tk.MustQuery(`show grants`).Check(testkit.Rows("GRANT USAGE ON *.* TO 'testu1'@'localhost'")) @@ -1210,9 +1210,9 @@ func TestUserPassword(t *testing.T) { tk := testkit.NewTestKit(t, store) rootk := testkit.NewTestKit(t, store) createAndCheckToErr(t, rootk, tc.errSQL, tc.user) - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: tc.user, Hostname: tc.host}, sha1Password(tc.simplePassword), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: tc.user, Hostname: tc.host}, sha1Password(tc.simplePassword), nil, nil)) createAndCheck(rootk, tc.sucSQL, tc.rsJSON, tc.user) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: tc.user, Hostname: tc.host}, sha1Password(tc.strongPassword), nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: tc.user, Hostname: tc.host}, sha1Password(tc.strongPassword), nil, nil)) } } @@ -1224,16 +1224,16 @@ func TestPasswordExpiredAndTacking(t *testing.T) { tk.MustExec(`set global validate_password.enable = ON`) tk = testkit.NewTestKit(t, store) createAndCheckToErr(t, tk, `CREATE USER 'u3'@'localhost' IDENTIFIED BY 'qwe123' PASSWORD EXPIRE INTERVAL 3 DAY FAILED_LOGIN_ATTEMPTS 4 PASSWORD_LOCK_TIME 3 COMMENT 'Some statements to test create user'`, user) - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: user, Hostname: host}, sha1Password("qwe123"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: user, Hostname: host}, sha1Password("qwe123"), nil, nil)) tk = testkit.NewTestKit(t, store) createAndCheck(tk, `CREATE USER 'u3'@'localhost' IDENTIFIED BY '!@#HASHhs123' PASSWORD EXPIRE INTERVAL 3 DAY FAILED_LOGIN_ATTEMPTS 4 PASSWORD_LOCK_TIME 3 COMMENT 'Some statements to test create user'`, "{\"Password_locking\": {\"failed_login_attempts\": 4, \"password_lock_time_days\": 3}, \"metadata\": {\"comment\": \"Some statements to test create user\"}}", user) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: user, Hostname: host}, sha1Password("!@#HASHhs123"), nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: user, Hostname: host}, sha1Password("!@#HASHhs123"), nil, nil)) tk = testkit.NewTestKit(t, store) tk.MustExec(fmt.Sprintf("ALTER USER '%s'@'%s' PASSWORD EXPIRE NEVER", user, host)) tk = testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: user, Hostname: host}, sha1Password("!@#HASHhs123"), nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: user, Hostname: host}, sha1Password("!@#HASHhs123"), nil, nil)) loginFailedAncCheck(t, store, user, host, "password", 1, "N") loginSucAncCheck(t, store, user, host, "!@#HASHhs123", 0, "N") @@ -1245,24 +1245,24 @@ func TestPasswordExpiredAndTacking(t *testing.T) { tk = testkit.NewTestKit(t, store) tk.MustExec(fmt.Sprintf("ALTER USER '%s'@'%s' PASSWORD EXPIRE", user, host)) tk = testkit.NewTestKit(t, store) - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: user, Hostname: host}, sha1Password("!@#HASHhs123"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: user, Hostname: host}, sha1Password("!@#HASHhs123"), nil, nil)) } func loginFailedAncCheck(t *testing.T, store kv.Storage, user, host, password string, failedLoginCount int64, autoAccountLocked string) { tk := testkit.NewTestKit(t, store) - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: user, Hostname: host}, sha1Password(password), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: user, Hostname: host}, sha1Password(password), nil, nil)) checkAuthUser(t, tk, user, failedLoginCount, autoAccountLocked) } func loginSucAncCheck(t *testing.T, store kv.Storage, user, host, password string, failedLoginCount int64, autoAccountLocked string) { tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: user, Hostname: host}, sha1Password(password), nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: user, Hostname: host}, sha1Password(password), nil, nil)) tk = testkit.NewTestKit(t, store) checkAuthUser(t, tk, user, failedLoginCount, autoAccountLocked) } func loadUser(t *testing.T, tk *testkit.TestKit, useCount int64, rootk *testkit.TestKit) { - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u5", Hostname: "localhost"}, sha1Password("password"), nil)) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "u5", Hostname: "localhost"}, sha1Password("password"), nil, nil)) checkAuthUser(t, rootk, "u5", useCount, "N") } diff --git a/executor/test/showtest/show_test.go b/executor/test/showtest/show_test.go index 3911f4e1a9934..11bbb73a671b5 100644 --- a/executor/test/showtest/show_test.go +++ b/executor/test/showtest/show_test.go @@ -60,7 +60,7 @@ func TestShowOpenTables(t *testing.T) { func TestShowCreateViewDefiner(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%", AuthUsername: "root", AuthHostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%", AuthUsername: "root", AuthHostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("create or replace view v1 as select 1") @@ -680,7 +680,7 @@ func TestShowVisibility(t *testing.T) { tk.MustExec(`create user 'show'@'%'`) tk1 := testkit.NewTestKit(t, store) - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "show", Hostname: "%"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "show", Hostname: "%"}, nil, nil, nil)) // No ShowDatabases privilege, this user would see nothing except INFORMATION_SCHEMA. tk.MustQuery("show databases").Check(testkit.Rows("INFORMATION_SCHEMA")) @@ -718,7 +718,7 @@ func TestShowDatabasesInfoSchemaFirst(t *testing.T) { tk.MustExec(`grant select on BBBB.* to 'show'@'%'`) tk1 := testkit.NewTestKit(t, store) - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "show", Hostname: "%"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "show", Hostname: "%"}, nil, nil, nil)) tk1.MustQuery("show databases").Check(testkit.Rows("INFORMATION_SCHEMA", "AAAA", "BBBB")) tk.MustExec(`drop user 'show'@'%'`) @@ -822,12 +822,12 @@ func TestShowGrantsPrivilege(t *testing.T) { tk.MustExec("create user show_grants") tk.MustExec("show grants for show_grants") tk1 := testkit.NewTestKit(t, store) - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "show_grants", Hostname: "%"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "show_grants", Hostname: "%"}, nil, nil, nil)) err := tk1.QueryToErr("show grants for root") require.EqualError(t, exeerrors.ErrDBaccessDenied.GenWithStackByArgs("show_grants", "%", mysql.SystemDB), err.Error()) // Test show grants for user with auth host name `%`. tk2 := testkit.NewTestKit(t, store) - require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{Username: "show_grants", Hostname: "127.0.0.1", AuthUsername: "show_grants", AuthHostname: "%"}, nil, nil)) + require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{Username: "show_grants", Hostname: "127.0.0.1", AuthUsername: "show_grants", AuthHostname: "%"}, nil, nil, nil)) tk2.MustQuery("show grants") } @@ -837,7 +837,7 @@ func TestShowStatsPrivilege(t *testing.T) { tk.MustExec("create user show_stats") tk1 := testkit.NewTestKit(t, store) - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "show_stats", Hostname: "%"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "show_stats", Hostname: "%"}, nil, nil, nil)) e := "[planner:1142]SHOW command denied to user 'show_stats'@'%' for table" err := tk1.ExecToErr("show stats_meta") require.ErrorContains(t, err, e) @@ -856,7 +856,7 @@ func TestShowStatsPrivilege(t *testing.T) { tk1.MustExec("SHOW STATS_HISTOGRAMS") tk.MustExec("create user a@'%' identified by '';") - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "a", Hostname: "%"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "a", Hostname: "%"}, nil, nil, nil)) tk.MustExec("grant select on mysql.stats_meta to a@'%';") tk.MustExec("grant select on mysql.stats_buckets to a@'%';") tk.MustExec("grant select on mysql.stats_histograms to a@'%';") @@ -868,7 +868,7 @@ func TestShowStatsPrivilege(t *testing.T) { func TestIssue18878(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "127.0.0.1", AuthHostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "127.0.0.1", AuthHostname: "%"}, nil, nil, nil)) tk.MustQuery("select user()").Check(testkit.Rows("root@127.0.0.1")) tk.MustQuery("show grants") tk.MustQuery("select user()").Check(testkit.Rows("root@127.0.0.1")) @@ -888,10 +888,10 @@ func TestIssue17794(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("CREATE USER 'root'@'8.8.%'") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "9.9.9.9", AuthHostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "9.9.9.9", AuthHostname: "%"}, nil, nil, nil)) tk1 := testkit.NewTestKit(t, store) - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "8.8.8.8", AuthHostname: "8.8.%"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "8.8.8.8", AuthHostname: "8.8.%"}, nil, nil, nil)) tk.MustQuery("show grants").Check(testkit.Rows("GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION")) tk1.MustQuery("show grants").Check(testkit.Rows("GRANT USAGE ON *.* TO 'root'@'8.8.%'")) } @@ -913,7 +913,7 @@ func TestIssue10549(t *testing.T) { tk.MustExec("GRANT 'app_developer' TO 'dev';") tk.MustExec("SET DEFAULT ROLE app_developer TO 'dev';") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "dev", Hostname: "%", AuthUsername: "dev", AuthHostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "dev", Hostname: "%", AuthUsername: "dev", AuthHostname: "%"}, nil, nil, nil)) tk.MustQuery("SHOW DATABASES;").Check(testkit.Rows("INFORMATION_SCHEMA", "newdb")) tk.MustQuery("SHOW GRANTS;").Check(testkit.Rows("GRANT USAGE ON *.* TO 'dev'@'%'", "GRANT ALL PRIVILEGES ON newdb.* TO 'dev'@'%'", "GRANT 'app_developer'@'%' TO 'dev'@'%'")) tk.MustQuery("SHOW GRANTS FOR CURRENT_USER").Check(testkit.Rows("GRANT USAGE ON *.* TO 'dev'@'%'", "GRANT ALL PRIVILEGES ON newdb.* TO 'dev'@'%'", "GRANT 'app_developer'@'%' TO 'dev'@'%'")) @@ -927,7 +927,7 @@ func TestIssue11165(t *testing.T) { tk.MustExec("CREATE USER 'manager'@'localhost';") tk.MustExec("GRANT 'r_manager' TO 'manager'@'localhost';") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "manager", Hostname: "localhost", AuthUsername: "manager", AuthHostname: "localhost"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "manager", Hostname: "localhost", AuthUsername: "manager", AuthHostname: "localhost"}, nil, nil, nil)) tk.MustExec("SET DEFAULT ROLE ALL TO 'manager'@'localhost';") tk.MustExec("SET DEFAULT ROLE NONE TO 'manager'@'localhost';") tk.MustExec("SET DEFAULT ROLE 'r_manager' TO 'manager'@'localhost';") @@ -1048,7 +1048,7 @@ func TestShow2(t *testing.T) { createTime := model.TSConvert2Time(tblInfo.Meta().UpdateTS).Format(time.DateTime) // The Hostname is the actual host - tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "192.168.0.1", AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890")) + tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "192.168.0.1", AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) r := tk.MustQuery("show table status from test like 't'") r.Check(testkit.Rows(fmt.Sprintf("t InnoDB 10 Compact 0 0 0 0 0 0 %s utf8mb4_bin 注释", createTime))) @@ -1082,7 +1082,7 @@ func TestShowCreateUser(t *testing.T) { err = tk.QueryToErr("show create user 'aaa'@'localhost';") require.Equal(t, exeerrors.ErrCannotUser.GenWithStackByArgs("SHOW CREATE USER", "'aaa'@'localhost'").Error(), err.Error()) - tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "127.0.0.1", AuthUsername: "root", AuthHostname: "%"}, nil, nil) + tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "127.0.0.1", AuthUsername: "root", AuthHostname: "%"}, nil, nil, nil) tk.MustQuery("show create user current_user"). Check(testkit.Rows("CREATE USER 'root'@'127.0.0.1' IDENTIFIED WITH 'mysql_native_password' AS '' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT")) @@ -1094,7 +1094,7 @@ func TestShowCreateUser(t *testing.T) { // "show create user" for other user requires the SELECT privilege on mysql database. tk1 := testkit.NewTestKit(t, store) tk1.MustExec("use mysql") - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "check_priv", Hostname: "127.0.0.1", AuthUsername: "test_show", AuthHostname: "asdf"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "check_priv", Hostname: "127.0.0.1", AuthUsername: "test_show", AuthHostname: "asdf"}, nil, nil, nil)) err = tk1.QueryToErr("show create user 'root'@'%'") require.Error(t, err) @@ -1176,14 +1176,14 @@ func TestUnprivilegedShow(t *testing.T) { tk.MustExec(`CREATE USER 'lowprivuser'`) // no grants - tk.Session().Auth(&auth.UserIdentity{Username: "lowprivuser", Hostname: "192.168.0.1", AuthUsername: "lowprivuser", AuthHostname: "%"}, nil, []byte("012345678901234567890")) + tk.Session().Auth(&auth.UserIdentity{Username: "lowprivuser", Hostname: "192.168.0.1", AuthUsername: "lowprivuser", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) rs, err := tk.Exec("SHOW TABLE STATUS FROM testshow") require.NoError(t, err) require.NotNil(t, rs) - tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "192.168.0.1", AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890")) + tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "192.168.0.1", AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) tk.MustExec("GRANT ALL ON testshow.t1 TO 'lowprivuser'") - tk.Session().Auth(&auth.UserIdentity{Username: "lowprivuser", Hostname: "192.168.0.1", AuthUsername: "lowprivuser", AuthHostname: "%"}, nil, []byte("012345678901234567890")) + tk.Session().Auth(&auth.UserIdentity{Username: "lowprivuser", Hostname: "192.168.0.1", AuthUsername: "lowprivuser", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) is := dom.InfoSchema() tblInfo, err := is.TableByName(model.NewCIStr("testshow"), model.NewCIStr("t1")) @@ -1217,7 +1217,7 @@ func TestShowTableStatus(t *testing.T) { tk.MustExec(`drop table if exists t;`) tk.MustExec(`create table t(a bigint);`) - tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "192.168.0.1", AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890")) + tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "192.168.0.1", AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) // It's not easy to test the result contents because every time the test runs, "Create_time" changed. tk.MustExec("show table status;") @@ -1922,7 +1922,7 @@ func TestShowDatabasesLike(t *testing.T) { tk := testkit.NewTestKit(t, store) require.NoError(t, tk.Session().Auth(&auth.UserIdentity{ - Username: "root", Hostname: "%"}, nil, nil)) + Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("DROP DATABASE IF EXISTS `TEST_$1`") tk.MustExec("DROP DATABASE IF EXISTS `test_$2`") @@ -1959,7 +1959,7 @@ func TestShowCollationsLike(t *testing.T) { tk := testkit.NewTestKit(t, store) require.NoError(t, tk.Session().Auth(&auth.UserIdentity{ - Username: "root", Hostname: "%"}, nil, nil)) + Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustQuery("SHOW COLLATION LIKE 'UTF8MB4_BI%'").Check(testkit.Rows("utf8mb4_bin utf8mb4 46 Yes Yes 1")) tk.MustQuery("SHOW COLLATION LIKE 'utf8mb4_bi%'").Check(testkit.Rows("utf8mb4_bin utf8mb4 46 Yes Yes 1")) } diff --git a/executor/test/simpletest/simple_test.go b/executor/test/simpletest/simple_test.go index 7cf76d7590def..173302d088741 100644 --- a/executor/test/simpletest/simple_test.go +++ b/executor/test/simpletest/simple_test.go @@ -97,7 +97,7 @@ func TestIssue9111(t *testing.T) { se, err := session.CreateSession4Test(store) require.NoError(t, err) defer se.Close() - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "user_admin", Hostname: "localhost"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "user_admin", Hostname: "localhost"}, nil, nil, nil)) ctx := context.Background() _, err = se.Execute(ctx, `create user test_create_user`) @@ -149,7 +149,7 @@ func TestExtendedStatsPrivileges(t *testing.T) { se, err := session.CreateSession4Test(store) require.NoError(t, err) defer se.Close() - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "u1", Hostname: "%"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "u1", Hostname: "%"}, nil, nil, nil)) ctx := context.Background() _, err = se.Execute(ctx, "set session tidb_enable_extended_stats = on") require.NoError(t, err) @@ -187,7 +187,7 @@ func TestIssue17247(t *testing.T) { tk1 := testkit.NewTestKit(t, store) tk1.MustExec("use test") - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "issue17247", Hostname: "%"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "issue17247", Hostname: "%"}, nil, nil, nil)) tk1.MustExec("ALTER USER USER() IDENTIFIED BY 'xxx'") tk1.MustExec("ALTER USER CURRENT_USER() IDENTIFIED BY 'yyy'") tk1.MustExec("ALTER USER CURRENT_USER IDENTIFIED BY 'zzz'") @@ -219,10 +219,10 @@ func TestSetCurrentUserPwd(t *testing.T) { tk.MustExec("DROP USER IF EXISTS issue28534;") }() - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "issue28534", Hostname: "localhost", CurrentUser: true, AuthUsername: "issue28534", AuthHostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "issue28534", Hostname: "localhost", CurrentUser: true, AuthUsername: "issue28534", AuthHostname: "%"}, nil, nil, nil)) tk.MustExec(`SET PASSWORD FOR CURRENT_USER() = "43582eussi"`) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) result := tk.MustQuery(`SELECT authentication_string FROM mysql.User WHERE User="issue28534"`) result.Check(testkit.Rows(auth.EncodePassword("43582eussi"))) } @@ -237,7 +237,7 @@ func TestShowGrantsAfterDropRole(t *testing.T) { tk.MustExec("GRANT r29473 TO u29473") tk.MustExec("GRANT CREATE USER ON *.* TO u29473") - tk.Session().Auth(&auth.UserIdentity{Username: "u29473", Hostname: "%"}, nil, nil) + tk.Session().Auth(&auth.UserIdentity{Username: "u29473", Hostname: "%"}, nil, nil, nil) tk.MustExec("SET ROLE r29473") tk.MustExec("DROP ROLE r29473") tk.MustQuery("SHOW GRANTS").Check(testkit.Rows("GRANT CREATE USER ON *.* TO 'u29473'@'%'")) @@ -262,7 +262,7 @@ func TestPrivilegesAfterDropUser(t *testing.T) { tk.MustQuery("SELECT COUNT(1) FROM mysql.global_priv WHERE USER='u1' AND HOST='%'").Check(testkit.Rows("1")) tk.MustQuery("SELECT COUNT(1) FROM mysql.tables_priv WHERE USER='u1' AND HOST='%'").Check(testkit.Rows("1")) tk.MustQuery("SELECT COUNT(1) FROM mysql.columns_priv WHERE USER='u1' AND HOST='%'").Check(testkit.Rows("1")) - tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil) + tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil) tk.MustQuery("SHOW GRANTS FOR u1").Check(testkit.Rows( "GRANT USAGE ON *.* TO 'u1'@'%'", "GRANT CREATE ON test.* TO 'u1'@'%'", @@ -285,7 +285,7 @@ func TestDropRoleAfterRevoke(t *testing.T) { // issue 29781 tk := testkit.NewTestKit(t, store) tk.MustExec("use test;") - tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil) + tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil) tk.MustExec("create role r1, r2, r3;") defer tk.MustExec("drop role if exists r1, r2, r3;") @@ -377,7 +377,7 @@ func TestSetRoleAllCorner(t *testing.T) { se, err := session.CreateSession4Test(store) require.NoError(t, err) defer se.Close() - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "set_role_all", Hostname: "localhost"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "set_role_all", Hostname: "localhost"}, nil, nil, nil)) ctx := context.Background() _, err = se.Execute(ctx, `set role all`) require.NoError(t, err) @@ -393,7 +393,7 @@ func TestCreateRole(t *testing.T) { se, err := session.CreateSession4Test(store) require.NoError(t, err) defer se.Close() - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "testCreateRole", Hostname: "localhost"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "testCreateRole", Hostname: "localhost"}, nil, nil, nil)) ctx := context.Background() _, err = se.Execute(ctx, `create role test_create_role;`) @@ -418,7 +418,7 @@ func TestDropRole(t *testing.T) { se, err := session.CreateSession4Test(store) require.NoError(t, err) defer se.Close() - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "testCreateRole", Hostname: "localhost"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "testCreateRole", Hostname: "localhost"}, nil, nil, nil)) ctx := context.Background() _, err = se.Execute(ctx, `drop role test_create_role;`) @@ -600,7 +600,7 @@ func TestRoleAdmin(t *testing.T) { se, err := session.CreateSession4Test(store) require.NoError(t, err) defer se.Close() - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "testRoleAdmin", Hostname: "localhost"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "testRoleAdmin", Hostname: "localhost"}, nil, nil, nil)) ctx := context.Background() _, err = se.Execute(ctx, "GRANT `targetRole` TO `testRoleAdmin`;") @@ -674,7 +674,7 @@ func TestSetDefaultRoleAll(t *testing.T) { se, err := session.CreateSession4Test(store) require.NoError(t, err) defer se.Close() - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "test_all", Hostname: "localhost"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "test_all", Hostname: "localhost"}, nil, nil, nil)) ctx := context.Background() _, err = se.Execute(ctx, "set default role all to test_all;") @@ -932,7 +932,7 @@ func TestFlushPrivileges(t *testing.T) { se, err := session.CreateSession4Test(store) require.NoError(t, err) defer se.Close() - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "testflush", Hostname: "localhost"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "testflush", Hostname: "localhost"}, nil, nil, nil)) ctx := context.Background() // Before flush. diff --git a/extension/function_test.go b/extension/function_test.go index 86fcd0be845c3..06fa301543525 100644 --- a/extension/function_test.go +++ b/extension/function_test.go @@ -104,7 +104,7 @@ func TestExtensionFuncCtx(t *testing.T) { tk.MustExec("grant ALL ON test.* to u1@localhost") tk1 := testkit.NewTestKit(t, store) - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost"}, nil, nil, nil)) tk1.MustExec("set role r1") tk1.MustExec("use test") tk1.Session().GetSessionVars().ConnectionInfo = &variable.ConnectionInfo{ @@ -344,35 +344,35 @@ func TestExtensionFuncPrivilege(t *testing.T) { tk1 := testkit.NewTestKit(t, store) // root has all privileges by default - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil, nil)) tk1.MustQuery("select custom_no_priv_func()").Check(testkit.Rows("zzz")) tk1.MustQuery("select custom_only_dyn_priv_func()").Check(testkit.Rows("abc")) tk1.MustQuery("select custom_only_sem_dyn_priv_func()").Check(testkit.Rows("def")) tk1.MustQuery("select custom_both_dyn_priv_func()").Check(testkit.Rows("ghi")) // u1 in non-sem - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost"}, nil, nil, nil)) tk1.MustQuery("select custom_no_priv_func()").Check(testkit.Rows("zzz")) require.EqualError(t, tk1.ExecToErr("select custom_only_dyn_priv_func()"), "[expression:1227]Access denied; you need (at least one of) the SUPER or CUSTOM_DYN_PRIV_1 privilege(s) for this operation") tk1.MustQuery("select custom_only_sem_dyn_priv_func()").Check(testkit.Rows("def")) require.EqualError(t, tk1.ExecToErr("select custom_both_dyn_priv_func()"), "[expression:1227]Access denied; you need (at least one of) the SUPER or CUSTOM_DYN_PRIV_1 privilege(s) for this operation") // u2 in non-sem - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u2", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u2", Hostname: "localhost"}, nil, nil, nil)) tk1.MustQuery("select custom_no_priv_func()").Check(testkit.Rows("zzz")) tk1.MustQuery("select custom_only_dyn_priv_func()").Check(testkit.Rows("abc")) tk1.MustQuery("select custom_only_sem_dyn_priv_func()").Check(testkit.Rows("def")) tk1.MustQuery("select custom_both_dyn_priv_func()").Check(testkit.Rows("ghi")) // u3 in non-sem - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u3", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u3", Hostname: "localhost"}, nil, nil, nil)) tk1.MustQuery("select custom_no_priv_func()").Check(testkit.Rows("zzz")) require.EqualError(t, tk1.ExecToErr("select custom_only_dyn_priv_func()"), "[expression:1227]Access denied; you need (at least one of) the SUPER or CUSTOM_DYN_PRIV_1 privilege(s) for this operation") tk1.MustQuery("select custom_only_sem_dyn_priv_func()").Check(testkit.Rows("def")) require.EqualError(t, tk1.ExecToErr("select custom_both_dyn_priv_func()"), "[expression:1227]Access denied; you need (at least one of) the SUPER or CUSTOM_DYN_PRIV_1 privilege(s) for this operation") // u4 in non-sem - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u4", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u4", Hostname: "localhost"}, nil, nil, nil)) tk1.MustQuery("select custom_no_priv_func()").Check(testkit.Rows("zzz")) tk1.MustQuery("select custom_only_dyn_priv_func()").Check(testkit.Rows("abc")) tk1.MustQuery("select custom_only_sem_dyn_priv_func()").Check(testkit.Rows("def")) @@ -381,35 +381,35 @@ func TestExtensionFuncPrivilege(t *testing.T) { sem.Enable() // root in sem - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil, nil)) tk1.MustQuery("select custom_no_priv_func()").Check(testkit.Rows("zzz")) tk1.MustQuery("select custom_only_dyn_priv_func()").Check(testkit.Rows("abc")) require.EqualError(t, tk1.ExecToErr("select custom_only_sem_dyn_priv_func()"), "[expression:1227]Access denied; you need (at least one of) the RESTRICTED_CUSTOM_DYN_PRIV_2 privilege(s) for this operation") require.EqualError(t, tk1.ExecToErr("select custom_both_dyn_priv_func()"), "[expression:1227]Access denied; you need (at least one of) the RESTRICTED_CUSTOM_DYN_PRIV_2 privilege(s) for this operation") // u1 in sem - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost"}, nil, nil, nil)) tk1.MustQuery("select custom_no_priv_func()").Check(testkit.Rows("zzz")) require.EqualError(t, tk1.ExecToErr("select custom_only_dyn_priv_func()"), "[expression:1227]Access denied; you need (at least one of) the CUSTOM_DYN_PRIV_1 privilege(s) for this operation") require.EqualError(t, tk1.ExecToErr("select custom_only_sem_dyn_priv_func()"), "[expression:1227]Access denied; you need (at least one of) the RESTRICTED_CUSTOM_DYN_PRIV_2 privilege(s) for this operation") require.EqualError(t, tk1.ExecToErr("select custom_both_dyn_priv_func()"), "[expression:1227]Access denied; you need (at least one of) the RESTRICTED_CUSTOM_DYN_PRIV_2 privilege(s) for this operation") // u2 in sem - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u2", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u2", Hostname: "localhost"}, nil, nil, nil)) tk1.MustQuery("select custom_no_priv_func()").Check(testkit.Rows("zzz")) tk1.MustQuery("select custom_only_dyn_priv_func()").Check(testkit.Rows("abc")) require.EqualError(t, tk1.ExecToErr("select custom_only_sem_dyn_priv_func()"), "[expression:1227]Access denied; you need (at least one of) the RESTRICTED_CUSTOM_DYN_PRIV_2 privilege(s) for this operation") require.EqualError(t, tk1.ExecToErr("select custom_both_dyn_priv_func()"), "[expression:1227]Access denied; you need (at least one of) the RESTRICTED_CUSTOM_DYN_PRIV_2 privilege(s) for this operation") // u3 in sem - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u3", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u3", Hostname: "localhost"}, nil, nil, nil)) tk1.MustQuery("select custom_no_priv_func()").Check(testkit.Rows("zzz")) require.EqualError(t, tk1.ExecToErr("select custom_only_dyn_priv_func()"), "[expression:1227]Access denied; you need (at least one of) the CUSTOM_DYN_PRIV_1 privilege(s) for this operation") tk1.MustQuery("select custom_only_sem_dyn_priv_func()").Check(testkit.Rows("def")) tk1.MustQuery("select custom_both_dyn_priv_func()").Check(testkit.Rows("ghi")) // u4 in sem - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u4", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "u4", Hostname: "localhost"}, nil, nil, nil)) tk1.MustQuery("select custom_no_priv_func()").Check(testkit.Rows("zzz")) tk1.MustQuery("select custom_only_dyn_priv_func()").Check(testkit.Rows("abc")) tk1.MustQuery("select custom_only_sem_dyn_priv_func()").Check(testkit.Rows("def")) diff --git a/extension/registry_test.go b/extension/registry_test.go index ba1130d815fbf..d353388c07edc 100644 --- a/extension/registry_test.go +++ b/extension/registry_test.go @@ -220,10 +220,10 @@ func TestSetVariablePrivilege(t *testing.T) { tk.MustExec("create user u2@localhost") tk1 := testkit.NewTestKit(t, store) - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil, nil)) tk2 := testkit.NewTestKit(t, store) - require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{Username: "u2", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{Username: "u2", Hostname: "localhost"}, nil, nil, nil)) sem.Disable() tk1.MustExec("set @@var1=7") @@ -297,11 +297,11 @@ func TestCustomAccessCheck(t *testing.T) { tk.MustExec("create user u2@localhost") tk1 := testkit.NewTestKit(t, store) - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil, nil)) tk1.MustExec("use test") tk2 := testkit.NewTestKit(t, store) - require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{Username: "u2", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{Username: "u2", Hostname: "localhost"}, nil, nil, nil)) tk.MustExec("GRANT all on test.t1 TO u2@localhost") tk2.MustExec("use test") diff --git a/infoschema/cluster_tables_test.go b/infoschema/cluster_tables_test.go index c59fd3a13a132..7e0b804a2c54a 100644 --- a/infoschema/cluster_tables_test.go +++ b/infoschema/cluster_tables_test.go @@ -202,7 +202,7 @@ func SubTestDataLockWaitsPrivilege(t *testing.T) { require.NoError(t, tk.Session().Auth(&auth.UserIdentity{ Username: "testuser", Hostname: "localhost", - }, nil, nil)) + }, nil, nil, nil)) err := tk.QueryToErr("select * from information_schema.DATA_LOCK_WAITS") require.EqualError(t, err, "[planner:1227]Access denied; you need (at least one of) the PROCESS privilege(s) for this operation") @@ -213,7 +213,7 @@ func SubTestDataLockWaitsPrivilege(t *testing.T) { require.NoError(t, tk.Session().Auth(&auth.UserIdentity{ Username: "testuser2", Hostname: "localhost", - }, nil, nil)) + }, nil, nil, nil)) _ = tk.MustQuery("select * from information_schema.DATA_LOCK_WAITS") } @@ -318,7 +318,7 @@ select * from t3; require.NoError(t, user1.Session().Auth(&auth.UserIdentity{ Username: "user1", Hostname: "127.0.0.1", - }, nil, nil)) + }, nil, nil, nil)) user1.MustQuery("select count(*) from `CLUSTER_SLOW_QUERY`").Check(testkit.Rows("1")) user1.MustQuery("select count(*) from `SLOW_QUERY`").Check(testkit.Rows("1")) user1.MustQuery("select user,query from `CLUSTER_SLOW_QUERY`").Check(testkit.Rows("user1 select * from t1;")) @@ -328,7 +328,7 @@ select * from t3; require.NoError(t, user2.Session().Auth(&auth.UserIdentity{ Username: "user2", Hostname: "127.0.0.1", - }, nil, nil)) + }, nil, nil, nil)) user2.MustQuery("select count(*) from `CLUSTER_SLOW_QUERY`").Check(testkit.Rows("2")) user2.MustQuery("select user,query from `CLUSTER_SLOW_QUERY` order by query").Check(testkit.Rows("user2 select * from t2;", "user2 select * from t3;")) } @@ -382,7 +382,7 @@ func TestStmtSummaryEvictedCountTable(t *testing.T) { require.NoError(t, tk.Session().Auth(&auth.UserIdentity{ Username: "testuser", Hostname: "localhost", - }, nil, nil)) + }, nil, nil, nil)) err := tk.QueryToErr("select * from information_schema.CLUSTER_STATEMENTS_SUMMARY_EVICTED") // This error is come from cop(TiDB) fetch from rpc server. @@ -391,7 +391,7 @@ func TestStmtSummaryEvictedCountTable(t *testing.T) { require.NoError(t, tk.Session().Auth(&auth.UserIdentity{ Username: "testuser2", Hostname: "localhost", - }, nil, nil)) + }, nil, nil, nil)) require.NoError(t, tk.QueryToErr("select * from information_schema.CLUSTER_STATEMENTS_SUMMARY_EVICTED")) } @@ -418,7 +418,7 @@ func TestStmtSummaryIssue35340(t *testing.T) { require.NoError(t, tk.Session().Auth(&auth.UserIdentity{ Username: user, Hostname: "localhost", - }, nil, nil)) + }, nil, nil, nil)) tk.MustQuery("select count(*) from information_schema.statements_summary;") } }() @@ -815,7 +815,7 @@ func (s *clusterTablesSuite) setUpMockPDHTTPServer() (*httptest.Server, string) func (s *clusterTablesSuite) newTestKitWithRoot(t *testing.T) *testkit.TestKit { tk := testkit.NewTestKit(t, s.store) tk.MustExec("use test") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) return tk } @@ -887,7 +887,7 @@ func TestCreateBindingFromHistory(t *testing.T) { defer s.httpServer.Close() defer s.rpcserver.Stop() tk := s.newTestKitWithRoot(t) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("drop table if exists t") @@ -953,7 +953,7 @@ func TestCreateBindingForPrepareFromHistory(t *testing.T) { defer s.httpServer.Close() defer s.rpcserver.Stop() tk := s.newTestKitWithRoot(t) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("drop table if exists t") @@ -982,7 +982,7 @@ func TestErrorCasesCreateBindingFromHistory(t *testing.T) { defer s.httpServer.Close() defer s.rpcserver.Stop() tk := s.newTestKitWithRoot(t) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("drop table if exists t1, t2, t3") @@ -1056,7 +1056,7 @@ func TestSetBindingStatusBySQLDigest(t *testing.T) { defer s.httpServer.Close() defer s.rpcserver.Stop() tk := s.newTestKitWithRoot(t) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("drop table if exists t") tk.MustExec("create table t(id int, a int, key(a))") @@ -1089,7 +1089,7 @@ func TestCreateBindingWhenCloseStmtSummaryTable(t *testing.T) { defer s.httpServer.Close() defer s.rpcserver.Stop() tk := s.newTestKitWithRoot(t) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("drop table if exists t") @@ -1110,7 +1110,7 @@ func TestCreateBindingForNotSupportedStmt(t *testing.T) { defer s.httpServer.Close() defer s.rpcserver.Stop() tk := s.newTestKitWithRoot(t) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("drop table if exists t") @@ -1141,7 +1141,7 @@ func TestCreateBindingRepeatedly(t *testing.T) { defer s.httpServer.Close() defer s.rpcserver.Stop() tk := s.newTestKitWithRoot(t) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("drop table if exists t") @@ -1213,7 +1213,7 @@ func TestCreateBindingWithUsingKeyword(t *testing.T) { defer s.httpServer.Close() defer s.rpcserver.Stop() tk := s.newTestKitWithRoot(t) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("drop table if exists t, t1, t2") @@ -1251,7 +1251,7 @@ func TestNewCreatedBindingCanWorkWithPlanCache(t *testing.T) { defer s.httpServer.Close() defer s.rpcserver.Stop() tk := s.newTestKitWithRoot(t) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("drop table if exists t, t1, t2") @@ -1279,7 +1279,7 @@ func TestCreateBindingForPrepareToken(t *testing.T) { defer s.httpServer.Close() defer s.rpcserver.Stop() tk := s.newTestKitWithRoot(t) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("drop table if exists t") diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index fd69f1196d855..c0f11cd9580b3 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -50,7 +50,7 @@ import ( func newTestKitWithRoot(t *testing.T, store kv.Storage) *testkit.TestKit { tk := testkit.NewTestKit(t, store) tk.MustExec("use test") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) return tk } @@ -60,7 +60,7 @@ func newTestKitWithPlanCache(t *testing.T, store kv.Storage) *testkit.TestKit { require.NoError(t, err) tk.SetSession(se) tk.RefreshConnectionID() - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) return tk } @@ -126,7 +126,7 @@ func TestInfoSchemaFieldValue(t *testing.T) { require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{ Username: "xxx", Hostname: "127.0.0.1", - }, nil, nil)) + }, nil, nil, nil)) tk1.MustQuery("select distinct(table_schema) from information_schema.tables").Check(testkit.Rows("INFORMATION_SCHEMA")) @@ -1083,7 +1083,7 @@ func TestStmtSummaryTablePrivilege(t *testing.T) { Hostname: "localhost", AuthUsername: "test_user", AuthHostname: "localhost", - }, nil, nil) + }, nil, nil, nil) result = tk1.MustQuery("select * from information_schema.statements_summary where digest_text like 'select * from `t`%'") // Ordinary users can not see others' records @@ -1143,7 +1143,7 @@ func TestCapturePrivilege(t *testing.T) { Hostname: "localhost", AuthUsername: "test_user", AuthHostname: "localhost", - }, nil, nil) + }, nil, nil, nil) rows = tk1.MustQuery("show global bindings").Rows() // Ordinary users can not see others' records @@ -1170,7 +1170,7 @@ func TestIssue18845(t *testing.T) { Hostname: "localhost", AuthUsername: "user18845", AuthHostname: "localhost", - }, nil, nil) + }, nil, nil, nil) tk.MustQuery(`select count(*) from information_schema.columns;`) } @@ -1534,7 +1534,7 @@ func TestInfoSchemaClientErrors(t *testing.T) { errno.IncrementError(1365, "root", "localhost") tk.MustExec("CREATE USER 'infoschematest'@'localhost'") - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "infoschematest", Hostname: "localhost"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "infoschematest", Hostname: "localhost"}, nil, nil, nil)) err := tk.QueryToErr("SELECT * FROM information_schema.client_errors_summary_global") require.Equal(t, "[planner:1227]Access denied; you need (at least one of) the PROCESS privilege(s) for this operation", err.Error()) @@ -1638,7 +1638,7 @@ func TestInfoSchemaDeadlockPrivilege(t *testing.T) { require.NoError(t, tk.Session().Auth(&auth.UserIdentity{ Username: "testuser", Hostname: "localhost", - }, nil, nil)) + }, nil, nil, nil)) err := tk.QueryToErr("select * from information_schema.deadlocks") require.Error(t, err) require.Equal(t, "[planner:1227]Access denied; you need (at least one of) the PROCESS privilege(s) for this operation", err.Error()) @@ -1649,7 +1649,7 @@ func TestInfoSchemaDeadlockPrivilege(t *testing.T) { require.NoError(t, tk.Session().Auth(&auth.UserIdentity{ Username: "testuser2", Hostname: "localhost", - }, nil, nil)) + }, nil, nil, nil)) _ = tk.MustQuery("select * from information_schema.deadlocks") } @@ -1835,7 +1835,7 @@ func TestAddFieldsForBinding(t *testing.T) { defer s.rpcserver.Stop() tk := s.newTestKitWithRoot(t) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int, key(a))") diff --git a/planner/core/binary_plan_test.go b/planner/core/binary_plan_test.go index e530e20bf8262..65548581451fb 100644 --- a/planner/core/binary_plan_test.go +++ b/planner/core/binary_plan_test.go @@ -49,7 +49,7 @@ func TestBinaryPlanSwitch(t *testing.T) { require.NoError(t, logutil.InitLogger(newCfg.Log.ToLogConfig())) store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec(fmt.Sprintf("set @@tidb_slow_query_file='%v'", f.Name())) origin := tk.MustQuery("SELECT @@global.tidb_generate_binary_plan") @@ -124,7 +124,7 @@ func TestTooLongBinaryPlan(t *testing.T) { require.NoError(t, logutil.InitLogger(newCfg.Log.ToLogConfig())) store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec(fmt.Sprintf("set @@tidb_slow_query_file='%v'", f.Name())) origin := tk.MustQuery("SELECT @@global.tidb_enable_stmt_summary") @@ -194,7 +194,7 @@ func TestLongBinaryPlan(t *testing.T) { require.NoError(t, logutil.InitLogger(newCfg.Log.ToLogConfig())) store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec(fmt.Sprintf("set @@tidb_slow_query_file='%v'", f.Name())) @@ -248,7 +248,7 @@ func TestBinaryPlanOfPreparedStmt(t *testing.T) { require.NoError(t, logutil.InitLogger(newCfg.Log.ToLogConfig())) store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec(fmt.Sprintf("set @@tidb_slow_query_file='%v'", f.Name())) tk.MustExec("use test") @@ -409,7 +409,7 @@ func TestUnnecessaryBinaryPlanInSlowLog(t *testing.T) { require.NoError(t, logutil.InitLogger(newCfg.Log.ToLogConfig())) store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec(fmt.Sprintf("set @@tidb_slow_query_file='%v'", f.Name())) origin := tk.MustQuery("SELECT @@global.tidb_slow_log_threshold") diff --git a/planner/core/integration_partition_test.go b/planner/core/integration_partition_test.go index 5fd57cc33ff14..becfcd39f729c 100644 --- a/planner/core/integration_partition_test.go +++ b/planner/core/integration_partition_test.go @@ -415,7 +415,7 @@ func TestListPartitionPrivilege(t *testing.T) { se, err := session.CreateSession4Test(store) require.NoError(t, err) - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.SetSession(se) tk.MustExec("create database list_partition_pri") tk.MustExec("use list_partition_pri") @@ -429,7 +429,7 @@ func TestListPartitionPrivilege(t *testing.T) { tk1 := testkit.NewTestKit(t, store) se, err = session.CreateSession4Test(store) require.NoError(t, err) - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "priv_test", Hostname: "%"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "priv_test", Hostname: "%"}, nil, nil, nil)) tk1.SetSession(se) tk1.MustExec(`use list_partition_pri`) err = tk1.ExecToErr(`alter table tlist truncate partition p0`) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index b308f145d6dd8..1f904aa979dc6 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -5270,7 +5270,7 @@ func TestVirtualExprPushDown(t *testing.T) { func TestIssue41458(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec(`create table t (a int, b int, c int, index ia(a));`) tk.MustExec("select * from t t1 join t t2 on t1.b = t2.b join t t3 on t2.b=t3.b join t t4 on t3.b=t4.b where t3.a=1 and t2.a=2;") diff --git a/planner/core/prepare_test.go b/planner/core/prepare_test.go index 583b6a5150334..c4d31a6aaceff 100644 --- a/planner/core/prepare_test.go +++ b/planner/core/prepare_test.go @@ -435,7 +435,7 @@ func TestPrepareCache(t *testing.T) { // user u_tp userSess := newSession(t, store, "test") - require.NoError(t, userSess.Auth(&auth.UserIdentity{Username: "u_tp", Hostname: "localhost"}, nil, nil)) + require.NoError(t, userSess.Auth(&auth.UserIdentity{Username: "u_tp", Hostname: "localhost"}, nil, nil, nil)) mustExec(t, userSess, `prepare ps_stp_r from 'select * from tp where c1 > ?'`) mustExec(t, userSess, `set @p2 = 2`) tk.SetSession(userSess) @@ -1811,7 +1811,7 @@ func TestIssue18066(t *testing.T) { tk := testkit.NewTestKit(t, store) tk.MustExec(`set tidb_enable_prepared_plan_cache=1`) tk.RefreshConnectionID() - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("drop table if exists t") diff --git a/privilege/privileges/ldap/mock_ldap_server_test.go b/privilege/privileges/ldap/mock_ldap_server_test.go index 08e28ffcf786b..dc65b5b63ee80 100644 --- a/privilege/privileges/ldap/mock_ldap_server_test.go +++ b/privilege/privileges/ldap/mock_ldap_server_test.go @@ -67,7 +67,6 @@ func (s *MockLDAPServer) Listen(port int) { }() s.listener = l - return } // Close closes the listener diff --git a/session/bootstrap_test.go b/session/bootstrap_test.go index fd208a46e03d9..11b33fdbd6464 100644 --- a/session/bootstrap_test.go +++ b/session/bootstrap_test.go @@ -59,7 +59,7 @@ func TestBootstrap(t *testing.T) { match(t, rows, `%`, "root", "", "mysql_native_password", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "N", "Y", "Y", "Y", "Y", "Y", nil, nil, nil, "", "N", time.Now(), nil) r.Close() - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "root", Hostname: "anyhost"}, []byte(""), []byte(""))) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "root", Hostname: "anyhost"}, []byte(""), []byte(""), nil)) mustExec(t, se, "use test") @@ -690,7 +690,7 @@ func TestForIssue23387(t *testing.T) { require.NoError(t, err) se := CreateSessionAndSetID(t, store) - se.Auth(&auth.UserIdentity{Username: "root", Hostname: `%`}, nil, []byte("012345678901234567890")) + se.Auth(&auth.UserIdentity{Username: "root", Hostname: `%`}, nil, []byte("012345678901234567890"), nil) mustExec(t, se, "create user quatest") dom.Close() // Upgrade to a newer version, check the user's privilege. @@ -700,7 +700,7 @@ func TestForIssue23387(t *testing.T) { defer dom.Close() se = CreateSessionAndSetID(t, store) - se.Auth(&auth.UserIdentity{Username: "root", Hostname: `%`}, nil, []byte("012345678901234567890")) + se.Auth(&auth.UserIdentity{Username: "root", Hostname: `%`}, nil, []byte("012345678901234567890"), nil) rs, err := exec(se, "show grants for quatest") require.NoError(t, err) rows, err := ResultSetToStringSlice(context.Background(), se, rs) diff --git a/session/sessiontest/session_test.go b/session/sessiontest/session_test.go index 3b7fd0a2d54b9..260c41d36d2ce 100644 --- a/session/sessiontest/session_test.go +++ b/session/sessiontest/session_test.go @@ -235,8 +235,8 @@ func TestAutoCommitRespectsReadOnly(t *testing.T) { var wg sync.WaitGroup tk1 := testkit.NewTestKit(t, store) tk2 := testkit.NewTestKit(t, store) - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) - require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) + require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk1.MustExec("create table test.auto_commit_test (a int)") wg.Add(1) @@ -850,11 +850,11 @@ func TestSkipWithGrant(t *testing.T) { save2 := privileges.SkipWithGrant privileges.SkipWithGrant = false - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "user_not_exist"}, []byte("yyy"), []byte("zzz"))) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "user_not_exist"}, []byte("yyy"), []byte("zzz"), nil)) privileges.SkipWithGrant = true - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "xxx", Hostname: `%`}, []byte("yyy"), []byte("zzz"))) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: `%`}, []byte(""), []byte(""))) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "xxx", Hostname: `%`}, []byte("yyy"), []byte("zzz"), nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: `%`}, []byte(""), []byte(""), nil)) tk.MustExec("use test") tk.MustExec("create table t (id int)") tk.MustExec("create role r_1") @@ -1716,14 +1716,14 @@ func TestGrantViewRelated(t *testing.T) { tkRoot.MustExec("use test") tkUser.MustExec("use test") - tkRoot.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost", CurrentUser: true, AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890")) + tkRoot.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost", CurrentUser: true, AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) tkRoot.MustExec("create table if not exists t (a int)") tkRoot.MustExec("create view v_version29 as select * from t") tkRoot.MustExec("create user 'u_version29'@'%'") tkRoot.MustExec("grant select on t to u_version29@'%'") - tkUser.Session().Auth(&auth.UserIdentity{Username: "u_version29", Hostname: "localhost", CurrentUser: true, AuthUsername: "u_version29", AuthHostname: "%"}, nil, []byte("012345678901234567890")) + tkUser.Session().Auth(&auth.UserIdentity{Username: "u_version29", Hostname: "localhost", CurrentUser: true, AuthUsername: "u_version29", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) tkUser.MustQuery("select current_user();").Check(testkit.Rows("u_version29@%")) require.Error(t, tkUser.ExecToErr("select * from test.v_version29;")) @@ -1797,7 +1797,7 @@ func TestUpdatePrivilege(t *testing.T) { tk1 := testkit.NewTestKit(t, store) tk1.MustExec("use test") - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "xxx", Hostname: "localhost"}, []byte(""), []byte(""))) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "xxx", Hostname: "localhost"}, []byte(""), []byte(""), nil)) tk1.MustMatchErrMsg("update t2 set id = 666 where id = 1;", "privilege check.*") @@ -1811,7 +1811,7 @@ func TestUpdatePrivilege(t *testing.T) { tk.MustExec("create table tb_wehub_server (id int, active_count int, used_count int)") tk.MustExec("create user 'weperk'") tk.MustExec("grant all privileges on weperk.* to 'weperk'@'%'") - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "weperk", Hostname: "%"}, []byte(""), []byte(""))) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "weperk", Hostname: "%"}, []byte(""), []byte(""), nil)) tk1.MustExec("use weperk") tk1.MustExec("update tb_wehub_server a set a.active_count=a.active_count+1,a.used_count=a.used_count+1 where id=1") @@ -1847,7 +1847,7 @@ and s.b !='xx';`) tk.MustExec("insert into tp.record (id,name,age) values (1,'john',18),(2,'lary',19),(3,'lily',18)") tk.MustExec("create table ap.record( id int,name varchar(128),age int)") tk.MustExec("insert into ap.record(id) values(1)") - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "xxx", Hostname: "localhost"}, []byte(""), []byte(""))) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "xxx", Hostname: "localhost"}, []byte(""), []byte(""), nil)) tk1.MustExec("update ap.record t inner join tp.record tt on t.id=tt.id set t.name=tt.name") } @@ -3437,7 +3437,7 @@ func TestSessionAuth(t *testing.T) { tk := testkit.NewTestKit(t, store) tk.MustExec("use test") - require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "Any not exist username with zero password!", Hostname: "anyhost"}, []byte(""), []byte(""))) + require.Error(t, tk.Session().Auth(&auth.UserIdentity{Username: "Any not exist username with zero password!", Hostname: "anyhost"}, []byte(""), []byte(""), nil)) } func TestLastInsertID(t *testing.T) { diff --git a/sessiontxn/staleread/externalts_test.go b/sessiontxn/staleread/externalts_test.go index 2ee7c6f14f767..a0bd0b81a938c 100644 --- a/sessiontxn/staleread/externalts_test.go +++ b/sessiontxn/staleread/externalts_test.go @@ -61,7 +61,7 @@ func TestExternalTimestampRead(t *testing.T) { func TestExternalTimestampReadonly(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("create table t (id INT NOT NULL,PRIMARY KEY (id))") @@ -88,7 +88,7 @@ func TestExternalTimestampReadonly(t *testing.T) { func TestExternalTimestampReadWithTransaction(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("create table t (id INT NOT NULL,PRIMARY KEY (id))") @@ -122,7 +122,7 @@ func TestExternalTimestampReadWithTransaction(t *testing.T) { func TestExternalTimestampNotAffectPrepare(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("create table t (id INT NOT NULL,PRIMARY KEY (id))") diff --git a/table/tables/cache_test.go b/table/tables/cache_test.go index c20d98cafc921..2560ea834fefc 100644 --- a/table/tables/cache_test.go +++ b/table/tables/cache_test.go @@ -472,7 +472,7 @@ func TestCacheTableWriteOperatorWaitLockLease(t *testing.T) { // This line is a hack, if auth user string is "", the statement summary is skipped, // so it's added to make the later code been covered. - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil, nil)) tk.MustExec("drop table if exists wait_tb1") tk.MustExec("create table wait_tb1(id int)") diff --git a/table/tables/tables_test.go b/table/tables/tables_test.go index 5d857d5adedfb..3a8140f43ca79 100644 --- a/table/tables/tables_test.go +++ b/table/tables/tables_test.go @@ -711,7 +711,7 @@ func TestConstraintCheckForUniqueIndex(t *testing.T) { func TestViewColumns(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk.MustExec("use test") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int primary key, b varchar(20))") @@ -768,7 +768,7 @@ func TestTxnAssertion(t *testing.T) { se, err := session.CreateSession4Test(store) se.SetConnectionID(1) require.NoError(t, err) - require.NoError(t, se.Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, se.Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk := testkit.NewTestKit(t, store) tk.SetSession(se) diff --git a/tests/realtikvtest/pessimistictest/pessimistic_test.go b/tests/realtikvtest/pessimistictest/pessimistic_test.go index d297eedad65bc..bcde6d9cbe19e 100644 --- a/tests/realtikvtest/pessimistictest/pessimistic_test.go +++ b/tests/realtikvtest/pessimistictest/pessimistic_test.go @@ -203,7 +203,7 @@ func TestDeadlock(t *testing.T) { // Use the root user so that the statements can be recorded into statements_summary table, which is necessary // for fetching - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk1.MustExec("drop table if exists deadlock") tk1.MustExec("create table deadlock (k int primary key, v int)") tk1.MustExec("insert into deadlock values (1, 1), (2, 1)") @@ -212,7 +212,7 @@ func TestDeadlock(t *testing.T) { ts1, err := strconv.ParseUint(tk1.MustQuery("select @@tidb_current_ts").Rows()[0][0].(string), 10, 64) require.NoError(t, err) - require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) tk2.MustExec("begin pessimistic") ts2, err := strconv.ParseUint(tk2.MustQuery("select @@tidb_current_ts").Rows()[0][0].(string), 10, 64) require.NoError(t, err) diff --git a/util/stmtsummary/v2/tests/table_test.go b/util/stmtsummary/v2/tests/table_test.go index e91df486fcc5f..2f1dbf363e4d5 100644 --- a/util/stmtsummary/v2/tests/table_test.go +++ b/util/stmtsummary/v2/tests/table_test.go @@ -241,7 +241,7 @@ func TestStmtSummaryTablePrivilege(t *testing.T) { Hostname: "localhost", AuthUsername: "test_user", AuthHostname: "localhost", - }, nil, nil) + }, nil, nil, nil) result = tk1.MustQuery("select * from information_schema.statements_summary where digest_text like 'select * from `t`%'") // Ordinary users can not see others' records @@ -299,7 +299,7 @@ func TestCapturePrivilege(t *testing.T) { Hostname: "localhost", AuthUsername: "test_user", AuthHostname: "localhost", - }, nil, nil) + }, nil, nil, nil) rows = tk1.MustQuery("show global bindings").Rows() // Ordinary users can not see others' records @@ -535,7 +535,7 @@ func newTestKit(t *testing.T, store kv.Storage) *testkit.TestKit { func newTestKitWithRoot(t *testing.T, store kv.Storage) *testkit.TestKit { tk := newTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) return tk } @@ -547,7 +547,7 @@ func newTestKitWithPlanCache(t *testing.T, store kv.Storage) *testkit.TestKit { require.NoError(t, err) tk.SetSession(se) tk.RefreshConnectionID() - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) + require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) return tk }