Search in sources :

Example 1 with DriveListService

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();
}
Also used : Delete(ch.cyberduck.core.features.Delete) CryptoListService(ch.cyberduck.core.cryptomator.features.CryptoListService) DriveListService(ch.cyberduck.core.googledrive.DriveListService) CryptoWriteFeature(ch.cyberduck.core.cryptomator.features.CryptoWriteFeature) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) StatusOutputStream(ch.cyberduck.core.io.StatusOutputStream) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) DriveReadFeature(ch.cyberduck.core.googledrive.DriveReadFeature) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) CryptoReadFeature(ch.cyberduck.core.cryptomator.features.CryptoReadFeature) FileHeader(org.cryptomator.cryptolib.api.FileHeader) Path(ch.cyberduck.core.Path) PathCache(ch.cyberduck.core.PathCache) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PathAttributes(ch.cyberduck.core.PathAttributes) DriveWriteFeature(ch.cyberduck.core.googledrive.DriveWriteFeature) DriveDeleteFeature(ch.cyberduck.core.googledrive.DriveDeleteFeature) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DriveAttributesFinderFeature(ch.cyberduck.core.googledrive.DriveAttributesFinderFeature) RandomNonceGenerator(ch.cyberduck.core.cryptomator.random.RandomNonceGenerator) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) DefaultAttributesFinderFeature(ch.cyberduck.core.shared.DefaultAttributesFinderFeature) DriveFindFeature(ch.cyberduck.core.googledrive.DriveFindFeature) AttributedList(ch.cyberduck.core.AttributedList) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) SimplePathPredicate(ch.cyberduck.core.SimplePathPredicate) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) File(com.google.api.services.drive.model.File) DriveFileIdProvider(ch.cyberduck.core.googledrive.DriveFileIdProvider) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractDriveTest(ch.cyberduck.core.googledrive.AbstractDriveTest) Test(org.junit.Test)

Example 2 with DriveListService

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();
}
Also used : Delete(ch.cyberduck.core.features.Delete) CryptoListService(ch.cyberduck.core.cryptomator.features.CryptoListService) DriveListService(ch.cyberduck.core.googledrive.DriveListService) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) CachingAttributesFinderFeature(ch.cyberduck.core.CachingAttributesFinderFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) Path(ch.cyberduck.core.Path) PathCache(ch.cyberduck.core.PathCache) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) PathAttributes(ch.cyberduck.core.PathAttributes) DriveWriteFeature(ch.cyberduck.core.googledrive.DriveWriteFeature) DriveDeleteFeature(ch.cyberduck.core.googledrive.DriveDeleteFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) DefaultTouchFeature(ch.cyberduck.core.shared.DefaultTouchFeature) DefaultAttributesFinderFeature(ch.cyberduck.core.shared.DefaultAttributesFinderFeature) AttributedList(ch.cyberduck.core.AttributedList) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) SimplePathPredicate(ch.cyberduck.core.SimplePathPredicate) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DriveFileIdProvider(ch.cyberduck.core.googledrive.DriveFileIdProvider) AbstractDriveTest(ch.cyberduck.core.googledrive.AbstractDriveTest) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 3 with DriveListService

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());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) CryptoListService(ch.cyberduck.core.cryptomator.features.CryptoListService) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) DriveListService(ch.cyberduck.core.googledrive.DriveListService) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) DriveWriteFeature(ch.cyberduck.core.googledrive.DriveWriteFeature) DriveDeleteFeature(ch.cyberduck.core.googledrive.DriveDeleteFeature) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) DefaultTouchFeature(ch.cyberduck.core.shared.DefaultTouchFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) DefaultFindFeature(ch.cyberduck.core.shared.DefaultFindFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) SimplePathPredicate(ch.cyberduck.core.SimplePathPredicate) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DriveFileIdProvider(ch.cyberduck.core.googledrive.DriveFileIdProvider) AbstractDriveTest(ch.cyberduck.core.googledrive.AbstractDriveTest) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 4 with DriveListService

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());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) CryptoListService(ch.cyberduck.core.cryptomator.features.CryptoListService) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) DriveListService(ch.cyberduck.core.googledrive.DriveListService) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) DriveWriteFeature(ch.cyberduck.core.googledrive.DriveWriteFeature) DriveDeleteFeature(ch.cyberduck.core.googledrive.DriveDeleteFeature) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) DefaultTouchFeature(ch.cyberduck.core.shared.DefaultTouchFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) DefaultFindFeature(ch.cyberduck.core.shared.DefaultFindFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) SimplePathPredicate(ch.cyberduck.core.SimplePathPredicate) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DriveFileIdProvider(ch.cyberduck.core.googledrive.DriveFileIdProvider) AbstractDriveTest(ch.cyberduck.core.googledrive.AbstractDriveTest) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 5 with DriveListService

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();
}
Also used : Delete(ch.cyberduck.core.features.Delete) CryptoListService(ch.cyberduck.core.cryptomator.features.CryptoListService) DriveListService(ch.cyberduck.core.googledrive.DriveListService) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) CachingAttributesFinderFeature(ch.cyberduck.core.CachingAttributesFinderFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) Directory(ch.cyberduck.core.features.Directory) Path(ch.cyberduck.core.Path) PathCache(ch.cyberduck.core.PathCache) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) PathAttributes(ch.cyberduck.core.PathAttributes) DriveDeleteFeature(ch.cyberduck.core.googledrive.DriveDeleteFeature) DriveDirectoryFeature(ch.cyberduck.core.googledrive.DriveDirectoryFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) DefaultAttributesFinderFeature(ch.cyberduck.core.shared.DefaultAttributesFinderFeature) AttributedList(ch.cyberduck.core.AttributedList) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) SimplePathPredicate(ch.cyberduck.core.SimplePathPredicate) CryptoFileIdProvider(ch.cyberduck.core.cryptomator.features.CryptoFileIdProvider) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DriveFileIdProvider(ch.cyberduck.core.googledrive.DriveFileIdProvider) AbstractDriveTest(ch.cyberduck.core.googledrive.AbstractDriveTest) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)6 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)6 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)6 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)6 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)6 Path (ch.cyberduck.core.Path)6 SimplePathPredicate (ch.cyberduck.core.SimplePathPredicate)6 CryptoListService (ch.cyberduck.core.cryptomator.features.CryptoListService)6 Delete (ch.cyberduck.core.features.Delete)6 AbstractDriveTest (ch.cyberduck.core.googledrive.AbstractDriveTest)6 DriveDeleteFeature (ch.cyberduck.core.googledrive.DriveDeleteFeature)6 DriveFileIdProvider (ch.cyberduck.core.googledrive.DriveFileIdProvider)6 DriveListService (ch.cyberduck.core.googledrive.DriveListService)6 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)6 DefaultVaultRegistry (ch.cyberduck.core.vault.DefaultVaultRegistry)6 VaultCredentials (ch.cyberduck.core.vault.VaultCredentials)6 IntegrationTest (ch.cyberduck.test.IntegrationTest)6 Test (org.junit.Test)6 DriveWriteFeature (ch.cyberduck.core.googledrive.DriveWriteFeature)5 CryptoFindFeature (ch.cyberduck.core.cryptomator.features.CryptoFindFeature)4