Search in sources :

Example 1 with Host

use of ch.cyberduck.core.Host in project cyberduck by iterate-ch.

the class CryptoB2SingleTransferWorkerTest method testUpload.

@Test
public void testUpload() throws Exception {
    final Path home = new Path("/test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    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));
    final B2VersionIdProvider fileid = new B2VersionIdProvider(session);
    assertTrue(new CryptoFindFeature(session, new B2FindFeature(session, fileid), cryptomator).find(dir1));
    assertEquals(content.length, new CryptoAttributesFeature(session, new B2AttributesFinderFeature(session, fileid), cryptomator).find(file1).getSize());
    {
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
        final InputStream in = new CryptoReadFeature(session, new B2ReadFeature(session, fileid), 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 B2AttributesFinderFeature(session, fileid), cryptomator).find(file2).getSize());
    {
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
        final InputStream in = new CryptoReadFeature(session, new B2ReadFeature(session, fileid), 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 B2DeleteFeature(session, fileid)).delete(Arrays.asList(file1, file2, dir1, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    localFile1.delete();
    localFile2.delete();
    localDirectory1.delete();
}
Also used : Delete(ch.cyberduck.core.features.Delete) TestProtocol(ch.cyberduck.core.TestProtocol) B2ReadFeature(ch.cyberduck.core.b2.B2ReadFeature) TransferAction(ch.cyberduck.core.transfer.TransferAction) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) SingleTransferWorker(ch.cyberduck.core.worker.SingleTransferWorker) B2VersionIdProvider(ch.cyberduck.core.b2.B2VersionIdProvider) B2AttributesFinderFeature(ch.cyberduck.core.b2.B2AttributesFinderFeature) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) B2DeleteFeature(ch.cyberduck.core.b2.B2DeleteFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) DefaultLocalDirectoryFeature(ch.cyberduck.core.local.DefaultLocalDirectoryFeature) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) CryptoReadFeature(ch.cyberduck.core.cryptomator.features.CryptoReadFeature) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) InputStream(java.io.InputStream) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) B2FindFeature(ch.cyberduck.core.b2.B2FindFeature) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) TransferItem(ch.cyberduck.core.transfer.TransferItem) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractB2Test(ch.cyberduck.core.b2.AbstractB2Test) Test(org.junit.Test)

Example 2 with Host

use of ch.cyberduck.core.Host in project cyberduck by iterate-ch.

the class RendezvousCollectionTest method testAdd.

@Test
public void testAdd() {
    final AbstractRendezvous bonjour = new AbstractRendezvous(new ProtocolFactory(Collections.singleton(new TestProtocol(Scheme.sftp)))) {
    };
    final RendezvousCollection c = new RendezvousCollection(bonjour);
    assertFalse(c.allowsAdd());
    assertFalse(c.allowsDelete());
    assertFalse(c.allowsEdit());
    bonjour.init();
    final Host h = new Host(new TestProtocol(Scheme.sftp), "h");
    h.setUuid("a");
    bonjour.add("h_sftp", h);
    assertEquals(h, c.lookup("a"));
    assertEquals(1, c.size());
    assertEquals(h, c.get(0));
    assertNotNull(c.get(0).getUuid());
    bonjour.remove("h_sftp");
    assertEquals(0, c.size());
    assertTrue(c.isEmpty());
}
Also used : ProtocolFactory(ch.cyberduck.core.ProtocolFactory) TestProtocol(ch.cyberduck.core.TestProtocol) Host(ch.cyberduck.core.Host) Test(org.junit.Test)

Example 3 with Host

use of ch.cyberduck.core.Host in project cyberduck by iterate-ch.

the class AbstractRendezvous method add.

protected void add(final String fullname, final String hostname, final int port, final String user, final String password, final String path) {
    final Protocol protocol = this.getProtocol(fullname);
    if (null == protocol) {
        log.warn(String.format("Unknown service type for %s", fullname));
        return;
    }
    final Host host = new Host(protocol, hostname, port);
    host.getCredentials().setUsername(user);
    host.getCredentials().setPassword(password);
    if (StringUtils.isNotBlank(path)) {
        host.setDefaultPath(PathNormalizer.normalize(path));
    }
    host.setComment(UserDateFormatterFactory.get().getLongFormat(new Date().getTime()));
    this.add(fullname, host);
}
Also used : Host(ch.cyberduck.core.Host) Protocol(ch.cyberduck.core.Protocol) Date(java.util.Date)

Example 4 with Host

