Skip to content

Commit bade78b

Browse files
committed
Add file upload to test03AddVault. Add preparations for uvf file/directory name encryption.
1 parent 6001100 commit bade78b

File tree

1 file changed

+65
-9
lines changed

1 file changed

+65
-9
lines changed

hub/src/test/java/ch/iterate/hub/core/AbstractHubSynchronizeTest.java

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,34 @@
55
package ch.iterate.hub.core;
66

77
import ch.cyberduck.core.*;
8+
import ch.cyberduck.core.features.Touch;
9+
import ch.cyberduck.core.features.Write;
810
import ch.cyberduck.core.preferences.PreferencesFactory;
11+
import ch.cyberduck.core.transfer.TransferStatus;
912
import ch.cyberduck.core.vault.DefaultVaultRegistry;
1013
import ch.cyberduck.core.vault.LoadingVaultLookupListener;
1114
import ch.cyberduck.core.vault.registry.VaultRegistryListService;
1215

16+
import ch.cyberduck.core.vault.registry.VaultRegistryTouchFeature;
17+
import ch.cyberduck.core.vault.registry.VaultRegistryWriteFeature;
18+
19+
import ch.iterate.hub.client.api.VaultResourceApi;
20+
import ch.iterate.hub.crypto.UserKeys;
21+
import ch.iterate.hub.crypto.uvf.UvfMetadataPayload;
22+
import ch.iterate.hub.workflows.UserKeysService;
23+
import ch.iterate.hub.workflows.UserKeysServiceImpl;
24+
import ch.iterate.hub.workflows.VaultServiceImpl;
25+
import com.google.common.primitives.Bytes;
26+
import com.nimbusds.jose.util.Base64URL;
27+
1328
import org.apache.logging.log4j.LogManager;
1429
import org.apache.logging.log4j.Logger;
1530
import org.junit.jupiter.api.Assertions;
1631
import org.junit.jupiter.params.ParameterizedTest;
1732
import org.openapitools.jackson.nullable.JsonNullableModule;
1833

1934
import java.text.SimpleDateFormat;
35+
import java.util.Base64;
2036
import java.util.Date;
2137
import java.util.EnumSet;
2238
import java.util.List;
@@ -296,23 +312,63 @@ public void test03AddVault(final HubTestConfig hubTestConfig) throws Exception {
296312

297313
final ListService proxy = session.getFeature(ListService.class);
298314
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordCallback());
299-
final ListService ff = new VaultRegistryListService(session, proxy, registry,
300-
new LoadingVaultLookupListener(registry, new DisabledPasswordCallback()));
301315

