16 package com.mapd.dashboard;
18 import static com.mapd.tests.HeavyDBAsserts.shouldThrowException;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import java.util.Arrays;
27 import java.util.List;
29 import ai.heavy.thrift.server.TDBObject;
30 import ai.heavy.thrift.server.TDBObjectType;
33 final static Logger
logger = LoggerFactory.getLogger(DashboardTest.class);
35 public static void main(String[]
args)
throws Exception {
36 logger.info(
"Hello, World");
41 x.testDbLevelDashboardPermissions();
45 logger.info(
"testUserRoles()");
47 "localhost", 6274,
"omnisci",
"admin",
"HyperInteractive");
49 su.runSql(
"CREATE USER dba (password = 'password', is_super = 'true');");
50 su.runSql(
"CREATE USER jason (password = 'password', is_super = 'false');");
51 su.runSql(
"CREATE USER bob (password = 'password', is_super = 'false');");
53 su.runSql(
"CREATE ROLE salesDept;");
54 su.runSql(
"CREATE USER foo (password = 'password', is_super = 'false');");
56 su.runSql(
"CREATE DATABASE db1;");
57 su.runSql(
"CREATE DATABASE db2;");
59 HeavyDBTestClient.getClient(
"localhost", 6274,
"db1",
"bob",
"password");
61 HeavyDBTestClient.getClient(
"localhost", 6274,
"db2",
"foo",
"password");
63 HeavyDBTestClient.getClient(
"localhost", 6274,
"db2",
"dba",
"password");
64 HeavyDBAsserts.assertEqual(0, dba1.get_users().size());
65 HeavyDBAsserts.assertEqual(0, dba1.get_roles().size());
66 HeavyDBAsserts.assertEqual(0, dba2.get_users().size());
67 HeavyDBAsserts.assertEqual(0, dba2.get_roles().size());
68 HeavyDBAsserts.assertEqual(5, dba.get_users().size());
69 HeavyDBAsserts.assertEqual(1, dba.get_roles().size());
71 su.runSql(
"GRANT create dashboard on database db1 to jason;");
72 HeavyDBAsserts.assertEqual(Arrays.asList(
"jason"), dba1.get_users());
73 HeavyDBAsserts.assertEqual(0, dba1.get_roles().size());
74 HeavyDBAsserts.assertEqual(0, dba2.get_users().size());
75 HeavyDBAsserts.assertEqual(0, dba2.get_roles().size());
76 HeavyDBAsserts.assertEqual(5, dba.get_users().size());
77 HeavyDBAsserts.assertEqual(1, dba.get_roles().size());
79 su.runSql(
"GRANT create dashboard on database db1 to salesDept;");
80 HeavyDBAsserts.assertEqual(Arrays.asList(
"jason"), dba1.get_users());
81 HeavyDBAsserts.assertEqual(Arrays.asList(
"salesDept"), dba1.get_roles());
82 HeavyDBAsserts.assertEqual(0, dba2.get_users().size());
83 HeavyDBAsserts.assertEqual(0, dba2.get_roles().size());
84 HeavyDBAsserts.assertEqual(5, dba.get_users().size());
85 HeavyDBAsserts.assertEqual(1, dba.get_roles().size());
87 su.runSql(
"DROP DATABASE db1;");
88 su.runSql(
"DROP DATABASE db2;");
89 su.runSql(
"DROP USER foo;");
90 su.runSql(
"DROP ROLE salesDept;");
91 su.runSql(
"DROP USER bob;");
92 su.runSql(
"DROP USER jason;");
93 su.runSql(
"DROP USER dba;");
97 logger.info(
"testDbLevelDashboardPermissions()");
100 "localhost", 6274,
"omnisci",
"admin",
"HyperInteractive");
102 su.runSql(
"CREATE USER dba (password = 'password', is_super = 'true');");
103 su.runSql(
"CREATE USER jason (password = 'password', is_super = 'false');");
105 su.runSql(
"CREATE ROLE salesDept;");
106 su.runSql(
"CREATE USER foo (password = 'password', is_super = 'false');");
108 su.runSql(
"GRANT salesDept TO foo;");
111 HeavyDBTestClient.getClient(
"localhost", 6274,
"omnisci",
"dba",
"password");
113 "localhost", 6274,
"omnisci",
"jason",
"password");
115 HeavyDBTestClient.getClient(
"localhost", 6274,
"omnisci",
"foo",
"password");
117 HeavyDBAsserts.assertEqual(
119 HeavyDBAsserts.assertEqual(
122 su.runSql(
"GRANT CREATE DASHBOARD ON DATABASE omnisci TO jason;");
123 HeavyDBAsserts.assertEqual(
125 HeavyDBAsserts.assertEqual(
130 HeavyDBAsserts.assertEqual(Arrays.asList(
true,
false,
false,
false), obj.getPrivs());
132 su.runSql(
"GRANT EDIT DASHBOARD ON DATABASE omnisci TO jason;");
134 HeavyDBAsserts.assertEqual(Arrays.asList(
true,
false,
false,
true), obj.getPrivs());
136 su.runSql(
"GRANT VIEW DASHBOARD ON DATABASE omnisci TO jason;");
138 HeavyDBAsserts.assertEqual(Arrays.asList(
true,
false,
true,
true), obj.getPrivs());
140 su.runSql(
"GRANT DELETE DASHBOARD ON DATABASE omnisci TO jason;");
142 HeavyDBAsserts.assertEqual(Arrays.asList(
true,
true,
true,
true), obj.getPrivs());
144 su.runSql(
"GRANT CREATE DASHBOARD ON DATABASE omnisci TO salesDept;");
145 HeavyDBAsserts.assertEqual(
147 HeavyDBAsserts.assertEqual(
151 HeavyDBAsserts.assertEqual(Arrays.asList(
true,
false,
false,
false), obj.getPrivs());
153 su.runSql(
"GRANT EDIT DASHBOARD ON DATABASE omnisci TO salesDept;");
155 HeavyDBAsserts.assertEqual(Arrays.asList(
true,
false,
false,
true), obj.getPrivs());
157 su.runSql(
"GRANT VIEW DASHBOARD ON DATABASE omnisci TO salesDept;");
159 HeavyDBAsserts.assertEqual(Arrays.asList(
true,
false,
true,
true), obj.getPrivs());
161 su.runSql(
"GRANT DELETE DASHBOARD ON DATABASE omnisci TO salesDept;");
163 HeavyDBAsserts.assertEqual(Arrays.asList(
true,
true,
true,
true), obj.getPrivs());
165 su.runSql(
"DROP USER foo;");
166 su.runSql(
"DROP ROLE salesDept;");
167 su.runSql(
"DROP USER jason;");
168 su.runSql(
"DROP USER dba;");
172 logger.info(
"testDashboards()");
175 "localhost", 6274,
"omnisci",
"admin",
"HyperInteractive");
177 List<String> users = su.get_users();
179 su.runSql(
"CREATE USER dba (password = 'password', is_super = 'true');");
180 su.runSql(
"CREATE USER jason (password = 'password', is_super = 'false');");
181 su.runSql(
"CREATE USER bob (password = 'password', is_super = 'false');");
183 su.runSql(
"CREATE ROLE salesDept;");
184 su.runSql(
"CREATE USER foo (password = 'password', is_super = 'false');");
186 su.runSql(
"GRANT salesDept TO foo;");
189 HeavyDBTestClient.getClient(
"localhost", 6274,
"omnisci",
"dba",
"password");
191 "localhost", 6274,
"omnisci",
"jason",
"password");
193 HeavyDBTestClient.getClient(
"localhost", 6274,
"omnisci",
"bob",
"password");
195 HeavyDBTestClient.getClient(
"localhost", 6274,
"omnisci",
"foo",
"password");
197 su.runSql(
"GRANT CREATE DASHBOARD ON DATABASE omnisci TO jason;");
199 shouldThrowException(
"bob should not be able to create dashboards",
200 () -> bob.create_dashboard(
"for_bob"));
201 shouldThrowException(
"foo should not be able to create dashboards",
202 () -> foo.create_dashboard(
"for_bob"));
204 int for_bob = jason.create_dashboard(
"for_bob");
205 int for_sales = jason.create_dashboard(
"for_sales");
206 int for_all = jason.create_dashboard(
"for_all");
208 HeavyDBAsserts.assertEqual(0, bob.get_dashboards().size());
209 HeavyDBAsserts.assertEqual(0, foo.get_dashboards().size());
212 granter.runSql(
"GRANT VIEW ON DASHBOARD " + for_bob +
" TO bob;");
213 granter.runSql(
"GRANT VIEW ON DASHBOARD " + for_sales +
" TO salesDept;");
214 granter.runSql(
"GRANT VIEW ON DASHBOARD " + for_all +
" TO bob;");
215 granter.runSql(
"GRANT VIEW ON DASHBOARD " + for_all +
" TO salesDept;");
217 HeavyDBAsserts.assertEqual(2, bob.get_dashboards().size());
218 HeavyDBAsserts.assertEqual(2, foo.get_dashboards().size());
220 shouldThrowException(
"bob should not be able to access for_sales",
221 () -> bob.get_dashboard(for_sales));
222 shouldThrowException(
223 "foo should not be able to access for_bob", () -> foo.get_dashboard(for_bob));
225 HeavyDBAsserts.assertEqual(
"for_bob", bob.get_dashboard(for_bob));
226 HeavyDBAsserts.assertEqual(
"for_all", bob.get_dashboard(for_all));
228 HeavyDBAsserts.assertEqual(
"for_sales", foo.get_dashboard(for_sales));
229 HeavyDBAsserts.assertEqual(
"for_all", foo.get_dashboard(for_all));
232 shouldThrowException(
"bob can not edit for_bob",
233 () -> bob.replace_dashboard(for_bob,
"for_bob2",
"jason"));
234 shouldThrowException(
"foo can not edit for_bob",
235 () -> foo.replace_dashboard(for_bob,
"for_bob2",
"jason"));
236 shouldThrowException(
"bob can not edit for_sales",
237 () -> bob.replace_dashboard(for_sales,
"for_sales2",
"jason"));
238 shouldThrowException(
"foo can not edit for_sales",
239 () -> foo.replace_dashboard(for_sales,
"for_sales2",
"jason"));
241 jason.runSql(
"GRANT EDIT ON DASHBOARD " + for_bob +
" TO bob;");
242 jason.runSql(
"GRANT EDIT ON DASHBOARD " + for_sales +
" TO salesDept;");
243 shouldThrowException(
"foo can not edit for_bob",
244 () -> foo.replace_dashboard(for_bob,
"for_bob2",
"jason"));
245 shouldThrowException(
"bob can not edit for_sales",
246 () -> bob.replace_dashboard(for_sales,
"for_sales2",
"jason"));
248 jason.replace_dashboard(for_all,
"for_all2",
"jason");
249 bob.replace_dashboard(for_bob,
"for_bob2",
"jason");
250 foo.replace_dashboard(for_sales,
"for_sales2",
"jason");
252 HeavyDBAsserts.assertEqual(
"for_bob2", bob.get_dashboard(for_bob));
253 HeavyDBAsserts.assertEqual(
"for_all2", bob.get_dashboard(for_all));
255 HeavyDBAsserts.assertEqual(
"for_sales2", foo.get_dashboard(for_sales));
256 HeavyDBAsserts.assertEqual(
"for_all2", foo.get_dashboard(for_all));
258 shouldThrowException(
259 "foo can not delete for_bob", () -> foo.delete_dashboard(for_bob));
260 shouldThrowException(
261 "foo can not delete for_sales", () -> foo.delete_dashboard(for_sales));
262 shouldThrowException(
263 "foo can not delete for_all", () -> foo.delete_dashboard(for_all));
265 shouldThrowException(
266 "bob can not delete for_bob", () -> bob.delete_dashboard(for_bob));
267 shouldThrowException(
268 "bob can not delete for_sales", () -> bob.delete_dashboard(for_sales));
269 shouldThrowException(
270 "bob can not delete for_all", () -> bob.delete_dashboard(for_all));
272 jason.delete_dashboard(for_bob);
274 HeavyDBAsserts.assertEqual(1, bob.get_dashboards().size());
275 HeavyDBAsserts.assertEqual(2, foo.get_dashboards().size());
276 HeavyDBAsserts.assertEqual(
"for_all2", bob.get_dashboard(for_all));
277 HeavyDBAsserts.assertEqual(
"for_sales2", foo.get_dashboard(for_sales));
278 HeavyDBAsserts.assertEqual(
"for_all2", foo.get_dashboard(for_all));
280 jason.delete_dashboard(for_all);
282 HeavyDBAsserts.assertEqual(0, bob.get_dashboards().size());
283 HeavyDBAsserts.assertEqual(1, foo.get_dashboards().size());
284 HeavyDBAsserts.assertEqual(
"for_sales2", foo.get_dashboard(for_sales));
286 jason.delete_dashboard(for_sales);
288 HeavyDBAsserts.assertEqual(0, bob.get_dashboards().size());
289 HeavyDBAsserts.assertEqual(0, foo.get_dashboards().size());
291 su.runSql(
"DROP USER foo;");
292 su.runSql(
"DROP ROLE salesDept;");
293 su.runSql(
"DROP USER bob;");
294 su.runSql(
"DROP USER jason;");
295 su.runSql(
"DROP USER dba;");
void testDbLevelDashboardPermissions()
static void main(String[] args)
static final Logger logger