28
28
import org .exist .security .MessageDigester ;
29
29
import org .exist .security .SecurityManager ;
30
30
import org .exist .test .ExistWebServer ;
31
+ import org .exist .util .MimeTable ;
31
32
import org .exist .xmldb .*;
32
- import org .junit .ClassRule ;
33
- import org .junit .Ignore ;
34
- import org .junit .Rule ;
35
- import org .junit .Test ;
33
+ import org .junit .*;
36
34
import org .junit .rules .TemporaryFolder ;
37
35
import org .junit .runner .RunWith ;
38
36
import org .junit .runners .Parameterized ;
@@ -85,6 +83,20 @@ private final String getBaseUri() {
85
83
return baseUri .replace (PORT_PLACEHOLDER , Integer .toString (existWebServer .getPort ()));
86
84
}
87
85
86
+ @ BeforeClass
87
+ public static void prepare () throws IOException {
88
+ Path mimeTypesDefinition = tempFolder .getRoot ().toPath ().resolve ("mime-types.xml" );
89
+ String mimeTypesContent =
90
+ "<mime-types default-mime-type=\" foo/bar\" default-resource-type=\" binary\" xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\" schema/mime-types.xsd\" >\n " +
91
+ "<mime-type name=\" text/html\" type=\" xml\" >\n " +
92
+ "<description>HTML document</description>\n " +
93
+ "<extensions>.html</extensions>\n " +
94
+ "</mime-type>\n " +
95
+ "</mime-types>" ;
96
+ Files .write (mimeTypesDefinition , mimeTypesContent .getBytes (UTF_8 ));
97
+ MimeTable .getInstance (mimeTypesDefinition );
98
+ }
99
+
88
100
@ Test
89
101
public void restoreValidZipBackup () throws IOException , XMLDBException {
90
102
final Path zipFile = createZipBackupWithValidContent ();
@@ -93,8 +105,8 @@ public void restoreValidZipBackup() throws IOException, XMLDBException {
93
105
94
106
restoreBackup (rootUri , zipFile , null , listener );
95
107
96
- assertEquals (5 , listener .restored .size ());
97
- assertEquals (0 , listener .warnings .size ());
108
+ assertEquals (7 , listener .restored .size ());
109
+ assertEquals (1 , listener .warnings .size ());
98
110
assertEquals (0 , listener .errors .size ());
99
111
}
100
112
@@ -106,8 +118,8 @@ public void restoreValidDirBackup() throws IOException, XMLDBException {
106
118
107
119
restoreBackup (rootUri , contentsFile , null , listener );
108
120
109
- assertEquals (5 , listener .restored .size ());
110
- assertEquals (0 , listener .warnings .size ());
121
+ assertEquals (7 , listener .restored .size ());
122
+ assertEquals (1 , listener .warnings .size ());
111
123
assertEquals (0 , listener .errors .size ());
112
124
}
113
125
@@ -181,7 +193,7 @@ public void restoreUserWithoutGroupIsPlacedInNoGroup() throws IOException, XMLDB
181
193
final Account account = userManagementService .getAccount (username );
182
194
assertNotNull (account );
183
195
assertEquals (SecurityManager .UNKNOWN_GROUP , account .getPrimaryGroup ());
184
- assertArrayEquals (new String [] { SecurityManager .UNKNOWN_GROUP }, account .getGroups ());
196
+ assertArrayEquals (new String []{ SecurityManager .UNKNOWN_GROUP }, account .getGroups ());
185
197
}
186
198
187
199
@ Test
@@ -202,7 +214,7 @@ public void restoreUserWithNoSuchGroupIsPlacedInNoGroup() throws IOException, XM
202
214
final Account account = userManagementService .getAccount (username );
203
215
assertNotNull (account );
204
216
assertEquals (SecurityManager .UNKNOWN_GROUP , account .getPrimaryGroup ());
205
- assertArrayEquals (new String [] { SecurityManager .UNKNOWN_GROUP }, account .getGroups ());
217
+ assertArrayEquals (new String []{ SecurityManager .UNKNOWN_GROUP }, account .getGroups ());
206
218
}
207
219
208
220
/**
@@ -251,9 +263,9 @@ public void restoreUserWithGroupsFromDbCollection() throws IOException, XMLDBExc
251
263
private void restoreUserWithGroups (final Path backupPath , final Path restorePath , final int expectedRestoredCount ) throws IOException , XMLDBException {
252
264
final String username = UUID .randomUUID ().toString () + "-user" ;
253
265
final String primaryGroup = username ; // personal group
254
- final String group1 = UUID .randomUUID ().toString () + "-group-1" ;
255
- final String group2 = UUID .randomUUID ().toString () + "-group-2" ;
256
- final String group3 = UUID .randomUUID ().toString () + "-group-3" ;
266
+ final String group1 = UUID .randomUUID ().toString () + "-group-1" ;
267
+ final String group2 = UUID .randomUUID ().toString () + "-group-2" ;
268
+ final String group3 = UUID .randomUUID ().toString () + "-group-3" ;
257
269
final TestRestoreListener listener = new TestRestoreListener ();
258
270
final XmldbURI rootUri = XmldbURI .create (getBaseUri ()).append (XmldbURI .ROOT_COLLECTION_URI );
259
271
@@ -269,7 +281,7 @@ private void restoreUserWithGroups(final Path backupPath, final Path restorePath
269
281
final Account account = userManagementService .getAccount (username );
270
282
assertNotNull (account );
271
283
assertEquals (primaryGroup , account .getPrimaryGroup ());
272
- assertArrayEquals (new String [] { primaryGroup , group1 , group2 , group3 }, account .getGroups ());
284
+ assertArrayEquals (new String []{ primaryGroup , group1 , group2 , group3 }, account .getGroups ());
273
285
}
274
286
275
287
private static void restoreBackup (final XmldbURI uri , final Path backup , @ Nullable final String backupPassword , final RestoreServiceTaskListener listener ) throws XMLDBException {
@@ -305,20 +317,30 @@ private static Path createBackupWithValidContent() throws IOException {
305
317
" <resource type=\" XMLResource\" name=\" doc2.xml\" owner=\" admin\" group=\" dba\" mode=\" 644\" created=\" 2019-05-15T15:58:48.638+04:00\" modified=\" 2019-05-15T15:58:48.638+04:00\" filename=\" doc2.xml\" mimetype=\" application/xml\" >\n " +
306
318
" <acl entries=\" 0\" version=\" 1\" />\n " +
307
319
" </resource>\n " +
308
- " <resource type=\" XMLResource\" name=\" doc3.xml\" owner=\" admin\" group=\" dba\" mode=\" 644\" created=\" 2019-05-15T15:58:49.618+04:00\" modified=\" 2019-05-15T15:58:49.618+04:00\" filename=\" doc3.xml\" mimetype=\" application/xml\" >\n " +
320
+ " <resource type=\" XMLResource\" name=\" doc3.xml\" owner=\" admin\" group=\" dba\" mode=\" 644\" created=\" 2019-05-15T15:58:49.618+04:00\" modified=\" 2019-05-15T15:58:49.618+04:00\" filename=\" doc3.xml\" mimetype=\" application/special-xml\" >\n " +
321
+ " <acl entries=\" 0\" version=\" 1\" />\n " +
322
+ " </resource>\n " +
323
+ " <resource type=\" BinaryResource\" name=\" doc4.html\" owner=\" admin\" group=\" dba\" mode=\" 644\" created=\" 2019-05-15T15:58:49.618+04:00\" modified=\" 2019-05-15T15:58:49.618+04:00\" filename=\" doc4.html\" mimetype=\" text/xhtml\" >\n " +
324
+ " <acl entries=\" 0\" version=\" 1\" />\n " +
325
+ " </resource>\n " +
326
+ " <resource type=\" BinaryResource\" name=\" doc5.html\" owner=\" admin\" group=\" dba\" mode=\" 644\" created=\" 2019-05-15T15:58:49.618+04:00\" modified=\" 2019-05-15T15:58:49.618+04:00\" filename=\" doc5.html\" mimetype=\" text/html\" >\n " +
309
327
" <acl entries=\" 0\" version=\" 1\" />\n " +
310
328
" </resource>\n " +
311
329
"</collection>" ;
312
330
313
331
final String doc1 = "<doc1/>" ;
314
332
final String doc2 = "<doc2/>" ;
315
333
final String doc3 = "<doc3/>" ;
334
+ final String doc4 = "<html><body><hr/></body></html>" ;
335
+ final String doc5 = "<html><body><hr></body></html>" ;
316
336
317
337
final Path dbContentsFile = Files .write (db .resolve (BackupDescriptor .COLLECTION_DESCRIPTOR ), dbContents .getBytes (UTF_8 ));
318
338
final Path col1ContentsFile = Files .write (col1 .resolve (BackupDescriptor .COLLECTION_DESCRIPTOR ), col1Contents .getBytes (UTF_8 ));
319
- Files .write (col1 .resolve ("doc1.xml" ), doc1 .getBytes (UTF_8 ));
320
- Files .write (col1 .resolve ("doc2.xml" ), doc2 .getBytes (UTF_8 ));
321
- Files .write (col1 .resolve ("doc3.xml" ), doc3 .getBytes (UTF_8 ));
339
+ Files .write (col1 .resolve ("doc1.xml" ), doc1 .getBytes (UTF_8 ));
340
+ Files .write (col1 .resolve ("doc2.xml" ), doc2 .getBytes (UTF_8 ));
341
+ Files .write (col1 .resolve ("doc3.xml" ), doc3 .getBytes (UTF_8 ));
342
+ Files .write (col1 .resolve ("doc4.html" ), doc4 .getBytes (UTF_8 ));
343
+ Files .write (col1 .resolve ("doc5.html" ), doc5 .getBytes (UTF_8 ));
322
344
323
345
return dbContentsFile ;
324
346
}
@@ -335,26 +357,26 @@ private static Path createBackupWithInvalidContent() throws IOException {
335
357
336
358
final String contents =
337
359
"<collection xmlns=\" http://exist.sourceforge.net/NS/exist\" name=\" /db/col1\" owner=\" admin\" group=\" dba\" mode=\" 755\" created=\" 2019-05-15T15:58:39.385+04:00\" deduplicate-blobs=\" false\" version=\" 2\" >\n " +
338
- " <acl entries=\" 0\" version=\" 1\" />\n " +
339
- " <resource type=\" XMLResource\" name=\" doc1.xml\" owner=\" admin\" group=\" dba\" mode=\" 644\" created=\" 2019-05-15T15:58:48.638+04:00\" modified=\" 2019-05-15T15:58:48.638+04:00\" filename=\" doc1.xml\" mimetype=\" application/xml\" >\n " +
340
- " <acl entries=\" 0\" version=\" 1\" />\n " +
341
- " </resource>\n " +
342
- " <resource type=\" XMLResource\" name=\" doc2.xml\" owner=\" admin\" group=\" dba\" mode=\" 644\" created=\" 2019-05-15T15:58:48.638+04:00\" modified=\" 2019-05-15T15:58:48.638+04:00\" filename=\" doc2.xml\" mimetype=\" application/xml\" >\n " +
343
- " <acl entries=\" 0\" version=\" 1\" />\n " +
344
- " </resource>\n " +
345
- " <resource type=\" XMLResource\" name=\" doc3.xml\" owner=\" admin\" group=\" dba\" mode=\" 644\" created=\" 2019-05-15T15:58:49.618+04:00\" modified=\" 2019-05-15T15:58:49.618+04:00\" filename=\" doc3.xml\" mimetype=\" application/xml\" >\n " +
346
- " <acl entries=\" 0\" version=\" 1\" />\n " +
347
- " </resource>\n " +
348
- "</collection>" ;
360
+ " <acl entries=\" 0\" version=\" 1\" />\n " +
361
+ " <resource type=\" XMLResource\" name=\" doc1.xml\" owner=\" admin\" group=\" dba\" mode=\" 644\" created=\" 2019-05-15T15:58:48.638+04:00\" modified=\" 2019-05-15T15:58:48.638+04:00\" filename=\" doc1.xml\" mimetype=\" application/xml\" >\n " +
362
+ " <acl entries=\" 0\" version=\" 1\" />\n " +
363
+ " </resource>\n " +
364
+ " <resource type=\" XMLResource\" name=\" doc2.xml\" owner=\" admin\" group=\" dba\" mode=\" 644\" created=\" 2019-05-15T15:58:48.638+04:00\" modified=\" 2019-05-15T15:58:48.638+04:00\" filename=\" doc2.xml\" mimetype=\" application/xml\" >\n " +
365
+ " <acl entries=\" 0\" version=\" 1\" />\n " +
366
+ " </resource>\n " +
367
+ " <resource type=\" XMLResource\" name=\" doc3.xml\" owner=\" admin\" group=\" dba\" mode=\" 644\" created=\" 2019-05-15T15:58:49.618+04:00\" modified=\" 2019-05-15T15:58:49.618+04:00\" filename=\" doc3.xml\" mimetype=\" application/xml\" >\n " +
368
+ " <acl entries=\" 0\" version=\" 1\" />\n " +
369
+ " </resource>\n " +
370
+ "</collection>" ;
349
371
350
372
final String doc1 = "<doc1/>" ;
351
373
final String doc2 = "<doc2>invalid" ;
352
374
final String doc3 = "<doc3/>" ;
353
375
354
376
final Path contentsFile = Files .write (col1 .resolve (BackupDescriptor .COLLECTION_DESCRIPTOR ), contents .getBytes (UTF_8 ));
355
- Files .write (col1 .resolve ("doc1.xml" ), doc1 .getBytes (UTF_8 ));
356
- Files .write (col1 .resolve ("doc2.xml" ), doc2 .getBytes (UTF_8 ));
357
- Files .write (col1 .resolve ("doc3.xml" ), doc3 .getBytes (UTF_8 ));
377
+ Files .write (col1 .resolve ("doc1.xml" ), doc1 .getBytes (UTF_8 ));
378
+ Files .write (col1 .resolve ("doc2.xml" ), doc2 .getBytes (UTF_8 ));
379
+ Files .write (col1 .resolve ("doc3.xml" ), doc3 .getBytes (UTF_8 ));
358
380
359
381
return contentsFile ;
360
382
}
@@ -417,10 +439,10 @@ private static Path createBackupWithUserWithoutPrimaryGroup(final String usernam
417
439
"<enabled>true</enabled>\n " +
418
440
"<umask>022</umask>\n " +
419
441
"<name>" + username + "</name>\n " +
420
- "</account>" ;
442
+ "</account>" ;
421
443
422
444
final Path contentsFile = Files .write (accountsCol .resolve (BackupDescriptor .COLLECTION_DESCRIPTOR ), contents .getBytes (UTF_8 ));
423
- Files .write (accountsCol .resolve (username + ".xml" ), invalidUserDoc .getBytes (UTF_8 ));
445
+ Files .write (accountsCol .resolve (username + ".xml" ), invalidUserDoc .getBytes (UTF_8 ));
424
446
425
447
return contentsFile ;
426
448
}
@@ -449,10 +471,10 @@ private static Path createBackupWithUserInNoSuchGroup(final String username) thr
449
471
"<enabled>true</enabled>\n " +
450
472
"<umask>022</umask>\n " +
451
473
"<name>" + username + "</name>\n " +
452
- "</account>\n " ;
474
+ "</account>\n " ;
453
475
454
476
final Path contentsFile = Files .write (accountsCol .resolve (BackupDescriptor .COLLECTION_DESCRIPTOR ), contents .getBytes (UTF_8 ));
455
- Files .write (accountsCol .resolve (username + ".xml" ), invalidUserDoc .getBytes (UTF_8 ));
477
+ Files .write (accountsCol .resolve (username + ".xml" ), invalidUserDoc .getBytes (UTF_8 ));
456
478
457
479
return contentsFile ;
458
480
}
@@ -497,11 +519,11 @@ private static void createBackupWithUserInGroups(final Path backupDir, final Str
497
519
for (final String groupName : groupNames ) {
498
520
groupsContents .append (
499
521
" <resource type=\" XMLResource\" name=\" " + groupName + ".xml\" owner=\" SYSTEM\" group=\" dba\" mode=\" 770\" created=\" 2019-05-15T15:58:48.638+04:00\" modified=\" 2019-05-15T15:58:48.638+04:00\" filename=\" " + groupName + ".xml\" mimetype=\" application/xml\" >\n " +
500
- " <acl entries=\" 0\" version=\" 1\" />\n " +
501
- " </resource>\n " );
522
+ " <acl entries=\" 0\" version=\" 1\" />\n " +
523
+ " </resource>\n " );
502
524
}
503
525
groupsContents .append (
504
- "</collection>" );
526
+ "</collection>" );
505
527
506
528
final String accountsContents =
507
529
"<collection xmlns=\" http://exist.sourceforge.net/NS/exist\" name=\" /db/system/security/exist/accounts\" owner=\" SYSTEM\" group=\" dba\" mode=\" 770\" created=\" 2019-05-15T15:58:39.385+04:00\" deduplicate-blobs=\" false\" version=\" 2\" >\n " +
@@ -520,14 +542,14 @@ private static void createBackupWithUserInGroups(final Path backupDir, final Str
520
542
"<digestPassword>" + backupPasswordDigest + "</digestPassword>\n " );
521
543
for (final String groupName : groupNames ) {
522
544
userDoc .append (
523
- "<group name=\" " + groupName + "\" />\n " );
545
+ "<group name=\" " + groupName + "\" />\n " );
524
546
}
525
547
userDoc .append (
526
- "<expired>false</expired>\n " +
548
+ "<expired>false</expired>\n " +
527
549
"<enabled>true</enabled>\n " +
528
550
"<umask>022</umask>\n " +
529
551
"<name>" + username + "</name>\n " +
530
- "</account>\n " );
552
+ "</account>\n " );
531
553
532
554
final Path dbContentsFile = Files .write (dbCol .resolve (BackupDescriptor .COLLECTION_DESCRIPTOR ), dbContents .getBytes (UTF_8 ));
533
555
final Path systemContentsFile = Files .write (systemCol .resolve (BackupDescriptor .COLLECTION_DESCRIPTOR ), systemContents .getBytes (UTF_8 ));
@@ -540,15 +562,15 @@ private static void createBackupWithUserInGroups(final Path backupDir, final Str
540
562
for (final String groupName : groupNames ) {
541
563
final String groupDoc =
542
564
"<group xmlns=\" http://exist-db.org/Configuration\" id=\" " + (groupId ++) + "\" >\n " +
543
- " <manager name=\" admin\" />\n " +
544
- " <metadata key=\" http://exist-db.org/security/description\" >Group named: " + groupName + "</metadata>\n " +
545
- " <name>" + groupName + "</name>\n " +
546
- "</group>" ;
565
+ " <manager name=\" admin\" />\n " +
566
+ " <metadata key=\" http://exist-db.org/security/description\" >Group named: " + groupName + "</metadata>\n " +
567
+ " <name>" + groupName + "</name>\n " +
568
+ "</group>" ;
547
569
548
570
Files .write (groupsCol .resolve (groupName + ".xml" ), groupDoc .getBytes (UTF_8 ));
549
571
}
550
572
551
- Files .write (accountsCol .resolve (username + ".xml" ), userDoc .toString ().getBytes (UTF_8 ));
573
+ Files .write (accountsCol .resolve (username + ".xml" ), userDoc .toString ().getBytes (UTF_8 ));
552
574
}
553
575
554
576
private static byte [] ripemd160 (final String s ) {
0 commit comments