Search in sources :

Example 1 with AzureListService

use of ch.cyberduck.core.azure.AzureListService in project cyberduck by iterate-ch.

the class AzureWriteFeatureTest method testWrite.

@Test
public void testWrite() throws Exception {
    final TransferStatus status = new TransferStatus();
    final byte[] content = RandomUtils.nextBytes(1048576);
    status.setLength(content.length);
    final Path home = new Path("cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
    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 CryptoWriteFeature<Void> writer = new CryptoWriteFeature<>(session, new AzureWriteFeature(session, null), cryptomator);
    final FileHeader header = cryptomator.getFileHeaderCryptor().create();
    status.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
    status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(content.length)));
    final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    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();
    final OperationContext context = new OperationContext();
    assertTrue(new CryptoFindFeature(session, new AzureFindFeature(session, context), cryptomator).find(test));
    final PathAttributes attributes = new CryptoListService(session, new AzureListService(session, context), cryptomator).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes();
    assertEquals(content.length, attributes.getSize());
    assertEquals(content.length, new CryptoWriteFeature<>(session, new AzureWriteFeature(session, context), cryptomator).append(test, status.withRemote(attributes)).size, 0L);
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    final InputStream in = new CryptoReadFeature(session, new AzureReadFeature(session, context), 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 AzureDeleteFeature(session, context)).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) CryptoWriteFeature(ch.cyberduck.core.cryptomator.features.CryptoWriteFeature) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) AzureFindFeature(ch.cyberduck.core.azure.AzureFindFeature) AzureWriteFeature(ch.cyberduck.core.azure.AzureWriteFeature) RotatingNonceGenerator(ch.cyberduck.core.cryptomator.random.RotatingNonceGenerator) AzureReadFeature(ch.cyberduck.core.azure.AzureReadFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) CryptoReadFeature(ch.cyberduck.core.cryptomator.features.CryptoReadFeature) FileHeader(org.cryptomator.cryptolib.api.FileHeader) Path(ch.cyberduck.core.Path) OperationContext(com.microsoft.azure.storage.OperationContext) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) AzureListService(ch.cyberduck.core.azure.AzureListService) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PathAttributes(ch.cyberduck.core.PathAttributes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) ByteArrayInputStream(java.io.ByteArrayInputStream) AzureDeleteFeature(ch.cyberduck.core.azure.AzureDeleteFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) AbstractAzureTest(ch.cyberduck.core.azure.AbstractAzureTest) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)1 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)1 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)1 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)1 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)1 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)1 Path (ch.cyberduck.core.Path)1 PathAttributes (ch.cyberduck.core.PathAttributes)1 AbstractAzureTest (ch.cyberduck.core.azure.AbstractAzureTest)1 AzureDeleteFeature (ch.cyberduck.core.azure.AzureDeleteFeature)1 AzureFindFeature (ch.cyberduck.core.azure.AzureFindFeature)1 AzureListService (ch.cyberduck.core.azure.AzureListService)1 AzureReadFeature (ch.cyberduck.core.azure.AzureReadFeature)1 AzureWriteFeature (ch.cyberduck.core.azure.AzureWriteFeature)1 CryptoFindFeature (ch.cyberduck.core.cryptomator.features.CryptoFindFeature)1 CryptoListService (ch.cyberduck.core.cryptomator.features.CryptoListService)1 CryptoReadFeature (ch.cyberduck.core.cryptomator.features.CryptoReadFeature)1 CryptoWriteFeature (ch.cyberduck.core.cryptomator.features.CryptoWriteFeature)1 RotatingNonceGenerator (ch.cyberduck.core.cryptomator.random.RotatingNonceGenerator)1 Delete (ch.cyberduck.core.features.Delete)1