|
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; |
|
42 | 44 | import org.apache.zeppelin.scheduler.SchedulerFactory; |
43 | 45 | import org.apache.zeppelin.search.SearchService; |
44 | 46 | import org.apache.zeppelin.search.LuceneSearch; |
| 47 | +import org.apache.zeppelin.user.AuthenticationInfo; |
45 | 48 | import org.apache.zeppelin.user.Credentials; |
46 | 49 | import org.junit.After; |
47 | 50 | import org.junit.Before; |
@@ -308,6 +311,72 @@ public void testCheckpointOneStorage() throws IOException, SchedulerException { |
308 | 311 | assertThat(gitRepo.revisionHistory(noteId, null).size()).isEqualTo(vCount + 1); |
309 | 312 | } |
310 | 313 |
|
| 314 | + @Test |
| 315 | + public void testSyncWithAcl() throws IOException { |
| 316 | + /* scenario 1 - note exists with acl on main storage */ |
| 317 | + AuthenticationInfo user1 = new AuthenticationInfo("user1"); |
| 318 | + Note note = notebookSync.createNote(user1); |
| 319 | + assertEquals(0, note.getParagraphs().size()); |
| 320 | + |
| 321 | + // saved on both storages |
| 322 | + assertEquals(1, notebookRepoSync.list(0, null).size()); |
| 323 | + assertEquals(1, notebookRepoSync.list(1, null).size()); |
| 324 | + |
| 325 | + /* check that user1 is the only owner */ |
| 326 | + NotebookAuthorization authInfo = NotebookAuthorization.getInstance(); |
| 327 | + Set<String> entity = new HashSet<String>(); |
| 328 | + entity.add(user1.getUser()); |
| 329 | + assertEquals(true, authInfo.isOwner(note.getId(), entity)); |
| 330 | + assertEquals(1, authInfo.getOwners(note.getId()).size()); |
| 331 | + assertEquals(0, authInfo.getReaders(note.getId()).size()); |
| 332 | + assertEquals(0, authInfo.getWriters(note.getId()).size()); |
| 333 | + |
| 334 | + /* update note and save on secondary storage */ |
| 335 | + Paragraph p1 = note.addParagraph(); |
| 336 | + p1.setText("hello world"); |
| 337 | + assertEquals(1, note.getParagraphs().size()); |
| 338 | + notebookRepoSync.save(1, note, null); |
| 339 | + |
| 340 | + /* check paragraph isn't saved into first storage */ |
| 341 | + assertEquals(0, notebookRepoSync.get(0, |
| 342 | + notebookRepoSync.list(0, null).get(0).getId(), null).getParagraphs().size()); |
| 343 | + /* check paragraph is saved into second storage */ |
| 344 | + assertEquals(1, notebookRepoSync.get(1, |
| 345 | + notebookRepoSync.list(1, null).get(0).getId(), null).getParagraphs().size()); |
| 346 | + |
| 347 | + /* now sync by user1 */ |
| 348 | + notebookRepoSync.sync(user1); |
| 349 | + |
| 350 | + /* check that note updated and acl are same on main storage*/ |
| 351 | + assertEquals(1, notebookRepoSync.get(0, |
| 352 | + notebookRepoSync.list(0, null).get(0).getId(), null).getParagraphs().size()); |
| 353 | + assertEquals(true, authInfo.isOwner(note.getId(), entity)); |
| 354 | + assertEquals(1, authInfo.getOwners(note.getId()).size()); |
| 355 | + assertEquals(0, authInfo.getReaders(note.getId()).size()); |
| 356 | + assertEquals(0, authInfo.getWriters(note.getId()).size()); |
| 357 | + |
| 358 | + /* scenario 2 - note doesn't exist on main storage */ |
| 359 | + /* remove from main storage */ |
| 360 | + notebookRepoSync.remove(0, note.getId(), user1); |
| 361 | + assertEquals(0, notebookRepoSync.list(0, null).size()); |
| 362 | + assertEquals(1, notebookRepoSync.list(1, null).size()); |
| 363 | + authInfo.removeNote(note.getId()); |
| 364 | + assertEquals(0, authInfo.getOwners(note.getId()).size()); |
| 365 | + assertEquals(0, authInfo.getReaders(note.getId()).size()); |
| 366 | + assertEquals(0, authInfo.getWriters(note.getId()).size()); |
| 367 | + |
| 368 | + /* now sync - should bring note from secondary storage with added acl */ |
| 369 | + notebookRepoSync.sync(user1); |
| 370 | + assertEquals(1, notebookRepoSync.list(0, null).size()); |
| 371 | + assertEquals(1, notebookRepoSync.list(1, null).size()); |
| 372 | + assertEquals(1, authInfo.getOwners(note.getId()).size()); |
| 373 | + assertEquals(1, authInfo.getReaders(note.getId()).size()); |
| 374 | + assertEquals(1, authInfo.getWriters(note.getId()).size()); |
| 375 | + assertEquals(true, authInfo.isOwner(note.getId(), entity)); |
| 376 | + assertEquals(true, authInfo.isReader(note.getId(), entity)); |
| 377 | + assertEquals(true, authInfo.isWriter(note.getId(), entity)); |
| 378 | + } |
| 379 | + |
311 | 380 | static void delete(File file){ |
312 | 381 | if(file.isFile()) file.delete(); |
313 | 382 | else if(file.isDirectory()){ |
|
0 commit comments