|
5 | 5 | package ch.iterate.hub.core; |
6 | 6 |
|
7 | 7 | import ch.cyberduck.core.*; |
| 8 | +import ch.cyberduck.core.features.Touch; |
| 9 | +import ch.cyberduck.core.features.Write; |
8 | 10 | import ch.cyberduck.core.preferences.PreferencesFactory; |
| 11 | +import ch.cyberduck.core.transfer.TransferStatus; |
9 | 12 | import ch.cyberduck.core.vault.DefaultVaultRegistry; |
10 | 13 | import ch.cyberduck.core.vault.LoadingVaultLookupListener; |
11 | 14 | import ch.cyberduck.core.vault.registry.VaultRegistryListService; |
12 | 15 |
|
| 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 | + |
13 | 28 | import org.apache.logging.log4j.LogManager; |
14 | 29 | import org.apache.logging.log4j.Logger; |
15 | 30 | import org.junit.jupiter.api.Assertions; |
16 | 31 | import org.junit.jupiter.params.ParameterizedTest; |
17 | 32 | import org.openapitools.jackson.nullable.JsonNullableModule; |
18 | 33 |
|
19 | 34 | import java.text.SimpleDateFormat; |
| 35 | +import java.util.Base64; |
20 | 36 | import java.util.Date; |
21 | 37 | import java.util.EnumSet; |
22 | 38 | import java.util.List; |
@@ -296,23 +312,63 @@ public void test03AddVault(final HubTestConfig hubTestConfig) throws Exception { |
296 | 312 |
|
297 | 313 | final ListService proxy = session.getFeature(ListService.class); |
298 | 314 | final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordCallback()); |
299 | | - final ListService ff = new VaultRegistryListService(session, proxy, registry, |
300 | | - new LoadingVaultLookupListener(registry, new DisabledPasswordCallback())); |
301 | 315 |
|
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 |
303 | 338 | // final AttributedList<Path> bucketList = ff.list(new Path("/", EnumSet.of(Path.Type.directory, Path.Type.volume)), new DisabledListProgressListener()); |
304 | 339 | // for(final Path path : bucketList) { |
305 | 340 | // log.info(path); |
306 | 341 | // } |
307 | 342 | // assertEquals(1, bucketList.size()); |
308 | 343 | // 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); |
312 | 371 | } |
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); |
316 | 372 | } |
317 | 373 | finally { |
318 | 374 | hubSession.close(); |
|
0 commit comments