OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
com.mapd.dashboard.DashboardTest Class Reference
+ Collaboration diagram for com.mapd.dashboard.DashboardTest:

Static Public Member Functions

static void main (String[] args) throws Exception
 

Package Functions

void testUserRoles () throws Exception
 
void testDbLevelDashboardPermissions () throws Exception
 
void testDashboards () throws Exception
 

Static Package Attributes

static final Logger logger = LoggerFactory.getLogger(DashboardTest.class)
 

Detailed Description

Definition at line 32 of file DashboardTest.java.

Member Function Documentation

static void com.mapd.dashboard.DashboardTest.main ( String[]  args) throws Exception
inlinestatic

Definition at line 35 of file DashboardTest.java.

35  {
36  logger.info("Hello, World");
37 
38  DashboardTest x = new DashboardTest();
39  x.testUserRoles();
40  x.testDashboards();
41  x.testDbLevelDashboardPermissions();
42  }
void com.mapd.dashboard.DashboardTest.testDashboards ( ) throws Exception
inlinepackage

Definition at line 171 of file DashboardTest.java.

171  {
172  logger.info("testDashboards()");
173 
174  HeavyDBTestClient su = HeavyDBTestClient.getClient(
175  "localhost", 6274, "omnisci", "admin", "HyperInteractive");
176 
177  List<String> users = su.get_users();
178 
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');");
182 
183  su.runSql("CREATE ROLE salesDept;");
184  su.runSql("CREATE USER foo (password = 'password', is_super = 'false');");
185 
186  su.runSql("GRANT salesDept TO foo;");
187 
188  HeavyDBTestClient dba =
189  HeavyDBTestClient.getClient("localhost", 6274, "omnisci", "dba", "password");
190  HeavyDBTestClient jason = HeavyDBTestClient.getClient(
191  "localhost", 6274, "omnisci", "jason", "password");
192  HeavyDBTestClient bob =
193  HeavyDBTestClient.getClient("localhost", 6274, "omnisci", "bob", "password");
194  HeavyDBTestClient foo =
195  HeavyDBTestClient.getClient("localhost", 6274, "omnisci", "foo", "password");
196 
197  su.runSql("GRANT CREATE DASHBOARD ON DATABASE omnisci TO jason;");
198 
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"));
203 
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");
207 
208  HeavyDBAsserts.assertEqual(0, bob.get_dashboards().size());
209  HeavyDBAsserts.assertEqual(0, foo.get_dashboards().size());
210 
211  HeavyDBTestClient granter = jason;
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;");
216 
217  HeavyDBAsserts.assertEqual(2, bob.get_dashboards().size());
218  HeavyDBAsserts.assertEqual(2, foo.get_dashboards().size());
219 
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));
224 
225  HeavyDBAsserts.assertEqual("for_bob", bob.get_dashboard(for_bob));
226  HeavyDBAsserts.assertEqual("for_all", bob.get_dashboard(for_all));
227 
228  HeavyDBAsserts.assertEqual("for_sales", foo.get_dashboard(for_sales));
229  HeavyDBAsserts.assertEqual("for_all", foo.get_dashboard(for_all));
230 
231  // check update
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"));
240 
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"));
247 
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");
251 
252  HeavyDBAsserts.assertEqual("for_bob2", bob.get_dashboard(for_bob));
253  HeavyDBAsserts.assertEqual("for_all2", bob.get_dashboard(for_all));
254 
255  HeavyDBAsserts.assertEqual("for_sales2", foo.get_dashboard(for_sales));
256  HeavyDBAsserts.assertEqual("for_all2", foo.get_dashboard(for_all));
257 
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));
264 
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));
271 
272  jason.delete_dashboard(for_bob);
273 
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));
279 
280  jason.delete_dashboard(for_all);
281 
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));
285 
286  jason.delete_dashboard(for_sales);
287 
288  HeavyDBAsserts.assertEqual(0, bob.get_dashboards().size());
289  HeavyDBAsserts.assertEqual(0, foo.get_dashboards().size());
290 
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;");
296  }
void com.mapd.dashboard.DashboardTest.testDbLevelDashboardPermissions ( ) throws Exception
inlinepackage

Definition at line 96 of file DashboardTest.java.

References DashboardDBObjectType.

