55package ch .iterate .hub .core ;
66
77import ch .cyberduck .core .*;
8+ import ch .cyberduck .core .exception .BackgroundException ;
89import ch .cyberduck .core .features .Bulk ;
10+ import ch .cyberduck .core .features .Directory ;
911import ch .cyberduck .core .features .Home ;
10- import ch .cyberduck .core .features .Touch ;
12+ import ch .cyberduck .core .features .Read ;
1113import ch .cyberduck .core .features .Vault ;
1214import ch .cyberduck .core .features .Write ;
13- import ch .cyberduck .core .io .ChecksumComputeFactory ;
14- import ch .cyberduck .core .io .HashAlgorithm ;
1515import ch .cyberduck .core .io .StatusOutputStream ;
1616import ch .cyberduck .core .preferences .PreferencesFactory ;
1717import ch .cyberduck .core .proxy .DisabledProxyFinder ;
2727import org .apache .commons .lang3 .StringUtils ;
2828import org .apache .logging .log4j .LogManager ;
2929import org .apache .logging .log4j .Logger ;
30+ import org .jetbrains .annotations .NotNull ;
3031import org .junit .jupiter .api .Assertions ;
3132import org .junit .jupiter .api .Disabled ;
3233import org .junit .jupiter .api .Test ;
3334import org .junit .jupiter .params .ParameterizedTest ;
3435import org .openapitools .jackson .nullable .JsonNullableModule ;
3536
3637import java .io .ByteArrayInputStream ;
38+ import java .io .IOException ;
39+ import java .util .Arrays ;
3740import java .util .Collections ;
3841import java .util .EnumSet ;
3942import java .util .List ;
6063import com .fasterxml .jackson .annotation .JsonInclude ;
6164import com .fasterxml .jackson .databind .ObjectMapper ;
6265
63- import org .testcontainers .shaded .org .apache .commons .io .input .NullInputStream ;
64-
6566import static ch .iterate .hub .testsetup .HubTestUtilities .getAdminApiClient ;
6667import static org .junit .jupiter .api .Assertions .*;
6768
6869public abstract class AbstractHubSynchronizeTest extends AbstractHubTest {
6970 private static final Logger log = LogManager .getLogger (AbstractHubSynchronizeTest .class .getName ());
7071
7172 /**
72- * Use to start unattended setup and then run
73+ * Use to start unattended setup and then run tests with PUnattendedMinio.
74+ *
7375 * @throws InterruptedException
7476 */
7577 @ Test
@@ -259,29 +261,50 @@ public void test03AddVault(final HubTestConfig config) throws Exception {
259261
260262 final Path bucket = new Path (vaultBookmark .getDefaultPath (), EnumSet .of (Path .Type .directory , Path .Type .volume , Path .Type .vault ));
261263 assertNotSame (Vault .DISABLED , vaultRegistry .find (session , bucket ));
264+
262265 {
266+ // encrypted file listing
263267 final AttributedList <Path > list = session .getFeature (ListService .class ).list (bucket , new DisabledListProgressListener ());
264268 assertTrue (list .isEmpty ());
265269 }
266270 {
271+ // encrypted file upload
267272 final Path home = vaultRegistry .find (session , bucket ).getHome ();
268- Path file = new Path (home , "gugus.txt" , EnumSet .of (AbstractPath .Type .file ));
269- byte [] content = RandomUtils .nextBytes (234 );
270- TransferStatus transferStatus = new TransferStatus ().withLength (content .length );
271- transferStatus .setChecksum (session .getFeature (Write .class ).checksum (file , transferStatus ).compute (new ByteArrayInputStream (content ), transferStatus ));
272- session .getFeature (Bulk .class ).pre (Transfer .Type .upload , Collections .singletonMap (new TransferItem (file ), transferStatus ), new DisabledConnectionCallback ());
273- StatusOutputStream <?> out = session .getFeature (Write .class ).write (file , transferStatus , new DisabledConnectionCallback ());
274- IOUtils .copyLarge (new ByteArrayInputStream (content ), out );
275- out .close ();
273+ final Path file = new Path (home , new AlphanumericRandomStringService (25 ).random (), EnumSet .of (AbstractPath .Type .file ));
274+ byte [] content = writeRandomFile (session , file , 234 );
276275 final AttributedList <Path > list = session .getFeature (ListService .class ).list (bucket , new DisabledListProgressListener ());
277- assertFalse (list .isEmpty ());
276+ assertEquals (1 , list .size ());
277+ assertEquals (file .getName (), list .get (0 ).getName ());
278+
279+ byte [] actual = new byte [300 ];
280+ int l = session .getFeature (Read .class ).read (file , new TransferStatus (), new DisabledConnectionCallback ()).read (actual );
281+ assertArrayEquals (content , Arrays .copyOfRange (actual , 0 , l ));
282+ assert l == 234 ;
278283 }
284+ {
285+ // encrypted directory creation and listing
286+ final Path home = vaultRegistry .find (session , bucket ).getHome ();
287+ final Path folder = new Path (home , new AlphanumericRandomStringService (25 ).random (), EnumSet .of (AbstractPath .Type .directory ));
288+
289+ session .getFeature (Directory .class ).mkdir (folder , new TransferStatus ());
290+ final AttributedList <Path > list = session .getFeature (ListService .class ).list (bucket , new DisabledListProgressListener ());
291+ assertEquals (2 , list .size ());
279292
280- // raw listing encrypted file names
281- vaultRegistry .close (bucket );
282- assertSame (Vault .DISABLED , vaultRegistry .find (session , bucket ));
283- assertTrue (vaultRegistry .isEmpty ());
293+ {
294+ // encrypted file upload in subfolder
295+ final Path file = new Path (folder , new AlphanumericRandomStringService (25 ).random (), EnumSet .of (AbstractPath .Type .file ));
296+ writeRandomFile (session , file , 555 );
297+ final AttributedList <Path > sublist = session .getFeature (ListService .class ).list (folder , new DisabledListProgressListener ());
298+ assertEquals (1 , sublist .size ());
299+ assertEquals (file .getName (), sublist .get (0 ).getName ());
300+ }
301+ }
284302 {
303+ // raw listing encrypted file names
304+ vaultRegistry .close (bucket );
305+ assertSame (Vault .DISABLED , vaultRegistry .find (session , bucket ));
306+ assertTrue (vaultRegistry .isEmpty ());
307+
285308 final AttributedList <Path > list = session .getFeature (ListService .class ).list (bucket , new DisabledListProgressListener ());
286309 assertFalse (list .isEmpty ());
287310 assertEquals (2 , list .size ());
@@ -293,4 +316,15 @@ public void test03AddVault(final HubTestConfig config) throws Exception {
293316 hubSession .close ();
294317 }
295318 }
319+
320+ private static byte @ NotNull [] writeRandomFile (final Session <?> session , final Path file , int size ) throws BackgroundException , IOException {
321+ final byte [] content = RandomUtils .nextBytes (size );
322+ final TransferStatus transferStatus = new TransferStatus ().withLength (content .length );
323+ transferStatus .setChecksum (session .getFeature (Write .class ).checksum (file , transferStatus ).compute (new ByteArrayInputStream (content ), transferStatus ));
324+ session .getFeature (Bulk .class ).pre (Transfer .Type .upload , Collections .singletonMap (new TransferItem (file ), transferStatus ), new DisabledConnectionCallback ());
325+ final StatusOutputStream <?> out = session .getFeature (Write .class ).write (file , transferStatus , new DisabledConnectionCallback ());
326+ IOUtils .copyLarge (new ByteArrayInputStream (content ), out );
327+ out .close ();
328+ return content ;
329+ }
296330}
0 commit comments