use of ch.cyberduck.core.Host in project cyberduck by iterate-ch.

the class AbstractBrickTest method setup.

@Before
public void setup() throws Exception {
    final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Collections.singleton(new BrickProtocol())));
    final Profile profile = new ProfilePlistReader(factory).read(this.getClass().getResourceAsStream("/Brick.cyberduckprofile"));
    final Host host = new Host(profile, "mountainduck.files.com", new Credentials(System.getProperties().getProperty("brick.user"), System.getProperties().getProperty("brick.password")));
    session = new BrickSession(host, new DefaultX509TrustManager(), new DefaultX509KeyManager());
    final LoginConnectionService login = new LoginConnectionService(new DisabledLoginCallback() {

        @Override
        public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) {
            fail(reason);
            return null;
        }
    }, new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener());
    login.check(session, new DisabledCancelCallback());
}
Also used : DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) LoginConnectionService(ch.cyberduck.core.LoginConnectionService) Host(ch.cyberduck.core.Host) ProfilePlistReader(ch.cyberduck.core.serializer.impl.dd.ProfilePlistReader) Profile(ch.cyberduck.core.Profile) ProtocolFactory(ch.cyberduck.core.ProtocolFactory) LoginOptions(ch.cyberduck.core.LoginOptions) DisabledCancelCallback(ch.cyberduck.core.DisabledCancelCallback) DisabledHostKeyCallback(ch.cyberduck.core.DisabledHostKeyCallback) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) Credentials(ch.cyberduck.core.Credentials) DefaultX509TrustManager(ch.cyberduck.core.ssl.DefaultX509TrustManager) Before(org.junit.Before)

Example 5 with Host

use of ch.cyberduck.core.Host in project cyberduck by iterate-ch.

the class AbtractBoxTest method setup.

@Before
public void setup() throws Exception {
    final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Collections.singleton(new BoxProtocol())));
    final Profile profile = new ProfilePlistReader(factory).read(this.getClass().getResourceAsStream("/Box.cyberduckprofile"));
    final Host host = new Host(profile, profile.getDefaultHostname(), new Credentials("cyberduck"));
    session = new BoxSession(host, new DefaultX509TrustManager(), new DefaultX509KeyManager());
    final LoginConnectionService login = new LoginConnectionService(new DisabledLoginCallback() {

        @Override
        public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) {
            fail(reason);
            return null;
        }
    }, new DisabledHostKeyCallback(), new TestPasswordStore(), new DisabledProgressListener());
    login.check(session, new DisabledCancelCallback());
}
Also used : DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) LoginConnectionService(ch.cyberduck.core.LoginConnectionService) Host(ch.cyberduck.core.Host) ProfilePlistReader(ch.cyberduck.core.serializer.impl.dd.ProfilePlistReader) Profile(ch.cyberduck.core.Profile) ProtocolFactory(ch.cyberduck.core.ProtocolFactory) LoginOptions(ch.cyberduck.core.LoginOptions) DisabledCancelCallback(ch.cyberduck.core.DisabledCancelCallback) DisabledHostKeyCallback(ch.cyberduck.core.DisabledHostKeyCallback) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) Credentials(ch.cyberduck.core.Credentials) DefaultX509TrustManager(ch.cyberduck.core.ssl.DefaultX509TrustManager) Before(org.junit.Before)

Aggregations

Host (ch.cyberduck.core.Host)541 Test (org.junit.Test)472 Path (ch.cyberduck.core.Path)344 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)236 TestProtocol (ch.cyberduck.core.TestProtocol)230 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)216 Credentials (ch.cyberduck.core.Credentials)201 IntegrationTest (ch.cyberduck.test.IntegrationTest)195 DisabledCancelCallback (ch.cyberduck.core.DisabledCancelCallback)182 DisabledHostKeyCallback (ch.cyberduck.core.DisabledHostKeyCallback)178 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)136 DefaultX509KeyManager (ch.cyberduck.core.ssl.DefaultX509KeyManager)136 NullSession (ch.cyberduck.core.NullSession)131 Local (ch.cyberduck.core.Local)122 Delete (ch.cyberduck.core.features.Delete)119 DisabledX509TrustManager (ch.cyberduck.core.ssl.DisabledX509TrustManager)111 LoginOptions (ch.cyberduck.core.LoginOptions)86 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)83 NullLocal (ch.cyberduck.core.NullLocal)78 ProtocolFactory (ch.cyberduck.core.ProtocolFactory)68