16 package com.mapd.tests;
18 import static com.mapd.tests.HeavyDBAsserts.shouldThrowException;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 final static Logger
logger = LoggerFactory.getLogger(TablePermissionsTest.class);
26 public static void main(String[]
args)
throws Exception {
28 test.testTablePermissions();
32 logger.info(
"testTablePermissions()");
35 "localhost", 6274,
"mapd",
"mapd",
"HyperInteractive");
37 su.runSql(
"CREATE USER dba (password = 'password', is_super = 'true');");
38 su.runSql(
"CREATE USER bob (password = 'password', is_super = 'false');");
39 su.runSql(
"CREATE USER bill (password = 'password', is_super = 'false');");
41 su.runSql(
"CREATE ROLE salesDept;");
42 su.runSql(
"CREATE USER foo (password = 'password', is_super = 'false');");
43 su.runSql(
"GRANT salesDept TO foo;");
45 su.runSql(
"CREATE DATABASE db1;");
46 su.runSql(
"CREATE DATABASE db2;");
48 su.runSql(
"GRANT ACCESS on database db1 TO bob;");
49 su.runSql(
"GRANT ACCESS on database db1 TO bill;");
50 su.runSql(
"GRANT ACCESS on database db1 TO foo;");
51 su.runSql(
"GRANT ACCESS on database db1 TO dba;");
54 HeavyDBTestClient.getClient(
"localhost", 6274,
"db1",
"dba",
"password");
56 HeavyDBTestClient.getClient(
"localhost", 6274,
"db1",
"bill",
"password");
58 HeavyDBTestClient.getClient(
"localhost", 6274,
"db1",
"bob",
"password");
60 HeavyDBTestClient.getClient(
"localhost", 6274,
"db1",
"foo",
"password");
62 shouldThrowException(
"bill should not be able to create tables",
63 () -> bill.runSql(
"CREATE TABLE bill_table(id integer);"));
64 shouldThrowException(
"bob should not be able to create tables",
65 () -> bob.runSql(
"CREATE TABLE bob_table(id integer);"));
66 shouldThrowException(
"foo should not be able to create tables",
67 () -> foo.runSql(
"CREATE TABLE foo_table(id integer);"));
70 dba.runSql(
"GRANT CREATE ON DATABASE db1 TO bill");
71 dba.runSql(
"GRANT DROP ON DATABASE db1 TO bill");
73 bill.runSql(
"CREATE TABLE bill_table(id integer);");
76 "not allowed to select", () -> bob.runSql(
"SELECT * from bill_table"));
78 "not allowed to select", () -> foo.runSql(
"SELECT * from bill_table"));
80 bill.runSql(
"GRANT SELECT ON TABLE bill_table TO bob");
82 bob.runSql(
"SELECT * from bill_table");
84 "foo not allowed to select", () -> foo.runSql(
"SELECT * from bill_table"));
86 bill.runSql(
"GRANT SELECT ON TABLE bill_table TO salesDept");
87 bob.runSql(
"SELECT * from bill_table");
88 foo.runSql(
"SELECT * from bill_table");
91 "insert not allowed", () -> bob.runSql(
"INSERT INTO bill_table VALUES(1)"));
93 "insert not allowed ", () -> foo.runSql(
"INSERT INTO bill_table VALUES(1)"));
95 bill.runSql(
"GRANT INSERT ON TABLE bill_table TO bob");
96 bob.runSql(
"INSERT INTO bill_table VALUES(1)");
98 "insert not allowed ", () -> foo.runSql(
"INSERT INTO bill_table VALUES(1)"));
100 bill.runSql(
"GRANT INSERT ON TABLE bill_table TO salesDept");
101 bob.runSql(
"INSERT INTO bill_table VALUES(1)");
102 foo.runSql(
"INSERT INTO bill_table VALUES(1)");
104 shouldThrowException(
"update not allowed",
105 () -> bob.runSql(
"UPDATE bill_table SET id = 2 WHERE id = 0"));
106 shouldThrowException(
"update not allowed ",
107 () -> foo.runSql(
"UPDATE bill_table SET id = 2 WHERE id = 0"));
109 bill.runSql(
"GRANT UPDATE ON TABLE bill_table TO bob");
110 bob.runSql(
"UPDATE bill_table SET id = 2 WHERE id = 0");
111 shouldThrowException(
"update not allowed ",
112 () -> foo.runSql(
"UPDATE bill_table SET id = 2 WHERE id = 0"));
114 bill.runSql(
"GRANT UPDATE ON TABLE bill_table TO salesDept");
115 bob.runSql(
"UPDATE bill_table SET id = 2 WHERE id = 0");
116 foo.runSql(
"UPDATE bill_table SET id = 2 WHERE id = 0");
118 shouldThrowException(
"update not allowed",
119 () -> bob.runSql(
"DELETE FROM bill_table WHERE id = 0"));
120 shouldThrowException(
"update not allowed ",
121 () -> foo.runSql(
"DELETE FROM bill_table WHERE id = 0"));
123 bill.runSql(
"GRANT DELETE ON TABLE bill_table TO bob");
124 bob.runSql(
"DELETE FROM bill_table WHERE id = 0");
125 shouldThrowException(
"update not allowed ",
126 () -> foo.runSql(
"DELETE FROM bill_table WHERE id = 0"));
128 bill.runSql(
"GRANT DELETE ON TABLE bill_table TO salesDept");
129 bob.runSql(
"DELETE FROM bill_table WHERE id = 0");
130 foo.runSql(
"DELETE FROM bill_table WHERE id = 0");
132 su.runSql(
"DROP DATABASE db1;");
133 su.runSql(
"DROP DATABASE db2;");
134 su.runSql(
"DROP USER foo;");
135 su.runSql(
"DROP ROLE salesDept;");
136 su.runSql(
"DROP USER bob;");
137 su.runSql(
"DROP USER bill;");
138 su.runSql(
"DROP USER dba;");
static void main(String[] args)
void testTablePermissions()
static final Logger logger