use of ch.cyberduck.core.vault.DefaultVaultRegistry in project cyberduck by iterate-ch.
the class B2DirectoryFeatureTest method testMakeDirectoryLongFilenameEncrypted.
@Test
public void testMakeDirectoryLongFilenameEncrypted() throws Exception {
assumeTrue(vaultVersion == CryptoVault.VAULT_VERSION_DEPRECATED);
final Path home = new Path("/test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
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 B2VersionIdProvider fileid = new B2VersionIdProvider(session);
final Path test = cryptomator.getFeature(session, Directory.class, new B2DirectoryFeature(session, fileid)).mkdir(new Path(vault, new AlphanumericRandomStringService(130).random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test));
cryptomator.getFeature(session, Delete.class, new B2DeleteFeature(session, fileid)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
session.close();
}
use of ch.cyberduck.core.vault.DefaultVaultRegistry in project cyberduck by iterate-ch.
the class SessionBackgroundActionTest method testGetExceptionConnectionCanceledException.
@Test
public void testGetExceptionConnectionCanceledException() {
SessionBackgroundAction<Void> a = new SessionBackgroundAction<Void>(new StatelessSessionPool(new TestLoginConnectionService(), new NullSession(new Host(new TestProtocol(), "t")), new DisabledTranscriptListener(), new DefaultVaultRegistry(new DisabledPasswordCallback())), new DisabledAlertCallback(), new DisabledProgressListener()) {
@Override
public Void run(final Session<?> session) throws BackgroundException {
throw new ConnectionCanceledException();
}
};
try {
a.call();
fail();
} catch (BackgroundException e) {
// Ignore
}
assertFalse(a.hasFailed());
}
use of ch.cyberduck.core.vault.DefaultVaultRegistry in project cyberduck by iterate-ch.
the class TransferBackgroundActionTest method testResumeOnRetryWithException.
@Test
public void testResumeOnRetryWithException() {
final AtomicBoolean alert = new AtomicBoolean();
final AbstractController controller = new AbstractController() {
@Override
public void invoke(final MainAction runnable, final boolean wait) {
runnable.run();
}
};
final Host host = new Host(new TestProtocol(), "test.cyberduck.ch");
final TransferOptions options = new TransferOptions();
final TransferBackgroundAction action = new TransferBackgroundAction(controller, new DefaultSessionPool(new TestLoginConnectionService(), new DisabledX509TrustManager(), new DefaultX509KeyManager(), new DefaultVaultRegistry(new DisabledPasswordCallback()), new DisabledTranscriptListener(), host) {
@Override
public Session<?> borrow(final BackgroundActionState callback) throws BackgroundException {
throw new ConnectionRefusedException("d", new SocketException());
}
}, SessionPool.DISCONNECTED, new TransferAdapter(), new DownloadTransfer(host, Collections.singletonList(new TransferItem(new Path("/home/test", EnumSet.of(Path.Type.file)), new NullLocal("/t")))), options) {
@Override
public boolean alert(final BackgroundException failure) {
final boolean alerted = alert.get();
alert.set(true);
return !alerted;
}
};
assertFalse(alert.get());
// Connect, prepare and run
new BackgroundCallable<Boolean>(action, controller).call();
assertTrue(alert.get());
assertTrue(action.hasFailed());
// assertTrue(options.resumeRequested);
}
use of ch.cyberduck.core.vault.DefaultVaultRegistry in project cyberduck by iterate-ch.
the class TransferBackgroundActionTest method testCopyBetweenHosts.
@Test
public void testCopyBetweenHosts() throws Exception {
final Session session = new NullTransferSession(new Host(new TestProtocol(), "test.cyberduck.ch"));
final Session destination = new NullTransferSession(new Host(new TestProtocol(), "test.cyberduck.ch"));
final Path directory = new Path("/home/jenkins/transfer", EnumSet.of(Path.Type.directory));
final Path test = new Path(directory, "test", EnumSet.of(Path.Type.file));
test.attributes().setSize(0L);
final Path copy = new Path(new Path("/transfer", EnumSet.of(Path.Type.directory)), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
final Transfer t = new CopyTransfer(session.getHost(), destination.getHost(), Collections.singletonMap(test, copy)) {
@Override
public TransferAction action(final Session<?> source, final Session<?> destination, final boolean resumeRequested, final boolean reloadRequested, final TransferPrompt prompt, final ListProgressListener listener) {
return TransferAction.overwrite;
}
};
final AbstractController controller = new AbstractController() {
@Override
public void invoke(final MainAction runnable, final boolean wait) {
runnable.run();
}
};
final AtomicBoolean start = new AtomicBoolean();
final AtomicBoolean stop = new AtomicBoolean();
final TransferBackgroundAction action = new TransferBackgroundAction(controller, new StatelessSessionPool(new TestLoginConnectionService(), session, new DisabledTranscriptListener(), new DefaultVaultRegistry(new DisabledPasswordCallback())), new StatelessSessionPool(new TestLoginConnectionService(), destination, new DisabledTranscriptListener(), new DefaultVaultRegistry(new DisabledPasswordCallback())), new TransferListener() {
@Override
public void transferDidStart(final Transfer transfer) {
assertEquals(t, transfer);
start.set(true);
}
@Override
public void transferDidStop(final Transfer transfer) {
assertEquals(t, transfer);
stop.set(true);
}
@Override
public void transferDidProgress(final Transfer transfer, final TransferProgress status) {
//
}
}, t, new TransferOptions());
action.prepare();
action.call();
action.finish();
assertFalse(action.hasFailed());
assertTrue(start.get());
assertTrue(stop.get());
assertTrue(t.isComplete());
assertNotNull(t.getTimestamp());
}
use of ch.cyberduck.core.vault.DefaultVaultRegistry in project cyberduck by iterate-ch.
the class CryptoDropboxSingleTransferWorkerTest method testUpload.
@Test
public void testUpload() 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 dir1 = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Local localDirectory1 = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
new DefaultLocalDirectoryFeature().mkdir(localDirectory1);
final byte[] content = RandomUtils.nextBytes(62768);
final Path file1 = new Path(dir1, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Local localFile1 = new Local(localDirectory1, file1.getName());
final OutputStream out1 = localFile1.getOutputStream(false);
IOUtils.write(content, out1);
out1.close();
final Path file2 = new Path(dir1, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Local localFile2 = new Local(localDirectory1, file2.getName());
final OutputStream out2 = localFile2.getOutputStream(false);
IOUtils.write(content, out2);
out2.close();
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 Transfer t = new UploadTransfer(new Host(new TestProtocol()), Collections.singletonList(new TransferItem(dir1, localDirectory1)), new NullFilter<>());
assertTrue(new SingleTransferWorker(session, session, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {
@Override
public TransferAction prompt(final TransferItem file) {
return TransferAction.overwrite;
}
}, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()) {
}.run(session));
assertTrue(new CryptoFindFeature(session, new DropboxFindFeature(session), cryptomator).find(dir1));
assertEquals(content.length, new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator).find(file1).getSize());
{
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new DropboxReadFeature(session), cryptomator).read(file1, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
}
assertEquals(content.length, new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator).find(file2).getSize());
{
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new DropboxReadFeature(session), cryptomator).read(file1, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
}
cryptomator.getFeature(session, Delete.class, new DropboxDeleteFeature(session)).delete(Arrays.asList(file1, file2, dir1, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
localFile1.delete();
localFile2.delete();
localDirectory1.delete();
}
Aggregations