Search in sources :

Example 6 with DefaultSessionFactory

use of com.helger.jsch.session.DefaultSessionFactory in project ph-web by phax.

the class SshProxyTest method initializeClass.

@BeforeClass
public static void initializeClass() {
    try (final InputStream inputStream = ClassLoader.getSystemResourceAsStream("configuration.properties")) {
        Assume.assumeNotNull(inputStream);
        properties = new NonBlockingProperties();
        properties.load(inputStream);
    } catch (final IOException e) {
        LOGGER.warn("cant find properties file (tests will be skipped)", e);
        properties = null;
        return;
    }
    final String knownHosts = properties.getProperty("ssh.knownHosts");
    final String privateKey = properties.getProperty("ssh.privateKey");
    username = properties.getProperty("scp.out.test.username");
    hostname = "localhost";
    port = Integer.parseInt(properties.getProperty("scp.out.test.port"));
    sessionFactory = new DefaultSessionFactory(username, hostname, port);
    try {
        sessionFactory.setKnownHosts(knownHosts);
        sessionFactory.setIdentityFromPrivateKey(privateKey);
    } catch (final JSchException e) {
        Assume.assumeNoException(e);
    }
}
Also used : NonBlockingProperties(com.helger.commons.lang.NonBlockingProperties) JSchException(com.jcraft.jsch.JSchException) DefaultSessionFactory(com.helger.jsch.session.DefaultSessionFactory) InputStream(java.io.InputStream) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 7 with DefaultSessionFactory

use of com.helger.jsch.session.DefaultSessionFactory in project ph-web by phax.

the class TunnelConnectionManagerTest method testGetTunnel.

@Test
public void testGetTunnel() {
    try (final TunnelConnectionManager manager = new TunnelConnectionManager(new DefaultSessionFactory())) {
        assertNotNull(manager);
        final List<String> pathAndSpecList = new ArrayList<>();
        pathAndSpecList.add("joe@crabshack|crab:10:imitationcrab:20");
        pathAndSpecList.add("bob@redlobster|lobster:15:tail:20");
        try {
            manager.setTunnelConnections(pathAndSpecList);
        } catch (final JSchException e) {
            LOGGER.info("unable to set pathAndSpecList: ", e);
            fail("unable to setPathAndSpecList: " + e.getMessage());
        }
        Tunnel tunnel = manager.getTunnel("imitationcrab", 20);
        assertEquals("crab", tunnel.getLocalAlias());
        assertEquals(10, tunnel.getLocalPort());
        tunnel = manager.getTunnel("tail", 20);
        assertEquals("lobster", tunnel.getLocalAlias());
        assertEquals(15, tunnel.getLocalPort());
    } catch (final JSchException e) {
        LOGGER.info("unable to create TunnelConnectionManager: ", e);
        fail("unable to create TunnelConnectionManager: " + e.getMessage());
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) DefaultSessionFactory(com.helger.jsch.session.DefaultSessionFactory) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

DefaultSessionFactory (com.helger.jsch.session.DefaultSessionFactory)7 JSchException (com.jcraft.jsch.JSchException)5 NonBlockingProperties (com.helger.commons.lang.NonBlockingProperties)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 BeforeClass (org.junit.BeforeClass)4 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1