302-
// TODO https://github.com/shift7-ch/cipherduck-hub/issues/4 should this only list the vault and not more?
316+
// TODO https://github.com/shift7-ch/cipherduck-hub/issues/19 uncomment once filename/directory name encryptionn cryptolib uvf is fixed:
317+
/*final UserKeys userKeys = new UserKeysServiceImpl(hubSession).getUserKeys(hubSession.getHost(), FirstLoginDeviceSetupCallback.disabled);
318+
final UvfMetadataPayload vaultMetadata = new VaultServiceImpl(hubSession).getVaultMetadataJWE(vaultUuid, userKeys);
319+
byte[] rawFileKey = Base64URL.from((vaultMetadata.seeds().get(vaultMetadata.latestSeed()))).decode();
320+
byte[] rawNameKey = Base64URL.from((vaultMetadata.seeds().get(vaultMetadata.latestSeed()))).decode();
321+
final byte[] vaultKey = Bytes.concat(rawFileKey, rawNameKey);
322+
final PasswordCallback prompt = new PasswordCallback() {
323+
@Override
324+
public void close(final String input) {
325+
// nothing to do
326+
}
327+
328+
@Override
329+
public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) {
330+
return new Credentials().withPassword(Base64.getEncoder().encodeToString(vaultKey));
331+
}
332+
};*/
333+
final LoginCallback prompt = new DisabledLoginCallback();
334+
final ListService listService = new VaultRegistryListService(session, proxy, registry,
335+
new LoadingVaultLookupListener(registry, prompt));
336+
337+
// TODO https://github.com/shift7-ch/cipherduck-hub/issues/19 fix with plain text
303338
// final AttributedList<Path> bucketList = ff.list(new Path("/", EnumSet.of(Path.Type.directory, Path.Type.volume)), new DisabledListProgressListener());
304339
// for(final Path path : bucketList) {
305340
// log.info(path);
306341
// }
307342
// assertEquals(1, bucketList.size());
308343
// assertTrue(bucketList.contains(new Path(String.format("/%s", vaultBookmark.getDefaultPath()), EnumSet.of(Path.Type.directory, AbstractPath.Type.volume))));
309-
final AttributedList<Path> vaultContents = ff.list(new Path(String.format("/%s", vaultBookmark.getDefaultPath()), EnumSet.of(Path.Type.directory)), new DisabledListProgressListener());
310-
for(final Path path : vaultContents) {
311-
log.info(path);
344+
{
345+
final AttributedList<Path> vaultContents = listService.list(new Path(String.format("/%s", vaultBookmark.getDefaultPath()), EnumSet.of(Path.Type.directory)), new DisabledListProgressListener());
346+
for(final Path path : vaultContents) {
347+
log.info(path);
348+
}
349+
assertEquals(2, vaultContents.size());
350+
assertTrue(vaultContents.find(new SimplePathPredicate(expectedPath)) != null);
351+
// TODO https://github.com/shift7-ch/cipherduck-hub/issues/19 fix paths once filename/directory name encryptionn cryptolib uvf is fixed:
352+
assertTrue(vaultContents.find(new SimplePathPredicate(new Path(String.format("/%s/d", vaultBookmark.getDefaultPath()), EnumSet.of(Path.Type.directory, AbstractPath.Type.placeholder)))) != null);
353+
}
354+
355+
{
356+
357+
final VaultRegistryTouchFeature<Object> touchFeature = new VaultRegistryTouchFeature<>(session, session.getFeature(Touch.class), registry);
358+
touchFeature.touch(new Path(String.format("/%s/abcd.txt", vaultBookmark.getDefaultPath()), EnumSet.of(Path.Type.file)), new TransferStatus());
359+
}
360+
361+
{
362+
final AttributedList<Path> vaultContents = listService.list(new Path(String.format("/%s", vaultBookmark.getDefaultPath()), EnumSet.of(Path.Type.directory)), new DisabledListProgressListener());
363+
for(final Path path : vaultContents) {
364+
log.info(path);
365+
}
366+
assertEquals(3, vaultContents.size());
367+
assertTrue(vaultContents.find(new SimplePathPredicate(expectedPath)) != null);
368+
// TODO https://github.com/shift7-ch/cipherduck-hub/issues/19 fix paths once filename/directory name encryptionn cryptolib uvf is fixed:
369+
assertTrue(vaultContents.find(new SimplePathPredicate(new Path(String.format("/%s/d", vaultBookmark.getDefaultPath()), EnumSet.of(Path.Type.directory, AbstractPath.Type.placeholder)))) != null);
370+
assertTrue(vaultContents.find(new SimplePathPredicate(new Path(String.format("/%s/abcd.txt", vaultBookmark.getDefaultPath()), EnumSet.of(Path.Type.file)))) != null);
312371
}
313-
assertEquals(2, vaultContents.size());
314-
assertTrue(vaultContents.find(new SimplePathPredicate(expectedPath)) != null);
315-
assertTrue(vaultContents.find(new SimplePathPredicate(new Path(String.format("/%s/d", vaultBookmark.getDefaultPath()), EnumSet.of(Path.Type.directory, AbstractPath.Type.placeholder)))) != null);
316372
}
317373
finally {
318374
hubSession.close();

0 commit comments

Comments
 (0)