|
24 | 24 |
|
25 | 25 | import java.io.File; |
26 | 26 | import java.io.IOException; |
| 27 | +import java.util.HashSet; |
27 | 28 | import java.util.Map; |
| 29 | +import java.util.Set; |
28 | 30 |
|
29 | 31 | import org.apache.commons.io.FileUtils; |
30 | 32 | import org.apache.zeppelin.conf.ZeppelinConfiguration; |
@@ -314,6 +316,72 @@ public void testCheckpointOneStorage() throws IOException, SchedulerException { |
314 | 316 | notebookRepoSync.remove(note.getId(), anonymous); |
315 | 317 | } |
316 | 318 |
|
| 319 | + @Test |
| 320 | + public void testSyncWithAcl() throws IOException { |
| 321 | + /* scenario 1 - note exists with acl on main storage */ |
| 322 | + AuthenticationInfo user1 = new AuthenticationInfo("user1"); |
| 323 | + Note note = notebookSync.createNote(user1); |
| 324 | + assertEquals(0, note.getParagraphs().size()); |
| 325 | + |
| 326 | + // saved on both storages |
| 327 | + assertEquals(1, notebookRepoSync.list(0, null).size()); |
| 328 | + assertEquals(1, notebookRepoSync.list(1, null).size()); |
| 329 | + |
| 330 | + /* check that user1 is the only owner */ |
| 331 | + NotebookAuthorization authInfo = NotebookAuthorization.getInstance(); |
| 332 | + Set<String> entity = new HashSet<String>(); |
| 333 | + entity.add(user1.getUser()); |
| 334 | + assertEquals(true, authInfo.isOwner(note.getId(), entity)); |
| 335 | + assertEquals(1, authInfo.getOwners(note.getId()).size()); |
| 336 | + assertEquals(0, authInfo.getReaders(note.getId()).size()); |
| 337 | + assertEquals(0, authInfo.getWriters(note.getId()).size()); |
| 338 | + |
| 339 | + /* update note and save on secondary storage */ |
| 340 | + Paragraph p1 = note.addParagraph(); |
| 341 | + p1.setText("hello world"); |
| 342 | + assertEquals(1, note.getParagraphs().size()); |
| 343 | + notebookRepoSync.save(1, note, null); |
| 344 | + |
| 345 | + /* check paragraph isn't saved into first storage */ |
| 346 | + assertEquals(0, notebookRepoSync.get(0, |
| 347 | + notebookRepoSync.list(0, null).get(0).getId(), null).getParagraphs().size()); |
| 348 | + /* check paragraph is saved into second storage */ |
| 349 | + assertEquals(1, notebookRepoSync.get(1, |
| 350 | + notebookRepoSync.list(1, null).get(0).getId(), null).getParagraphs().size()); |
| 351 | + |
| 352 | + /* now sync by user1 */ |
| 353 | + notebookRepoSync.sync(user1); |
| 354 | + |
| 355 | + /* check that note updated and acl are same on main storage*/ |
| 356 | + assertEquals(1, notebookRepoSync.get(0, |
| 357 | + notebookRepoSync.list(0, null).get(0).getId(), null).getParagraphs().size()); |
| 358 | + assertEquals(true, authInfo.isOwner(note.getId(), entity)); |
| 359 | + assertEquals(1, authInfo.getOwners(note.getId()).size()); |
| 360 | + assertEquals(0, authInfo.getReaders(note.getId()).size()); |
| 361 | + assertEquals(0, authInfo.getWriters(note.getId()).size()); |
| 362 | + |
| 363 | + /* scenario 2 - note doesn't exist on main storage */ |
| 364 | + /* remove from main storage */ |
| 365 | + notebookRepoSync.remove(0, note.getId(), user1); |
| 366 | + assertEquals(0, notebookRepoSync.list(0, null).size()); |
| 367 | + assertEquals(1, notebookRepoSync.list(1, null).size()); |
| 368 | + authInfo.removeNote(note.getId()); |
| 369 | + assertEquals(0, authInfo.getOwners(note.getId()).size()); |
| 370 | + assertEquals(0, authInfo.getReaders(note.getId()).size()); |
| 371 | + assertEquals(0, authInfo.getWriters(note.getId()).size()); |
| 372 | + |
| 373 | + /* now sync - should bring note from secondary storage with added acl */ |
| 374 | + notebookRepoSync.sync(user1); |
| 375 | + assertEquals(1, notebookRepoSync.list(0, null).size()); |
| 376 | + assertEquals(1, notebookRepoSync.list(1, null).size()); |
| 377 | + assertEquals(1, authInfo.getOwners(note.getId()).size()); |
| 378 | + assertEquals(1, authInfo.getReaders(note.getId()).size()); |
| 379 | + assertEquals(1, authInfo.getWriters(note.getId()).size()); |
| 380 | + assertEquals(true, authInfo.isOwner(note.getId(), entity)); |
| 381 | + assertEquals(true, authInfo.isReader(note.getId(), entity)); |
| 382 | + assertEquals(true, authInfo.isWriter(note.getId(), entity)); |
| 383 | + } |
| 384 | + |
317 | 385 | static void delete(File file){ |
318 | 386 | if(file.isFile()) file.delete(); |
319 | 387 | else if(file.isDirectory()){ |
|
0 commit comments