Skip to content

Commit 4c25df7

Browse files
committed
Add test to access vault contents.
1 parent 50546de commit 4c25df7

File tree

1 file changed

+22
-56
lines changed

1 file changed

+22
-56
lines changed

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

Lines changed: 22 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919
import ch.cyberduck.core.Session;
2020
import ch.cyberduck.core.SimplePathPredicate;
2121
import ch.cyberduck.core.features.Home;
22+
import ch.cyberduck.core.features.Vault;
2223
import ch.cyberduck.core.preferences.PreferencesFactory;
2324
import ch.cyberduck.core.proxy.DisabledProxyFinder;
2425
import ch.cyberduck.core.ssl.DefaultX509KeyManager;
2526
import ch.cyberduck.core.ssl.DisabledX509TrustManager;
2627
import ch.cyberduck.core.vault.DefaultVaultRegistry;
27-
import ch.cyberduck.core.vault.LoadingVaultLookupListener;
28-
import ch.cyberduck.core.vault.registry.VaultRegistryListService;
2928

3029
import org.apache.commons.lang3.StringUtils;
3130
import org.apache.logging.log4j.LogManager;
@@ -34,11 +33,8 @@
3433
import org.junit.jupiter.params.ParameterizedTest;
3534
import org.openapitools.jackson.nullable.JsonNullableModule;
3635

37-
import java.text.SimpleDateFormat;
38-
import java.util.Date;
3936
import java.util.EnumSet;
4037
import java.util.List;
41-
import java.util.TimeZone;
4238
import java.util.UUID;
4339

