if (!afuture.await(softTimeout)) { throw new TimeLimitExceededException( String.format(
log.debug("waiting to send authentication"); try { this.authFuture.await(); // TODO use verify + configurable timeout } catch (IOException e) { log.debug("Unexpected exception", e);
log.debug("waiting to send authentication"); try { this.authFuture.await(); // TODO use verify + configurable timeout } catch (IOException e) { log.debug("Unexpected exception", e);
private static void assertAuthenticationResult(String message, AuthFuture future, boolean expected) throws IOException { assertTrue(message + ": failed to get result on time", future.await(5L, TimeUnit.SECONDS)); assertEquals(message + ": mismatched authentication result", expected, future.isSuccess()); }
@Test public void testPasswordTimeout() throws Exception { SSHClient client = spy(this.client); SshClient ssh = spy(SshClient.setUpDefaultClient()); ConnectFuture future = mock(ConnectFuture.class); ClientSession session = mock(ClientSession.class); doReturn(ssh).when(client).createSshClient(); doReturn(future).when(ssh).connect(any(), any(), anyInt()); when(future.await(anyLong())).thenReturn(true); when(future.getSession()).thenReturn(session); AuthFuture authFuture = mock(AuthFuture.class); when(authFuture.await(anyLong())).thenReturn(false); when(session.auth()).thenReturn(authFuture); assertThrows(TimeLimitExceededException.class, () -> { client.connect(); client.authenticate(); }); } }
log.debug("waiting to send authentication"); try { this.authFuture.await(); // TODO use verify + configurable timeout } catch (IOException e) { log.debug("Unexpected exception", e);
private static void assertAuthenticationResult(String message, AuthFuture future, boolean expected) throws IOException { assertTrue(message + ": failed to get result on time", future.await(5L, TimeUnit.SECONDS)); assertEquals(message + ": mismatched authentication result", expected, future.isSuccess()); }
private static void assertAuthenticationResult(String message, AuthFuture future, boolean expected) throws IOException { assertTrue(message + ": failed to get result on time", future.await(5L, TimeUnit.SECONDS)); assertEquals(message + ": mismatched authentication result", expected, future.isSuccess()); }
authFuture.await(AUTH_TIMEOUT); if (!authFuture.isSuccess()) { throw new SshException("Error establishing ssh connection to [" + username + "@" + host + ":" + port
assertTrue("Failed to authenticate on time", auth.await(5L, TimeUnit.SECONDS)); assertTrue("Authentication failed", auth.isSuccess()); } finally {
assertTrue("Failed to authenticate on time", auth.await(5L, TimeUnit.SECONDS)); assertTrue("Authentication failed", auth.isSuccess()); } finally {
assertTrue("Failed to authenticate on time", auth.await(5L, TimeUnit.SECONDS)); assertTrue("Authentication failed", auth.isSuccess()); } finally {
assertTrue("Failed to complete auth in allocated time", future.await(11L, TimeUnit.SECONDS)); assertFalse("Unexpected authentication success", future.isSuccess());
try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshd.getPort()).verify(7L, TimeUnit.SECONDS).getSession()) { AuthFuture auth = session.auth(); assertTrue("Failed to complete authentication on time", auth.await(17L, TimeUnit.SECONDS)); assertFalse("Unexpected authentication success", auth.isSuccess()); assertEquals("Mismatched interactive challenge calls", 1, challengeCount.get());
try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshd.getPort()).verify(7L, TimeUnit.SECONDS).getSession()) { AuthFuture auth = session.auth(); assertTrue("Failed to complete authentication on time", auth.await(17L, TimeUnit.SECONDS)); assertFalse("Unexpected authentication success", auth.isSuccess()); assertEquals("Mismatched interactive challenge calls", 1, challengeCount.get());
assertTrue("Failed to complete authentication on time", auth.await(11L, TimeUnit.SECONDS)); if (auth.isSuccess()) { assertTrue("Premature authentication success", index > 1);
try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshd.getPort()).verify(7L, TimeUnit.SECONDS).getSession()) { AuthFuture auth = session.auth(); assertTrue("Failed to complete authentication on time", auth.await(17L, TimeUnit.SECONDS)); assertFalse("Unexpected authentication success", auth.isSuccess()); assertEquals("Mismatched interactive challenge calls", 1, challengeCount.get());
@Test public void testFailAuthenticationWithFuture() throws Exception { final int maxAllowedAuths = 10; PropertyResolverUtils.updateProperty(sshd, ServerAuthenticationManager.MAX_AUTH_REQUESTS, maxAllowedAuths); sshd.start(); client.setServiceFactories(Arrays.asList( new ClientUserAuthServiceOld.Factory(), ClientConnectionServiceFactory.INSTANCE )); client.start(); try (ClientSession s = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshd.getPort()).verify(7L, TimeUnit.SECONDS).getSession()) { int nbTrials = 0; AuthFuture authFuture; do { nbTrials++; assertTrue("Number of trials below max.", nbTrials < 100); authFuture = s.getService(ClientUserAuthServiceOld.class) .auth(new org.apache.sshd.deprecated.UserAuthPassword(s, "ssh-connection", "buggy")); assertTrue("Authentication wait failed", authFuture.await(5L, TimeUnit.SECONDS)); assertTrue("Authentication not done", authFuture.isDone()); assertFalse("Authentication unexpectedly successful", authFuture.isSuccess()); } while (authFuture.getException() == null); Throwable t = authFuture.getException(); assertNotNull("Missing auth future exception", t); assertTrue("Number trials (" + nbTrials + ") below min.=" + maxAllowedAuths, nbTrials > maxAllowedAuths); } finally { client.stop(); } }
@Test public void testFailAuthenticationWithFuture() throws Exception { final int maxAllowedAuths = 10; PropertyResolverUtils.updateProperty(sshd, ServerAuthenticationManager.MAX_AUTH_REQUESTS, maxAllowedAuths); sshd.start(); client.setServiceFactories(Arrays.asList( new ClientUserAuthServiceOld.Factory(), ClientConnectionServiceFactory.INSTANCE )); client.start(); try (ClientSession s = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshd.getPort()).verify(7L, TimeUnit.SECONDS).getSession()) { int nbTrials = 0; AuthFuture authFuture; do { nbTrials++; assertTrue("Number of trials below max.", nbTrials < 100); authFuture = s.getService(ClientUserAuthServiceOld.class) .auth(new org.apache.sshd.deprecated.UserAuthPassword(s, "ssh-connection", "buggy")); assertTrue("Authentication wait failed", authFuture.await(5L, TimeUnit.SECONDS)); assertTrue("Authentication not done", authFuture.isDone()); assertFalse("Authentication unexpectedly successful", authFuture.isSuccess()); } while (authFuture.getException() == null); Throwable t = authFuture.getException(); assertNotNull("Missing auth future exception", t); assertTrue("Number trials (" + nbTrials + ") below min.=" + maxAllowedAuths, nbTrials > maxAllowedAuths); } finally { client.stop(); } }
@Test public void testFailAuthenticationWithFuture() throws Exception { final int maxAllowedAuths = 10; PropertyResolverUtils.updateProperty(sshd, ServerAuthenticationManager.MAX_AUTH_REQUESTS, maxAllowedAuths); sshd.start(); client.setServiceFactories(Arrays.asList( new ClientUserAuthServiceOld.Factory(), ClientConnectionServiceFactory.INSTANCE )); client.start(); try (ClientSession s = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshd.getPort()).verify(7L, TimeUnit.SECONDS).getSession()) { int nbTrials = 0; AuthFuture authFuture; do { nbTrials++; assertTrue("Number of trials below max.", nbTrials < 100); authFuture = s.getService(ClientUserAuthServiceOld.class) .auth(new org.apache.sshd.deprecated.UserAuthPassword(s, "ssh-connection", "buggy")); assertTrue("Authentication wait failed", authFuture.await(5L, TimeUnit.SECONDS)); assertTrue("Authentication not done", authFuture.isDone()); assertFalse("Authentication unexpectedly successful", authFuture.isSuccess()); } while (authFuture.getException() == null); Throwable t = authFuture.getException(); assertNotNull("Missing auth future exception", t); assertTrue("Number trials (" + nbTrials + ") below min.=" + maxAllowedAuths, nbTrials > maxAllowedAuths); } finally { client.stop(); } }