96  {
97  logger.info("testDbLevelDashboardPermissions()");
98 
99  HeavyDBTestClient su = HeavyDBTestClient.getClient(
100  "localhost", 6274, "omnisci", "admin", "HyperInteractive");
101 
102  su.runSql("CREATE USER dba (password = 'password', is_super = 'true');");
103  su.runSql("CREATE USER jason (password = 'password', is_super = 'false');");
104 
105  su.runSql("CREATE ROLE salesDept;");
106  su.runSql("CREATE USER foo (password = 'password', is_super = 'false');");
107 
108  su.runSql("GRANT salesDept TO foo;");
109 
110  HeavyDBTestClient dba =
111  HeavyDBTestClient.getClient("localhost", 6274, "omnisci", "dba", "password");
112  HeavyDBTestClient jason = HeavyDBTestClient.getClient(
113  "localhost", 6274, "omnisci", "jason", "password");
114  HeavyDBTestClient foo =
115  HeavyDBTestClient.getClient("localhost", 6274, "omnisci", "foo", "password");
116 
117  HeavyDBAsserts.assertEqual(
118  0, jason.get_db_object_privs("", TDBObjectType.DashboardDBObjectType).size());
119  HeavyDBAsserts.assertEqual(
120  0, foo.get_db_object_privs("", TDBObjectType.DashboardDBObjectType).size());
121 
122  su.runSql("GRANT CREATE DASHBOARD ON DATABASE omnisci TO jason;");
123  HeavyDBAsserts.assertEqual(
124  1, jason.get_db_object_privs("", TDBObjectType.DashboardDBObjectType).size());
125  HeavyDBAsserts.assertEqual(
126  0, foo.get_db_object_privs("", TDBObjectType.DashboardDBObjectType).size());
127 
128  TDBObject obj =
129  jason.get_db_object_privs("", TDBObjectType.DashboardDBObjectType).get(0);
130  HeavyDBAsserts.assertEqual(Arrays.asList(true, false, false, false), obj.getPrivs());
131 
132  su.runSql("GRANT EDIT DASHBOARD ON DATABASE omnisci TO jason;");
133  obj = jason.get_db_object_privs("", TDBObjectType.DashboardDBObjectType).get(0);
134  HeavyDBAsserts.assertEqual(Arrays.asList(true, false, false, true), obj.getPrivs());
135 
136  su.runSql("GRANT VIEW DASHBOARD ON DATABASE omnisci TO jason;");
137  obj = jason.get_db_object_privs("", TDBObjectType.DashboardDBObjectType).get(0);
138  HeavyDBAsserts.assertEqual(Arrays.asList(true, false, true, true), obj.getPrivs());
139 
140  su.runSql("GRANT DELETE DASHBOARD ON DATABASE omnisci TO jason;");
141  obj = jason.get_db_object_privs("", TDBObjectType.DashboardDBObjectType).get(0);
142  HeavyDBAsserts.assertEqual(Arrays.asList(true, true, true, true), obj.getPrivs());
143 
144  su.runSql("GRANT CREATE DASHBOARD ON DATABASE omnisci TO salesDept;");
145  HeavyDBAsserts.assertEqual(
146  1, jason.get_db_object_privs("", TDBObjectType.DashboardDBObjectType).size());
147  HeavyDBAsserts.assertEqual(
148  1, foo.get_db_object_privs("", TDBObjectType.DashboardDBObjectType).size());
149 
150  obj = foo.get_db_object_privs("", TDBObjectType.DashboardDBObjectType).get(0);
151  HeavyDBAsserts.assertEqual(Arrays.asList(true, false, false, false), obj.getPrivs());
152 
153  su.runSql("GRANT EDIT DASHBOARD ON DATABASE omnisci TO salesDept;");
154  obj = foo.get_db_object_privs("", TDBObjectType.DashboardDBObjectType).get(0);
155  HeavyDBAsserts.assertEqual(Arrays.asList(true, false, false, true), obj.getPrivs());
156 
157  su.runSql("GRANT VIEW DASHBOARD ON DATABASE omnisci TO salesDept;");
158  obj = foo.get_db_object_privs("", TDBObjectType.DashboardDBObjectType).get(0);
159  HeavyDBAsserts.assertEqual(Arrays.asList(true, false, true, true), obj.getPrivs());
160 
161  su.runSql("GRANT DELETE DASHBOARD ON DATABASE omnisci TO salesDept;");
162  obj = foo.get_db_object_privs("", TDBObjectType.DashboardDBObjectType).get(0);
163  HeavyDBAsserts.assertEqual(Arrays.asList(true, true, true, true), obj.getPrivs());
164 
165  su.runSql("DROP USER foo;");
166  su.runSql("DROP ROLE salesDept;");
167  su.runSql("DROP USER jason;");
168  su.runSql("DROP USER dba;");
169  }
void com.mapd.dashboard.DashboardTest.testUserRoles ( ) throws Exception
inlinepackage

Definition at line 44 of file DashboardTest.java.

44  {
45  logger.info("testUserRoles()");
46  HeavyDBTestClient su = HeavyDBTestClient.getClient(
47  "localhost", 6274, "omnisci", "admin", "HyperInteractive");
48 
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');");
52 
53  su.runSql("CREATE ROLE salesDept;");
54  su.runSql("CREATE USER foo (password = 'password', is_super = 'false');");
55 
56  su.runSql("CREATE DATABASE db1;");
57  su.runSql("CREATE DATABASE db2;");
58  HeavyDBTestClient dba1 =
59  HeavyDBTestClient.getClient("localhost", 6274, "db1", "bob", "password");
60  HeavyDBTestClient dba2 =
61  HeavyDBTestClient.getClient("localhost", 6274, "db2", "foo", "password");
62  HeavyDBTestClient dba =
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());
70 
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());
78 
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());
86 
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;");
94  }

Member Data Documentation

final Logger com.mapd.dashboard.DashboardTest.logger = LoggerFactory.getLogger(DashboardTest.class)
staticpackage

Definition at line 33 of file DashboardTest.java.


The documentation for this class was generated from the following file: