setServiceFactories(DEFAULT_SERVICE_FACTORIES);
setServiceFactories(DEFAULT_SERVICE_FACTORIES);
@Test public void testFailAuthenticationWithWaitFor() 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; Collection<ClientSession.ClientSessionEvent> res = Collections.emptySet(); Collection<ClientSession.ClientSessionEvent> mask = EnumSet.of(ClientSession.ClientSessionEvent.CLOSED, ClientSession.ClientSessionEvent.WAIT_AUTH); while (!res.contains(ClientSession.ClientSessionEvent.CLOSED)) { nbTrials++; s.getService(ClientUserAuthServiceOld.class) .auth(new org.apache.sshd.deprecated.UserAuthPassword(s, "ssh-connection", "buggy")); res = s.waitFor(mask, TimeUnit.SECONDS.toMillis(5L)); assertFalse("Timeout signalled", res.contains(ClientSession.ClientSessionEvent.TIMEOUT)); } assertTrue("Number trials (" + nbTrials + ") below min.=" + maxAllowedAuths, nbTrials > maxAllowedAuths); } finally { client.stop(); } }
@Test public void testFailAuthenticationWithWaitFor() 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; Collection<ClientSession.ClientSessionEvent> res = Collections.emptySet(); Collection<ClientSession.ClientSessionEvent> mask = EnumSet.of(ClientSession.ClientSessionEvent.CLOSED, ClientSession.ClientSessionEvent.WAIT_AUTH); while (!res.contains(ClientSession.ClientSessionEvent.CLOSED)) { nbTrials++; s.getService(ClientUserAuthServiceOld.class) .auth(new org.apache.sshd.deprecated.UserAuthPassword(s, "ssh-connection", "buggy")); res = s.waitFor(mask, TimeUnit.SECONDS.toMillis(5L)); assertFalse("Timeout signalled", res.contains(ClientSession.ClientSessionEvent.TIMEOUT)); } assertTrue("Number trials (" + nbTrials + ") below min.=" + maxAllowedAuths, nbTrials > maxAllowedAuths); } finally { client.stop(); } }
@Test public void testFailAuthenticationWithWaitFor() 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; Collection<ClientSession.ClientSessionEvent> res = Collections.emptySet(); Collection<ClientSession.ClientSessionEvent> mask = EnumSet.of(ClientSession.ClientSessionEvent.CLOSED, ClientSession.ClientSessionEvent.WAIT_AUTH); while (!res.contains(ClientSession.ClientSessionEvent.CLOSED)) { nbTrials++; s.getService(ClientUserAuthServiceOld.class) .auth(new org.apache.sshd.deprecated.UserAuthPassword(s, "ssh-connection", "buggy")); res = s.waitFor(mask, TimeUnit.SECONDS.toMillis(5L)); assertFalse("Timeout signalled", res.contains(ClientSession.ClientSessionEvent.TIMEOUT)); } 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(); } }
@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(); } }