@Test(expected = AuthenticationException.class) public void testWrongPassword() throws Exception { _sshdialog.setKeyPair(null); _sshdialog.setPassword("bad"); _sshdialog.connect(); _sshdialog.authenticate(); }
@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(); }
@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(); }
@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(); } }
@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(); } }
@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()); }
@Test(expected = AuthenticationException.class) public void testWrongKeyPair() throws Exception { _sshdialog.setKeyPair(KeyPairGenerator.getInstance("RSA").generateKeyPair()); _sshdialog.connect(); _sshdialog.authenticate(); }
@Test public void testPassword() throws Exception { _sshdialog.setKeyPair(null); _sshdialog.connect(); _sshdialog.authenticate(); }
@Test public void testKeyPair() throws Exception { _sshdialog.connect(); _sshdialog.authenticate(); }