|
19 | 19 | import ch.cyberduck.core.Session; |
20 | 20 | import ch.cyberduck.core.SimplePathPredicate; |
21 | 21 | import ch.cyberduck.core.features.Home; |
| 22 | +import ch.cyberduck.core.features.Vault; |
22 | 23 | import ch.cyberduck.core.preferences.PreferencesFactory; |
23 | 24 | import ch.cyberduck.core.proxy.DisabledProxyFinder; |
24 | 25 | import ch.cyberduck.core.ssl.DefaultX509KeyManager; |
25 | 26 | import ch.cyberduck.core.ssl.DisabledX509TrustManager; |
26 | 27 | import ch.cyberduck.core.vault.DefaultVaultRegistry; |
27 | | -import ch.cyberduck.core.vault.LoadingVaultLookupListener; |
28 | | -import ch.cyberduck.core.vault.registry.VaultRegistryListService; |
29 | 28 |
|
30 | 29 | import org.apache.commons.lang3.StringUtils; |
31 | 30 | import org.apache.logging.log4j.LogManager; |
|
34 | 33 | import org.junit.jupiter.params.ParameterizedTest; |
35 | 34 | import org.openapitools.jackson.nullable.JsonNullableModule; |
36 | 35 |
|
37 | | -import java.text.SimpleDateFormat; |
38 | | -import java.util.Date; |
39 | 36 | import java.util.EnumSet; |
40 | 37 | import java.util.List; |
41 | | -import java.util.TimeZone; |
42 | 38 | import java.util.UUID; |
43 | 39 |
|
44 | 40 | import ch.iterate.hub.client.ApiClient; |
|
54 | 50 | import ch.iterate.hub.protocols.hub.HubStorageProfileListService; |
55 | 51 | import ch.iterate.hub.protocols.hub.HubStorageProfileSyncSchedulerService; |
56 | 52 | import ch.iterate.hub.protocols.hub.HubStorageVaultSyncSchedulerService; |
57 | | -import ch.iterate.hub.protocols.s3.S3AssumeRoleSession; |
| 53 | +import ch.iterate.hub.protocols.s3.S3AutoLoadVaultSession; |
58 | 54 | import ch.iterate.hub.testsetup.AbstractHubTest; |
59 | 55 | import ch.iterate.hub.testsetup.HubTestConfig; |
60 | 56 | import ch.iterate.hub.testsetup.MethodIgnorableSource; |
|
68 | 64 | public abstract class AbstractHubSynchronizeTest extends AbstractHubTest { |
69 | 65 | private static final Logger log = LogManager.getLogger(AbstractHubSynchronizeTest.class.getName()); |
70 | 66 |
|
71 | | - // allow for 15s time difference |
72 | | - private static final int LAG = 15000; |
73 | | - |
74 | 67 | /** |
75 | 68 | * Verify storage profiles are synced from hub bookmark. |
76 | 69 | */ |
@@ -240,58 +233,31 @@ public void test03AddVault(final HubTestConfig config) throws Exception { |
240 | 233 | final Host vaultBookmark = new HubStorageVaultSyncSchedulerService(hubSession).toBookmark(vaultId, FirstLoginDeviceSetupCallback.disabled); |
241 | 234 | log.info(String.format("Using vault bookmark %s", vaultBookmark)); |
242 | 235 |
|
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); |
244 | 239 | session.open(new DisabledProxyFinder(), new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback()); |
245 | 240 | session.login(new DisabledLoginCallback(), new DisabledCancelCallback()); |
246 | 241 |
|
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()); |
249 | 244 | 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))))); |
291 | 260 | } |
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))))); |
295 | 261 | } |
296 | 262 | finally { |
297 | 263 | hubSession.close(); |
|
0 commit comments