use of ch.cyberduck.core.ftp.list.FTPListService in project cyberduck by iterate-ch.
the class FTPListServiceTest method testListCryptomator.
@Test
public void testListCryptomator() 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 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));
assertTrue(new CryptoListService(session, new FTPListService(session, null, null), cryptomator).list(vault, new DisabledListProgressListener()).isEmpty());
new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new FTPWriteFeature(session)), new FTPWriteFeature(session), cryptomator).touch(test, new TransferStatus());
assertEquals(test, new CryptoListService(session, new FTPListService(session, null, null), cryptomator).list(vault, new DisabledListProgressListener()).get(0));
cryptomator.getFeature(session, Delete.class, new FTPDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.ftp.list.FTPListService in project cyberduck by iterate-ch.
the class FTPUnixPermissionFeatureTest method testSetUnixPermission.
@Test(expected = InteroperabilityException.class)
public void testSetUnixPermission() throws Exception {
final FTPWorkdirService workdir = new FTPWorkdirService(session);
final Path home = workdir.find();
final Path test = new Path(workdir.find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
new FTPTouchFeature(session).touch(test, new TransferStatus());
new FTPUnixPermissionFeature(session).setUnixPermission(test, new Permission(666));
assertEquals("666", new FTPListService(session, null, TimeZone.getDefault()).list(home, new DisabledListProgressListener()).get(test).attributes().getPermission().getMode());
new FTPDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.ftp.list.FTPListService in project cyberduck by iterate-ch.
the class FTPWriteFeatureTest method testWrite.
@Test
public void testWrite() throws Exception {
final TransferStatus status = new TransferStatus();
final int length = 1048576;
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 FTPWriteFeature(session), cryptomator);
final FileHeader header = cryptomator.getFileHeaderCryptor().create();
status.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(content.length)));
status.setChecksum(writer.checksum(test, status).compute(new ByteArrayInputStream(content), status));
status.setLength(content.length);
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 DefaultFindFeature(session), cryptomator).find(test));
final PathAttributes attr = new CryptoAttributesFeature(session, new FTPAttributesFinderFeature(session), cryptomator).find(test);
assertEquals(content.length, new CryptoListService(session, new FTPListService(session, null, TimeZone.getDefault()), cryptomator).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize());
assertEquals(content.length, new CryptoWriteFeature<>(session, new FTPWriteFeature(session), cryptomator).append(test, status.withRemote(attr)).size, 0L);
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new FTPReadFeature(session), cryptomator).read(test, new TransferStatus(), new DisabledConnectionCallback());
new StreamCopier(status, status).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
cryptomator.getFeature(session, Delete.class, new FTPDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.ftp.list.FTPListService in project cyberduck by iterate-ch.
the class FTPMFMTTimestampFeatureTest method testSetTimestamp.
@Test
public void testSetTimestamp() throws Exception {
final Path home = new FTPWorkdirService(session).find();
final long modified = System.currentTimeMillis();
final Path test = new Path(new FTPWorkdirService(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
new FTPTouchFeature(session).touch(test, new TransferStatus());
new FTPMFMTTimestampFeature(session).setTimestamp(test, modified);
assertEquals(modified / 1000 * 1000, new FTPListService(session, null, TimeZone.getDefault()).list(home, new DisabledListProgressListener()).get(test).attributes().getModificationDate());
new FTPDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.ftp.list.FTPListService in project cyberduck by iterate-ch.
the class FTPWriteFeatureTest method testReadWrite.
@Test
public void testReadWrite() throws Exception {
final TransferStatus status = new TransferStatus();
final byte[] content = "test".getBytes(StandardCharsets.UTF_8);
status.setLength(content.length);
final Path test = new Path(new FTPWorkdirService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final OutputStream out = new FTPWriteFeature(session).write(test, status, new DisabledConnectionCallback());
assertNotNull(out);
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
out.close();
assertTrue(session.getFeature(Find.class).find(test));
final PathAttributes attributes = new FTPListService(session, null, TimeZone.getDefault()).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes();
assertEquals(content.length, attributes.getSize());
assertEquals(content.length, new FTPWriteFeature(session).append(test, status.withRemote(attributes)).size, 0L);
{
final InputStream in = new FTPReadFeature(session).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
new StreamCopier(status, status).transfer(in, buffer);
in.close();
assertArrayEquals(content, buffer.toByteArray());
}
{
final byte[] buffer = new byte[content.length - 1];
final InputStream in = new FTPReadFeature(session).read(test, new TransferStatus().withLength(content.length).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 FTPDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Aggregations