@Test // see SSHD-554
  public void testSetSocketOptions() throws Exception {
    try (SshServer sshd = setupTestServer()) {
      PropertyResolverUtils.updateProperty(sshd, FactoryManager.SOCKET_KEEPALIVE, true);
      PropertyResolverUtils.updateProperty(sshd, FactoryManager.SOCKET_LINGER, 5);
      PropertyResolverUtils.updateProperty(sshd, FactoryManager.SOCKET_RCVBUF, 1024);
      PropertyResolverUtils.updateProperty(sshd, FactoryManager.SOCKET_REUSEADDR, true);
      PropertyResolverUtils.updateProperty(sshd, FactoryManager.SOCKET_SNDBUF, 1024);
      PropertyResolverUtils.updateProperty(sshd, FactoryManager.TCP_NODELAY, true);

      sshd.start();

      int port = sshd.getPort();
      long startTime = System.nanoTime();
      try (Socket s = new Socket(TEST_LOCALHOST, port)) {
        long endTime = System.nanoTime();
        long duration = endTime - startTime;
        assertTrue(
            "Connect duration is too high: " + duration, duration <= TimeUnit.SECONDS.toNanos(15L));
      } finally {
        sshd.stop();
      }
    }
  }
Exemple #2
0
  @Test
  public void testBuiltinCipherSession() throws Exception {
    Assume.assumeTrue(
        "No internal support for " + builtInCipher.getName(),
        builtInCipher.isSupported() && checkCipher(jschCipher.getName()));

    try (SshServer sshd = SshServer.setUpDefaultServer()) {
      sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
      sshd.setCipherFactories(
          Arrays.<NamedFactory<org.apache.sshd.common.cipher.Cipher>>asList(builtInCipher));
      sshd.setShellFactory(new EchoShellFactory());
      sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
      sshd.start();

      try {
        runJschTest(sshd.getPort());
      } finally {
        sshd.stop(true);
      }
    }
  }
  @Test
  public void testGitPgm() throws Exception {
    Path targetParent = detectTargetFolder().getParent();
    Path serverDir = getTempTargetRelativeFile(getClass().getSimpleName());

    //
    // TODO: the GitpgmCommandFactory is kept in the test tree
    // TODO: because it's quite limited for now
    //

    try (SshServer sshd = setupTestServer()) {
      sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory()));
      sshd.setCommandFactory(
          new GitPgmCommandFactory(Utils.resolveRelativeRemotePath(targetParent, serverDir)));
      sshd.start();

      int port = sshd.getPort();
      try {
        Utils.deleteRecursive(serverDir);

        try (SshClient client = setupTestClient()) {
          client.start();

          try (ClientSession session =
              client
                  .connect(getCurrentTestName(), SshdSocketAddress.LOCALHOST_IP, port)
                  .verify(7L, TimeUnit.SECONDS)
                  .getSession()) {
            session.addPasswordIdentity(getCurrentTestName());
            session.auth().verify(5L, TimeUnit.SECONDS);

            Path repo = serverDir.resolve(getCurrentTestName());
            Git.init().setDirectory(repo.toFile()).call();
            Git git = Git.open(repo.toFile());
            git.commit()
                .setMessage("First Commit")
                .setCommitter(getCurrentTestName(), "*****@*****.**")
                .call();

            Path readmeFile = Files.createFile(repo.resolve("readme.txt"));
            String commandPrefix = "git --git-dir " + repo.getFileName();
            execute(session, commandPrefix + " add " + readmeFile.getFileName());
            execute(session, commandPrefix + " commit -m \"readme\"");
          } finally {
            client.stop();
          }
        }
      } finally {
        sshd.stop();
      }
    }
  }