use of ch.cyberduck.core.dav.DAVWriteFeature in project cyberduck by iterate-ch.
the class MicrosoftIISDAVLockFeatureTest method testLock.
@Test
public void testLock() throws Exception {
final Host host = new Host(new DAVProtocol(), "winbuild.iterate.ch", new Credentials(System.getProperties().getProperty("webdav.iis.user"), System.getProperties().getProperty("webdav.iis.password")));
host.setDefaultPath("/WebDAV");
final DAVSession session = new DAVSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager());
session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback());
final TransferStatus status = new TransferStatus();
final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
final byte[] content = "test".getBytes(StandardCharsets.UTF_8);
final OutputStream out = local.getOutputStream(false);
IOUtils.write(content, out);
out.close();
status.setLength(content.length);
final Path test = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final HttpUploadFeature upload = new DAVUploadFeature(session);
upload.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledConnectionCallback());
final String lock = new DAVLockFeature(session).lock(test);
assertTrue(new MicrosoftIISDAVFindFeature(session).find(test));
final PathAttributes attributes = new MicrosoftIISDAVListService(session, new MicrosoftIISDAVAttributesFinderFeature(session)).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes();
assertEquals(content.length, attributes.getSize(), 0L);
assertEquals(content.length, new DAVWriteFeature(session).append(test, status.withRemote(attributes)).size, 0L);
{
final byte[] buffer = new byte[content.length];
IOUtils.readFully(new MicrosoftIISDAVReadFeature(session).read(test, new TransferStatus(), new DisabledConnectionCallback()), buffer);
assertArrayEquals(content, buffer);
}
{
final byte[] buffer = new byte[content.length - 1];
final InputStream in = new MicrosoftIISDAVReadFeature(session).read(test, new TransferStatus().withLength(content.length - 1L).append(true).withOffset(1L), new DisabledConnectionCallback());
IOUtils.readFully(in, buffer);
in.close();
final byte[] reference = new byte[content.length - 1];
System.arraycopy(content, 1, reference, 0, content.length - 1);
assertArrayEquals(reference, buffer);
}
new DAVLockFeature(session).unlock(test, lock);
new DAVDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.dav.DAVWriteFeature in project cyberduck by iterate-ch.
the class DAVMoveFeatureTest method testMove.
@Test
public void testMove() throws Exception {
final Path home = new DefaultHomeFinderService(session).find();
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path folder = new Path(vault, 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));
cryptomator.getFeature(session, Directory.class, new DAVDirectoryFeature(session)).mkdir(folder, new TransferStatus());
final Path template = new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Path file = new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new DAVWriteFeature(session)), new DAVWriteFeature(session), cryptomator).touch(template, new TransferStatus()).withAttributes(new CryptoAttributesFeature(session, new DAVAttributesFinderFeature(session), cryptomator).find(template));
assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(file));
final Move move = cryptomator.getFeature(session, Move.class, new DAVMoveFeature(session));
// rename file
final Path fileRenamed = move.move(file, new Path(folder, "f1", EnumSet.of(Path.Type.file)), new TransferStatus(), new Delete.DisabledCallback(), new DisabledConnectionCallback());
assertFalse(new CryptoFindFeature(session, new DAVFindFeature(session), cryptomator).find(file));
assertTrue(new CryptoFindFeature(session, new DAVFindFeature(session), cryptomator).find(fileRenamed));
assertEquals(fileRenamed.attributes(), new CryptoAttributesFeature(session, new DAVAttributesFinderFeature(session), cryptomator).find(fileRenamed));
// rename folder
final Path folderRenamed = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
move.move(folder, folderRenamed, new TransferStatus(), new Delete.DisabledCallback(), new DisabledConnectionCallback());
assertFalse(new CryptoFindFeature(session, new DAVFindFeature(session), cryptomator).find(folder));
assertTrue(new CryptoFindFeature(session, new DAVFindFeature(session), cryptomator).find(folderRenamed));
final Path fileRenamedInRenamedFolder = new Path(folderRenamed, "f1", EnumSet.of(Path.Type.file));
assertTrue(new CryptoFindFeature(session, new DAVFindFeature(session), cryptomator).find(fileRenamedInRenamedFolder));
cryptomator.getFeature(session, Delete.class, new DAVDeleteFeature(session)).delete(Arrays.asList(fileRenamedInRenamedFolder, folderRenamed, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.dav.DAVWriteFeature in project cyberduck by iterate-ch.
the class DAVReadFeatureTest method testReadRange.
@Test
public void testReadRange() throws Exception {
final TransferStatus status = new TransferStatus();
final int length = 140000;
final byte[] content = RandomUtils.nextBytes(length);
status.setLength(content.length);
final Path home = new DefaultHomeFinderService(session).find();
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 CryptoWriteFeature<Void> writer = new CryptoWriteFeature<>(session, new DAVWriteFeature(session), 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 DAVFindFeature(session), cryptomator).find(test));
assertEquals(content.length, new CryptoListService(session, new DAVListService(session), cryptomator).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize());
assertEquals(content.length, writer.append(test, status.withRemote(new CryptoAttributesFeature(session, new DAVAttributesFinderFeature(session), cryptomator).find(test))).size, 0L);
{
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(40000);
final TransferStatus read = new TransferStatus();
// offset within chunk
read.setOffset(23);
read.setAppend(true);
// ensure to read at least two chunks
read.withLength(40000);
final InputStream in = new CryptoReadFeature(session, new DAVReadFeature(session), cryptomator).read(test, read, new DisabledConnectionCallback());
new StreamCopier(read, read).withLimit(40000L).transfer(in, buffer);
final byte[] reference = new byte[40000];
System.arraycopy(content, 23, reference, 0, reference.length);
assertArrayEquals(reference, buffer.toByteArray());
}
{
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(40000);
final TransferStatus read = new TransferStatus();
// offset at the beginning of a new chunk
read.setOffset(65536);
read.setAppend(true);
// ensure to read at least two chunks
read.withLength(40000);
final InputStream in = new CryptoReadFeature(session, new DAVReadFeature(session), cryptomator).read(test, read, new DisabledConnectionCallback());
new StreamCopier(read, read).withLimit(40000L).transfer(in, buffer);
final byte[] reference = new byte[40000];
System.arraycopy(content, 65536, reference, 0, reference.length);
assertArrayEquals(reference, buffer.toByteArray());
}
{
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(40000);
final TransferStatus read = new TransferStatus();
// offset at the beginning+1 of a new chunk
read.setOffset(65537);
read.setAppend(true);
// ensure to read at least two chunks
read.withLength(40000);
final InputStream in = new CryptoReadFeature(session, new DAVReadFeature(session), cryptomator).read(test, read, new DisabledConnectionCallback());
new StreamCopier(read, read).withLimit(40000L).transfer(in, buffer);
final byte[] reference = new byte[40000];
System.arraycopy(content, 65537, reference, 0, reference.length);
assertArrayEquals(reference, buffer.toByteArray());
}
cryptomator.getFeature(session, Delete.class, new DAVDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.dav.DAVWriteFeature in project cyberduck by iterate-ch.
the class DAVTouchFeatureTest method testTouchDeleteTouchLongFilename.
@Test
public void testTouchDeleteTouchLongFilename() throws Exception {
assumeTrue(vaultVersion == CryptoVault.VAULT_VERSION_DEPRECATED);
final Path home = new DefaultHomeFinderService(session).find();
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path test = new Path(vault, new AlphanumericRandomStringService(130).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));
new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new DAVWriteFeature(session)), new DAVWriteFeature(session), cryptomator).touch(test, new TransferStatus());
assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test));
cryptomator.getFeature(session, Delete.class, new DAVDeleteFeature(session)).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new DAVWriteFeature(session)), new DAVWriteFeature(session), cryptomator).touch(test, new TransferStatus());
assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test));
cryptomator.getFeature(session, Delete.class, new DAVDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.dav.DAVWriteFeature in project cyberduck by iterate-ch.
the class DAVTouchFeatureTest method testTouchLongFilenameEncrypted.
@Test
public void testTouchLongFilenameEncrypted() throws Exception {
assumeTrue(vaultVersion == CryptoVault.VAULT_VERSION_DEPRECATED);
final Path home = new DefaultHomeFinderService(session).find();
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 Path template = new Path(vault, new AlphanumericRandomStringService(130).random(), EnumSet.of(Path.Type.file));
final Path test = new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new DAVWriteFeature(session)), new DAVWriteFeature(session), cryptomator).touch(template, new TransferStatus()).withAttributes(new CryptoAttributesFeature(session, new DAVAttributesFinderFeature(session), cryptomator).find(template));
assertTrue(new CryptoFindFeature(session, new DAVFindFeature(session), cryptomator).find(test));
assertEquals(test.attributes(), new CryptoAttributesFeature(session, new DAVAttributesFinderFeature(session), cryptomator).find(test));
cryptomator.getFeature(session, Delete.class, new DAVDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Aggregations