Search in sources :

Example 1 with DriveFindFeature

use of ch.cyberduck.core.googledrive.DriveFindFeature 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 DriveFindFeature

use of ch.cyberduck.core.googledrive.DriveFindFeature in project cyberduck by iterate-ch.

the class DriveDirectoryFeatureTest method testMakeDirectoryEncrypted.

@Test
public void testMakeDirectoryEncrypted() throws Exception {
    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 fileid = new DriveFileIdProvider(session);
    final Path test = cryptomator.getFeature(session, Directory.class, new DriveDirectoryFeature(session, fileid)).mkdir(new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
    final String versionId = test.attributes().getFileId();
    assertNotNull(versionId);
    // Assert both filename and file id matches
    assertTrue(new CryptoFindFeature(session, new DriveFindFeature(session, fileid), cryptomator).find(test));
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test));
    final PathAttributes attributes = new CryptoAttributesFeature(session, new DriveAttributesFinderFeature(session, fileid), cryptomator).find(test);
    assertEquals(versionId, attributes.getFileId());
    assertEquals(attributes, new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator).find(test));
    cryptomator.getFeature(session, Delete.class, new DriveDeleteFeature(session, fileid)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) PathAttributes(ch.cyberduck.core.PathAttributes) DriveDeleteFeature(ch.cyberduck.core.googledrive.DriveDeleteFeature) DriveDirectoryFeature(ch.cyberduck.core.googledrive.DriveDirectoryFeature) DriveAttributesFinderFeature(ch.cyberduck.core.googledrive.DriveAttributesFinderFeature) 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) 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) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DriveFileIdProvider(ch.cyberduck.core.googledrive.DriveFileIdProvider) Directory(ch.cyberduck.core.features.Directory) AbstractDriveTest(ch.cyberduck.core.googledrive.AbstractDriveTest) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)2 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)2 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)2 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)2 Path (ch.cyberduck.core.Path)2 PathAttributes (ch.cyberduck.core.PathAttributes)2 CryptoAttributesFeature (ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature)2 CryptoFindFeature (ch.cyberduck.core.cryptomator.features.CryptoFindFeature)2 Delete (ch.cyberduck.core.features.Delete)2 AbstractDriveTest (ch.cyberduck.core.googledrive.AbstractDriveTest)2 DriveAttributesFinderFeature (ch.cyberduck.core.googledrive.DriveAttributesFinderFeature)2 DriveDeleteFeature (ch.cyberduck.core.googledrive.DriveDeleteFeature)2 DriveFileIdProvider (ch.cyberduck.core.googledrive.DriveFileIdProvider)2 DriveFindFeature (ch.cyberduck.core.googledrive.DriveFindFeature)2 DefaultAttributesFinderFeature (ch.cyberduck.core.shared.DefaultAttributesFinderFeature)2 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)2 DefaultVaultRegistry (ch.cyberduck.core.vault.DefaultVaultRegistry)2 VaultCredentials (ch.cyberduck.core.vault.VaultCredentials)2 IntegrationTest (ch.cyberduck.test.IntegrationTest)2 Test (org.junit.Test)2