예제 #1
0
 @Test(expected = AuthenticationException.class)
 public void testWrongPassword() throws Exception {
   _sshdialog.setKeyPair(null);
   _sshdialog.setPassword("bad");
   _sshdialog.connect();
   _sshdialog.authenticate();
 }
예제 #2
0
  @Test
  public void testLong() throws Throwable {
    final String LINE = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASDSSSSSSSSSSSSSSSSSSSSSSSDDDDDD";
    final int NUM = 10000;
    final int FACTOR = 5;

    StringBuilder longText = new StringBuilder();
    for (int i = 0; i < NUM / FACTOR; i++) {
      longText.append(LINE).append("\n");
    }

    List<String> expect = new LinkedList<String>();
    expect.add("start");
    for (int i = 0; i < NUM; i++) {
      expect.add(LINE);
    }

    List<String> send = new LinkedList<String>();
    for (int i = 0; i < NUM; i++) {
      if (i % (NUM / FACTOR) == 0) {
        send.add(longText.toString());
      } else {
        send.add(null);
      }
    }

    Sink sink = new Sink(expect.toArray(new String[0]), send.toArray(new String[0]));
    _sshdialog.connect();
    _sshdialog.authenticate();
    _sshdialog.executeCommand(sink, "echo start && sleep 4 && cat", null);
    sink.exception();
  }
예제 #3
0
 @Test(expected = TimeLimitExceededException.class)
 public void testTimeout() throws Throwable {
   Sink sink = new Sink(new String[] {"start"}, new String[] {});
   _sshdialog.setSoftTimeout(1 * 1000);
   _sshdialog.connect();
   _sshdialog.authenticate();
   _sshdialog.executeCommand(sink, "cat", null);
   sink.exception();
 }
예제 #4
0
 @Before
 public void setUp() {
   _sshdialog = new SSHDialog();
   _sshdialog.setHost(s_host, s_port);
   _sshdialog.setPassword(s_password);
   _sshdialog.setKeyPair(s_keyPair);
   _sshdialog.setSoftTimeout(10 * 1000);
   _sshdialog.setHardTimeout(30 * 1000);
 }
예제 #5
0
 @Test(expected = RuntimeException.class)
 public void testStderr() throws Throwable {
   try (final InputStream start = new ByteArrayInputStream("start\n".getBytes("UTF-8"))) {
     Sink sink =
         new Sink(new String[] {"start", "text1", "text2"}, new String[] {"text1", "text2"});
     _sshdialog.connect();
     _sshdialog.authenticate();
     _sshdialog.executeCommand(sink, "echo message >&2 && cat", new InputStream[] {start});
     sink.exception();
   }
 }
예제 #6
0
 @Test
 public void testSimple() throws Throwable {
   try (final InputStream start = new ByteArrayInputStream("start\n".getBytes("UTF-8"))) {
     Sink sink =
         new Sink(new String[] {"start", "text1", "text2"}, new String[] {"text1", "text2"});
     _sshdialog.connect();
     _sshdialog.authenticate();
     _sshdialog.executeCommand(sink, "cat", new InputStream[] {start});
     sink.exception();
   }
 }
예제 #7
0
 @Test
 public void testDelay() throws Throwable {
   ReaderSink sink = new ReaderSink(10);
   _sshdialog.setSoftTimeout(60 * 1000);
   _sshdialog.setHardTimeout(60 * 1000);
   _sshdialog.connect();
   _sshdialog.authenticate();
   _sshdialog.executeCommand(
       sink, "x=0;while [ $x -lt 100 ]; do echo line$x; x=$(($x+1)); done", null);
   sink.exception();
   assertEquals("line99", sink.getLast());
 }
예제 #8
0
 @After
 public void tearDown() {
   try {
     if (_sshdialog != null) {
       _sshdialog.close();
       _sshdialog = null;
     }
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
예제 #9
0
 @Test(expected = AuthenticationException.class)
 public void testWrongKeyPair() throws Exception {
   _sshdialog.setKeyPair(KeyPairGenerator.getInstance("RSA").generateKeyPair());
   _sshdialog.connect();
   _sshdialog.authenticate();
 }
예제 #10
0
 @Test
 public void testPassword() throws Exception {
   _sshdialog.setKeyPair(null);
   _sshdialog.connect();
   _sshdialog.authenticate();
 }
예제 #11
0
 @Test
 public void testKeyPair() throws Exception {
   _sshdialog.connect();
   _sshdialog.authenticate();
 }