4440
import ch.iterate.hub.client.ApiClient;
@@ -54,7 +50,7 @@
5450
import ch.iterate.hub.protocols.hub.HubStorageProfileListService;
5551
import ch.iterate.hub.protocols.hub.HubStorageProfileSyncSchedulerService;
5652
import ch.iterate.hub.protocols.hub.HubStorageVaultSyncSchedulerService;
57-
import ch.iterate.hub.protocols.s3.S3AssumeRoleSession;
53+
import ch.iterate.hub.protocols.s3.S3AutoLoadVaultSession;
5854
import ch.iterate.hub.testsetup.AbstractHubTest;
5955
import ch.iterate.hub.testsetup.HubTestConfig;
6056
import ch.iterate.hub.testsetup.MethodIgnorableSource;
@@ -68,9 +64,6 @@
6864
public abstract class AbstractHubSynchronizeTest extends AbstractHubTest {
6965
private static final Logger log = LogManager.getLogger(AbstractHubSynchronizeTest.class.getName());
7066

71-
// allow for 15s time difference
72-
private static final int LAG = 15000;
73-
7467
/**
7568
* Verify storage profiles are synced from hub bookmark.
7669
*/
@@ -240,58 +233,31 @@ public void test03AddVault(final HubTestConfig config) throws Exception {
240233
final Host vaultBookmark = new HubStorageVaultSyncSchedulerService(hubSession).toBookmark(vaultId, FirstLoginDeviceSetupCallback.disabled);
241234
log.info(String.format("Using vault bookmark %s", vaultBookmark));
242235

243-
final Session<?> session = new S3AssumeRoleSession(vaultBookmark, new DisabledX509TrustManager(), new DefaultX509KeyManager());
236+
final DefaultVaultRegistry vaultRegistry = new DefaultVaultRegistry(new DisabledPasswordCallback());
237+
final Session<?> session = new S3AutoLoadVaultSession(vaultBookmark, new DisabledX509TrustManager(), new DefaultX509KeyManager())
238+
.withRegistry(vaultRegistry);
244239
session.open(new DisabledProxyFinder(), new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
245240
session.login(new DisabledLoginCallback(), new DisabledCancelCallback());
246241

247-
log.info(String.format("Listing bucket %s in %s", vaultBookmark.getDefaultPath(), vaultBookmark));
248-
final Date before = new Date();
242+
assertFalse(vaultRegistry.isEmpty());
243+
assertEquals(1, vaultRegistry.size());
249244
final Path bucket = new Path(vaultBookmark.getDefaultPath(), EnumSet.of(Path.Type.directory, Path.Type.volume));
250-
final AttributedList<Path> bucketListRaw = session.getFeature(ListService.class).list(bucket, new DisabledListProgressListener());
251-
final Date after = new Date();
252-
253-
log.info(before);
254-
log.info(after);
255-
log.info("paths:");
256-
257-
for(final Path path : bucketListRaw) {
258-
final Date date = new Date();
259-
date.setTime(path.attributes().getModificationDate());
260-
final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE dd-MMM-yy HH:mm:ssZ");
261-
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("Europe/London"));
262-
log.info(String.format("%s %s [%s,%s]", path,
263-
simpleDateFormat.format(date),
264-
simpleDateFormat.format(before),
265-
simpleDateFormat.format(after))
266-
);
267-
268-
if(path.isFile()) {
269-
date.setTime(path.attributes().getModificationDate() + LAG);
270-
assertTrue(date.after(before));
271-
date.setTime(path.attributes().getModificationDate() - LAG);
272-
assertTrue(date.before(after));
273-
}
274-
}
275-
final Path expectedPath = new Path(bucket, PreferencesFactory.get().getProperty("cryptomator.vault.config.filename"), EnumSet.of(AbstractPath.Type.file));
276-
log.info("expectedPath {}", expectedPath);
277-
assertNotNull(bucketListRaw.find(new SimplePathPredicate(expectedPath)));
278-
279-
final ListService proxy = session.getFeature(ListService.class);
280-
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordCallback());
281-
final ListService listService = new VaultRegistryListService(session, proxy, registry,
282-
new LoadingVaultLookupListener(registry, new DisabledPasswordCallback()));
283-
284-
// TODO https://github.com/shift7-ch/cipherduck-hub/issues/4 should this only list the vault and not more?
285-
// final AttributedList<Path> bucketList = ff.list(Home.ROOT, new DisabledListProgressListener());
286-
// assertEquals(1, bucketList.size());
287-
// assertTrue(bucketList.contains(bucket));
288-
final AttributedList<Path> vaultContents = listService.list(bucket, new DisabledListProgressListener());
289-
for(final Path path : vaultContents) {
290-
log.info(path);
245+
assertNotSame(Vault.DISABLED, vaultRegistry.find(session, bucket));
246+
247+
// {
248+
// final AttributedList<Path> list = session.getFeature(ListService.class).list(bucket, new DisabledListProgressListener());
249+
// assertTrue(list.isEmpty());
250+
// }
251+
252+
vaultRegistry.close(bucket);
253+
assertTrue(vaultRegistry.isEmpty());
254+
{
255+
final AttributedList<Path> list = session.getFeature(ListService.class).list(bucket, new DisabledListProgressListener());
256+
assertFalse(list.isEmpty());
257+
assertEquals(2, list.size());
258+
assertNotNull(list.find(new SimplePathPredicate(new Path(bucket, "d", EnumSet.of(Path.Type.directory, AbstractPath.Type.placeholder)))));
259+
assertNotNull(list.find(new SimplePathPredicate(new Path(bucket, PreferencesFactory.get().getProperty("cryptomator.vault.config.filename"), EnumSet.of(Path.Type.file)))));
291260
}
292-
assertEquals(2, vaultContents.size());
293-
assertNotNull(vaultContents.find(new SimplePathPredicate(expectedPath)));
294-
assertNotNull(vaultContents.find(new SimplePathPredicate(new Path(bucket, "d", EnumSet.of(Path.Type.directory, AbstractPath.Type.placeholder)))));
295261
}
296262
finally {
297263
hubSession.close();

0 commit comments

Comments
 (0)