@@ -20,6 +20,7 @@ import (
20
20
"github.com/cockroachdb/cockroach/pkg/sql/sqlerrors"
21
21
"github.com/cockroachdb/cockroach/pkg/sql/unsafesql"
22
22
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
23
+ "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
23
24
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
24
25
"github.com/cockroachdb/cockroach/pkg/util/log"
25
26
"github.com/cockroachdb/cockroach/pkg/util/log/eventpb"
@@ -67,12 +68,12 @@ func TestAccessCheckServer(t *testing.T) {
67
68
pool := s .SQLConn (t )
68
69
defer pool .Close ()
69
70
71
+ runner := sqlutils .MakeSQLRunner (pool )
70
72
// override the log limiter so that the tests can run without pauses.
71
73
defer unsafesql .TestRemoveLimiters ()()
72
74
73
75
// create a user table to test user table access.
74
- _ , err := pool .Exec ("CREATE TABLE foo (id INT PRIMARY KEY)" )
75
- require .NoError (t , err )
76
+ runner .Exec (t , "CREATE TABLE foo (id INT PRIMARY KEY)" )
76
77
77
78
// create and register a log accessedSpy to see the unsafe access logs
78
79
accessedSpy := logtestutils .NewStructuredLogSpy [eventpb.UnsafeInternalsAccessed ](
@@ -119,6 +120,7 @@ func TestAccessCheckServer(t *testing.T) {
119
120
120
121
for _ , test := range []struct {
121
122
Query string
123
+ AppName string
122
124
Internal bool
123
125
AllowUnsafeInternals bool
124
126
Passes bool
@@ -157,6 +159,14 @@ func TestAccessCheckServer(t *testing.T) {
157
159
Passes : true ,
158
160
LogsAccessed : true ,
159
161
},
162
+ {
163
+ Query : "SELECT * FROM system.namespace" ,
164
+ AppName : "$ internal app" ,
165
+ Internal : false ,
166
+ AllowUnsafeInternals : false ,
167
+ Passes : true ,
168
+ LogsAccessed : false ,
169
+ },
160
170
// Tests on unsupported crdb_internal objects.
161
171
{
162
172
Query : "SELECT * FROM crdb_internal.gossip_alerts" ,
@@ -223,6 +233,7 @@ func TestAccessCheckServer(t *testing.T) {
223
233
t .Run (fmt .Sprintf ("query=%s,internal=%t,allowUnsafe=%t" , test .Query , test .Internal , test .AllowUnsafeInternals ), func (t * testing.T ) {
224
234
accessedSpy .Reset ()
225
235
deniedSpy .Reset ()
236
+ runner .Exec (t , "SET application_name = $1" , test .AppName )
226
237
err := sendQuery (test .AllowUnsafeInternals , test .Internal , test .Query )
227
238
if test .Passes {
228
239
require .NoError (t , err )
0 commit comments