forked from apache/cassandra-dtest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
system_keyspaces_test.py
125 lines (96 loc) · 5.29 KB
/
system_keyspaces_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import pytest
import logging
from cassandra import Unauthorized
from dtest import Tester
from tools.assertions import assert_all, assert_exception, assert_none
since = pytest.mark.since
logger = logging.getLogger(__name__)
class TestSystemKeyspaces(Tester):
@since('3.0')
def test_local_system_keyspaces(self):
cluster = self.cluster
cluster.populate(1).start()
node = cluster.nodelist()[0]
session = self.patient_cql_connection(node)
# ALTER KEYSPACE should fail for system and system_schema
stmt = """
ALTER KEYSPACE system
WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1' : '1'};"""
assert_exception(session, stmt, expected=Unauthorized)
stmt = """
ALTER KEYSPACE system_schema
WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1' : '1'};"""
assert_exception(session, stmt, expected=Unauthorized)
# DROP KEYSPACE should fail for system and system_schema
assert_exception(session, 'DROP KEYSPACE system;', expected=Unauthorized)
assert_exception(session, 'DROP KEYSPACE system_schema;', expected=Unauthorized)
# CREATE TABLE should fail in system and system_schema
assert_exception(session,
'CREATE TABLE system.new_table (id int PRIMARY KEY);',
expected=Unauthorized)
assert_exception(session,
'CREATE TABLE system_schema.new_table (id int PRIMARY KEY);',
expected=Unauthorized)
# ALTER TABLE should fail in system and system_schema
assert_exception(session,
"ALTER TABLE system.local WITH comment = '';",
expected=Unauthorized)
assert_exception(session,
"ALTER TABLE system_schema.tables WITH comment = '';",
expected=Unauthorized)
# DROP TABLE should fail in system and system_schema
assert_exception(session, 'DROP TABLE system.local;', expected=Unauthorized)
assert_exception(session, 'DROP TABLE system_schema.tables;', expected=Unauthorized)
@since('3.0')
def test_replicated_system_keyspaces(self):
cluster = self.cluster
cluster.populate(1).start()
node = cluster.nodelist()[0]
session = self.patient_cql_connection(node)
# ALTER KEYSPACE should work for system_auth, system_distributed, and system_traces
stmt = """
ALTER KEYSPACE system_auth
WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1' : '1'};"""
assert_none(session, stmt)
stmt = """
ALTER KEYSPACE system_distributed
WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1' : '1'};"""
assert_none(session, stmt)
stmt = """
ALTER KEYSPACE system_traces
WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1' : '1'};"""
assert_none(session, stmt)
stmt = """
SELECT replication
FROM system_schema.keyspaces
WHERE keyspace_name IN ('system_auth', 'system_distributed', 'system_traces');"""
replication = {'class': 'org.apache.cassandra.locator.NetworkTopologyStrategy', 'datacenter1': '1'}
assert_all(session, stmt, [[replication], [replication], [replication]])
# DROP KEYSPACE should fail for system_auth, system_distributed, and system_traces
assert_exception(session, 'DROP KEYSPACE system_auth;', expected=Unauthorized)
assert_exception(session, 'DROP KEYSPACE system_distributed;', expected=Unauthorized)
assert_exception(session, 'DROP KEYSPACE system_traces;', expected=Unauthorized)
# CREATE TABLE should fail in system_auth, system_distributed, and system_traces
assert_exception(session,
'CREATE TABLE system_auth.new_table (id int PRIMARY KEY);',
expected=Unauthorized)
assert_exception(session,
'CREATE TABLE system_distributed.new_table (id int PRIMARY KEY);',
expected=Unauthorized)
assert_exception(session,
'CREATE TABLE system_traces.new_table (id int PRIMARY KEY);',
expected=Unauthorized)
# ALTER TABLE should fail in system_auth, system_distributed, and system_traces
assert_exception(session,
"ALTER TABLE system_auth.roles WITH comment = '';",
expected=Unauthorized)
assert_exception(session,
"ALTER TABLE system_distributed.repair_history WITH comment = '';",
expected=Unauthorized)
assert_exception(session,
"ALTER TABLE system_traces.sessions WITH comment = '';",
expected=Unauthorized)
# DROP TABLE should fail in system_auth, system_distributed, and system_traces
assert_exception(session, 'DROP TABLE system_auth.roles;', expected=Unauthorized)
assert_exception(session, 'DROP TABLE system_distributed.repair_history;', expected=Unauthorized)
assert_exception(session, 'DROP TABLE system_traces.sessions;', expected=Unauthorized)