~linuxjedi/drizzle/drizzle-gcc-4.7.0

« back to all changes in this revision

Viewing changes to plugin/simple_user_policy/tests/t/basic.test

  • Committer: Monty Taylor
  • Date: 2010-04-15 19:14:53 UTC
  • mto: This revision was merged to the branch mainline in revision 1476.
  • Revision ID: mordred@inaugust.com-20100415191453-ril2x8qdo78fny9w
Replaced test_authz with a plugin implementing a hard-coded simple
multi-tennancy policy. The policy describes:
- A root user exists which can do anything
- A user may only see a schema that is named the same has his user name
- A user may see data_dictionary and information_schema (data_dictionary
  required for show databases to work)

This way, we can more clearly test the results of the authorization
interface while providing an optional plugin that is actually useful to some
human.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Check for error if no parameter provided
2
 
create database authz_no;
 
2
create database user1;
 
3
create database user2;
 
4
show databases;
 
5
 
 
6
# Set up a table to be able to test not being able to kill other people
 
7
use user2;
 
8
create table t1 (kill_id int);
 
9
insert into t1 values(connection_id());
 
10
 
 
11
# Test that we get a normal don't exist error for things that don't exist
3
12
--error ER_NO_SUCH_TABLE
4
 
SELECT * from authz_no.dont_exist;
5
 
create database authz_yes;
6
 
show databases;
 
13
SELECT * from user1.dont_exist;
 
14
 
 
15
# Connect as user1 - should only see information_schema, user1 and
 
16
# data_dictionary
 
17
# Also tests that we are able to read data_dictionary, without which fail
 
18
# would happen
7
19
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
8
 
connect (should_succeed,localhost,authz,test,,);
 
20
connect (should_succeed,localhost,user1,,user1,,);
9
21
connection should_succeed;
10
22
show databases;
11
 
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
12
 
--replace_regex /@'.*?'/@'LOCALHOST'/
13
 
--error ER_DBACCESS_DENIED_ERROR
14
 
SELECT * from authz_no.dont_exist;
15
 
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
16
 
--replace_regex /@'.*?'/@'LOCALHOST'/
17
 
--error ER_DBACCESS_DENIED_ERROR
18
 
create database authz_no;
19
 
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
20
 
--replace_regex /@'.*?'/@'LOCALHOST'/
21
 
--error ER_DBACCESS_DENIED_ERROR
22
 
drop database authz_no;
23
 
 
24
 
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
25
 
connect (con1,localhost,root,test,,);
26
 
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
27
 
connect (con2,localhost,root,test,,);
 
23
 
 
24
# Test that we get blocked on not being allowed to see user2 at all before
 
25
# we get blocked on the table not existing
 
26
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
 
27
--replace_regex /@'.*?'/@'LOCALHOST'/
 
28
--error ER_DBACCESS_DENIED_ERROR
 
29
SELECT * from user2.dont_exist;
 
30
 
 
31
# Test that we can't create a schema that isn't named the same as we are
 
32
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
 
33
--replace_regex /@'.*?'/@'LOCALHOST'/
 
34
--error ER_DBACCESS_DENIED_ERROR
 
35
create database authorize_fail;
 
36
 
 
37
# Test that we can't drop a schema that isn't named the same as we are
 
38
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
 
39
--replace_regex /@'.*?'/@'LOCALHOST'/
 
40
--error ER_DBACCESS_DENIED_ERROR
 
41
drop database user2;
 
42
 
 
43
# Set up a table to test that we can kill other versions of us
 
44
create table t1 (kill_id int);
 
45
insert into t1 values(connection_id());
 
46
 
 
47
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
 
48
connect (con1,localhost,user1,,user1,);
 
49
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
 
50
connect (con2,localhost,user2,,user2,);
28
51
connection con1;
29
52
 
 
53
# Check that we don't see other people's connections
30
54
--replace_column 3 # 5 # 6 # 7 #
31
55
show processlist;
32
56
 
 
57
# Check that we can kill a process that is owned by our user
33
58
--disable_reconnect
34
 
create table t1 (kill_id int);
35
 
insert into t1 values(connection_id());
36
 
 
 
59
select ((@id := kill_id) - kill_id) from t1;
 
60
kill @id;
 
61
 
 
62
connection should_succeed;
 
63
--sleep 2
 
64
 
 
65
--disable_query_log
 
66
--disable_result_log
 
67
# One of the following statements should fail
 
68
--error 0,5,20,23
 
69
select 1;
 
70
--error 0,5,20,23
 
71
select 1;
 
72
--enable_query_log
 
73
--enable_result_log
 
74
--enable_reconnect
 
75
 
 
76
select ((@id := kill_id) - kill_id) from t1;
 
77
select @id != connection_id();
 
78
 
 
79
# Set the table to our current id now
 
80
update t1 set kill_id = connection_id();
 
81
 
 
82
# Test that we cannot kill a process owned by someone else
37
83
connection con2;
38
 
select ((@id := kill_id) - kill_id) from t1;
39
 
kill @id;
40
 
 
41
 
connection con1;
42
 
--sleep 2
43
 
 
44
 
--disable_query_log
45
 
--disable_result_log
46
 
# One of the following statements should fail
47
 
--error 0,5,20,23
48
 
select 1;
49
 
--error 0,5,20,23
50
 
select 1;
51
 
--enable_query_log
52
 
--enable_result_log
53
 
--enable_reconnect
54
 
 
55
 
select ((@id := kill_id) - kill_id) from t1;
56
 
select @id != connection_id();
57
 
 
58
 
update t1 set kill_id= connection_id();
59
 
 
60
 
connection should_succeed;
61
 
--replace_column 3 # 6 #
 
84
--replace_column 3 # 5 # 6 # 7 #
62
85
show processlist;
63
86
select ((@id := kill_id) - kill_id) from t1;
64
87
 
65
88
--error ER_NO_SUCH_THREAD
66
89
kill @id;
67
90
 
68
 
 
 
91
# Test that root can see everybody
 
92
connection default;
 
93
--replace_column 3 # 5 # 6 # 7 #
 
94
show processlist;
 
95
 
 
96
# Test that root can kill someone else
 
97
use user1;
 
98
--disable_reconnect
 
99
select ((@id := kill_id) - kill_id) from t1;
 
100
kill @id;
 
101
 
 
102
connection should_succeed;
 
103
--sleep 2
 
104
 
 
105
--disable_query_log
 
106
--disable_result_log
 
107
# One of the following statements should fail
 
108
--error 0,5,20,23
 
109
select 1;
 
110
--error 0,5,20,23
 
111
select 1;
 
112
--enable_query_log
 
113
--enable_result_log
 
114
--enable_reconnect
 
115
 
 
116
select ((@id := kill_id) - kill_id) from t1;
 
117
select @id != connection_id();
69
118
 
70
119
 
71
120
# Test failing initial connection
74
123
--error ER_DBACCESS_DENIED_ERROR
75
124
connect (should_fail,localhost,authz,,authz_no,,);
76
125
 
 
126
# Clean up after ourselves
77
127
connection default;
78
 
drop table t1;
79
 
drop schema authz_yes;
80
 
drop schema authz_no;
 
128
drop schema user1;
 
129
drop schema user2;
 
130
disconnect con1;
 
131
disconnect con2;
 
132
disconnect should_succeed;