1
1
import unittest
2
2
from crate .client import connect
3
+ from crate .client .exceptions import ProgrammingError
4
+
3
5
from crate .qa .tests import NodeProvider , insert_data , wait_for_active_shards , UpgradePath
4
6
5
7
ROLLING_UPGRADES_V4 = (
@@ -103,6 +105,7 @@ def _test_rolling_upgrade(self, path, nodes):
103
105
) CLUSTERED INTO { shards } SHARDS
104
106
WITH (number_of_replicas={ replicas } )
105
107
''' )
108
+ c .execute ("deny dql on table doc.t1 to arthur" )
106
109
c .execute ("CREATE VIEW doc.v1 AS SELECT type, title, value FROM doc.t1" )
107
110
insert_data (conn , 'doc' , 't1' , 1000 )
108
111
@@ -150,6 +153,11 @@ def _test_rolling_upgrade(self, path, nodes):
150
153
c = custom_user_conn .cursor ()
151
154
wait_for_active_shards (c , expected_active_shards )
152
155
c .execute ("SELECT 1" )
156
+ # has no privilege
157
+ with self .assertRaisesRegex (ProgrammingError , "RelationUnknown.*" ):
158
+ c .execute ("EXPLAIN SELECT * FROM doc.t1" )
159
+ # has privilege
160
+ c .execute ("EXPLAIN SELECT * FROM doc.v1" )
153
161
154
162
cluster [idx ] = new_node
155
163
with connect (new_node .http_url , error_trace = True ) as conn :
@@ -160,7 +168,10 @@ def _test_rolling_upgrade(self, path, nodes):
160
168
self .assertEqual (c .fetchall (), [["arthur" ], ["crate" ]])
161
169
162
170
c .execute ("select * from sys.privileges" )
163
- self .assertEqual (c .fetchall (), [["CLUSTER" , "arthur" , "crate" , None , "GRANT" , "DQL" ]])
171
+ self .assertEqual (
172
+ c .fetchall (),
173
+ [['TABLE' , 'arthur' , 'crate' , 'doc.t1' , 'DENY' , 'DQL' ],
174
+ ['CLUSTER' , 'arthur' , 'crate' , None , 'GRANT' , 'DQL' ]])
164
175
165
176
c .execute ('''
166
177
SELECT type, AVG(value)
@@ -239,3 +250,14 @@ def _test_rolling_upgrade(self, path, nodes):
239
250
''' )
240
251
res = c .fetchone ()
241
252
self .assertEqual (res [0 ], nodes + 1 )
253
+
254
+ # Ensure Arthur can be dropped and re-added
255
+ c .execute ("drop user arthur" )
256
+ c .execute ("select * from sys.privileges" )
257
+ self .assertEqual (c .fetchall (), [])
258
+
259
+ # Ensure view 'v' can be dropped and re-added
260
+ c .execute ("DROP VIEW doc.v1" )
261
+ c .execute ("CREATE VIEW doc.v1 AS SELECT 11" )
262
+ c .execute ("SELECT * FROM doc.v1" )
263
+ self .assertEqual (c .fetchall (), [[11 ]])
0 commit comments