use of ch.cyberduck.core.googledrive.DriveListService in project cyberduck by iterate-ch.
the class DriveWriteFeatureTest method testWriteWithCache.
@Test
public void testWriteWithCache() throws Exception {
final TransferStatus status = new TransferStatus();
final int length = 1048576;
final byte[] content = RandomUtils.nextBytes(length);
status.setLength(content.length);
final Path home = DriveHomeFinderService.MYDRIVE_FOLDER;
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final CryptoVault cryptomator = new CryptoVault(vault);
cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final DriveFileIdProvider fileid = new DriveFileIdProvider(session);
final CryptoWriteFeature<File> writer = new CryptoWriteFeature<>(session, new DriveWriteFeature(session, fileid), cryptomator);
final FileHeader header = cryptomator.getFileHeaderCryptor().create();
status.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
status.setNonces(new RandomNonceGenerator());
status.setChecksum(writer.checksum(test, status).compute(new ByteArrayInputStream(content), status));
final OutputStream out = writer.write(test, status, new DisabledConnectionCallback());
assertNotNull(out);
new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
out.close();
assertTrue(new CryptoFindFeature(session, new DriveFindFeature(session, fileid), cryptomator).find(test));
final Path found = new CryptoListService(session, new DriveListService(session, fileid), cryptomator).list(test.getParent(), new DisabledListProgressListener()).find(new SimplePathPredicate(test));
final String fileId = found.attributes().getFileId();
assertNotNull(fileId);
final Cache<Path> cache = new PathCache(1);
final AttributedList<Path> list = new AttributedList<>();
list.add(found);
cache.put(vault, list);
assertEquals(content.length, cache.get(vault).get(0).attributes().getSize());
assertEquals(content.length, found.attributes().getSize());
assertEquals(content.length, writer.append(test, status.withRemote(found.attributes())).size, 0L);
{
final PathAttributes attributes = new CryptoAttributesFeature(session, new DriveAttributesFinderFeature(session, fileid), cryptomator).find(test);
assertEquals(content.length, attributes.getSize());
assertEquals(fileId, found.attributes().getFileId());
}
{
final PathAttributes attributes = new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator).find(test);
assertEquals(content.length, attributes.getSize());
assertEquals(fileId, found.attributes().getFileId());
}
{
final PathAttributes attributes = new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator).find(test);
assertEquals(content.length, attributes.getSize());
assertEquals(fileId, found.attributes().getFileId());
}
assertEquals(content.length, cache.get(vault).get(0).attributes().getSize());
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new DriveReadFeature(session, fileid), cryptomator).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
new StreamCopier(status, status).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
cryptomator.getFeature(session, Delete.class, new DriveDeleteFeature(session, fileid)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
session.close();
}
use of ch.cyberduck.core.googledrive.DriveListService in project cyberduck by iterate-ch.
the class DriveAttributesFinderFeatureTest method testFindDefaultAttributesFinderWithCacheCryptomator.
@Test
public void testFindDefaultAttributesFinderWithCacheCryptomator() throws Exception {
final Path home = DriveHomeFinderService.MYDRIVE_FOLDER;
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final CryptoVault cryptomator = new CryptoVault(vault);
cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final DriveFileIdProvider idProvider = new DriveFileIdProvider(session);
final Path test = new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new DriveWriteFeature(session, idProvider)), new DriveWriteFeature(session, idProvider), cryptomator).touch(new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
final Path found = new CryptoListService(session, new DriveListService(session, idProvider), cryptomator).list(test.getParent(), new DisabledListProgressListener()).find(new SimplePathPredicate(test));
assertEquals(0L, found.attributes().getSize());
final Cache<Path> cache = new PathCache(1);
final AttributedList<Path> list = new AttributedList<>();
list.add(found);
cache.put(vault, list);
final PathAttributes attributes = new CachingAttributesFinderFeature(cache, new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator)).find(test);
assertNotNull(attributes);
assertEquals(0L, attributes.getSize());
assertEquals(0L, cache.get(vault).get(0).attributes().getSize());
cryptomator.getFeature(session, Delete.class, new DriveDeleteFeature(session, idProvider)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
session.close();
}
use of ch.cyberduck.core.googledrive.DriveListService in project cyberduck by iterate-ch.
the class DriveTouchFeatureTest method testTouchLongFilenameEncrypted.
@Test
public void testTouchLongFilenameEncrypted() throws Exception {
assumeTrue(vaultVersion == CryptoVault.VAULT_VERSION_DEPRECATED);
final Path home = DriveHomeFinderService.MYDRIVE_FOLDER;
final CryptoVault cryptomator = new CryptoVault(new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)));
final Path vault = cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final DriveFileIdProvider idProvider = new DriveFileIdProvider(session);
final Path test = new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new DriveWriteFeature(session, idProvider)), new DriveWriteFeature(session, idProvider), cryptomator).touch(new Path(vault, new AlphanumericRandomStringService(130).random(), EnumSet.of(Path.Type.file)), new TransferStatus());
assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test));
final Path found = new CryptoListService(session, new DriveListService(session, idProvider), cryptomator).list(test.getParent(), new DisabledListProgressListener()).find(new SimplePathPredicate(test));
final String fileId = found.attributes().getFileId();
assertNotNull(fileId);
cryptomator.getFeature(session, Delete.class, new DriveDeleteFeature(session, idProvider)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.googledrive.DriveListService in project cyberduck by iterate-ch.
the class DriveTouchFeatureTest method testTouchLongFilenameEncryptedDefaultFeature.
@Test
public void testTouchLongFilenameEncryptedDefaultFeature() throws Exception {
assumeTrue(vaultVersion == CryptoVault.VAULT_VERSION_DEPRECATED);
final Path home = DriveHomeFinderService.MYDRIVE_FOLDER;
final CryptoVault cryptomator = new CryptoVault(new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)));
final Path vault = cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final DriveFileIdProvider idProvider = new DriveFileIdProvider(session);
final Path test = new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new DriveWriteFeature(session, idProvider)), new DriveWriteFeature(session, idProvider), cryptomator).touch(new Path(vault, new AlphanumericRandomStringService(130).random(), EnumSet.of(Path.Type.file)), new TransferStatus());
assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test));
final Path found = new CryptoListService(session, new DriveListService(session, idProvider), cryptomator).list(test.getParent(), new DisabledListProgressListener()).find(new SimplePathPredicate(test));
final String fileId = found.attributes().getFileId();
assertNotNull(fileId);
cryptomator.getFeature(session, Delete.class, new DriveDeleteFeature(session, idProvider)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.googledrive.DriveListService in project cyberduck by iterate-ch.
the class DriveAttributesFinderFeatureTest method testFindDirectoryDefaultAttributesFinderWithCacheCryptomator.
@Test
public void testFindDirectoryDefaultAttributesFinderWithCacheCryptomator() throws Exception {
final Path home = DriveHomeFinderService.MYDRIVE_FOLDER;
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final CryptoVault cryptomator = new CryptoVault(vault);
cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final DriveFileIdProvider idProvider = new DriveFileIdProvider(session);
assertEquals(new CryptoFileIdProvider(session, idProvider, cryptomator).getFileId(vault, new DisabledListProgressListener()), idProvider.getFileId(vault, new DisabledListProgressListener()));
final Path test = cryptomator.getFeature(session, Directory.class, new DriveDirectoryFeature(session, idProvider)).mkdir(new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
final String fileId = test.attributes().getFileId();
assertNotNull(fileId);
final Path found = new CryptoListService(session, new DriveListService(session, idProvider), cryptomator).list(test.getParent(), new DisabledListProgressListener()).find(new SimplePathPredicate(test));
assertNull(found.attributes().getFileId());
assertEquals(fileId, new CryptoFileIdProvider(session, idProvider, cryptomator).getFileId(found, new DisabledListProgressListener()));
final Cache<Path> cache = new PathCache(1);
final AttributedList<Path> list = new AttributedList<>();
list.add(test);
cache.put(vault, list);
final PathAttributes attributes = new CachingAttributesFinderFeature(cache, new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator)).find(test);
assertEquals(fileId, attributes.getFileId());
cryptomator.getFeature(session, Delete.class, new DriveDeleteFeature(session, idProvider)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
session.close();
}
Aggregations