mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 23:30:55 +03:00
Fixed a few warnings
This commit is contained in:
@@ -50,7 +50,7 @@ public class RemotePortForwarderTest {
|
|||||||
public HttpServer httpServer = new HttpServer();
|
public HttpServer httpServer = new HttpServer();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws IOException {
|
public void setUp() throws IOException {
|
||||||
fixture.getServer().setTcpipForwardingFilter(new AcceptAllForwardingFilter());
|
fixture.getServer().setTcpipForwardingFilter(new AcceptAllForwardingFilter());
|
||||||
File file = httpServer.getDocRoot().newFile("index.html");
|
File file = httpServer.getDocRoot().newFile("index.html");
|
||||||
FileUtil.writeToFile(file, "<html><head/><body><h1>Hi!</h1></body></html>");
|
FileUtil.writeToFile(file, "<html><head/><body><h1>Hi!</h1></body></html>");
|
||||||
@@ -59,49 +59,49 @@ public class RemotePortForwarderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldHaveWorkingHttpServer() throws IOException {
|
public void shouldHaveWorkingHttpServer() throws IOException {
|
||||||
// Just to check that we have a working http server...
|
// Just to check that we have a working http server...
|
||||||
httpGet("127.0.0.1", 8080);
|
assertThat(httpGet("127.0.0.1", 8080), equalTo(200));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldDynamicallyForwardPortForLocalhost() throws IOException {
|
public void shouldDynamicallyForwardPortForLocalhost() throws IOException {
|
||||||
SSHClient sshClient = getFixtureClient();
|
SSHClient sshClient = getFixtureClient();
|
||||||
RemotePortForwarder.Forward bind = forwardPort(sshClient, "127.0.0.1", new SinglePort(0));
|
RemotePortForwarder.Forward bind = forwardPort(sshClient, "127.0.0.1", new SinglePort(0));
|
||||||
httpGet("127.0.0.1", bind.getPort());
|
assertThat(httpGet("127.0.0.1", bind.getPort()), equalTo(200));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldDynamicallyForwardPortForAllIPv4() throws IOException {
|
public void shouldDynamicallyForwardPortForAllIPv4() throws IOException {
|
||||||
SSHClient sshClient = getFixtureClient();
|
SSHClient sshClient = getFixtureClient();
|
||||||
RemotePortForwarder.Forward bind = forwardPort(sshClient, "0.0.0.0", new SinglePort(0));
|
RemotePortForwarder.Forward bind = forwardPort(sshClient, "0.0.0.0", new SinglePort(0));
|
||||||
httpGet("127.0.0.1", bind.getPort());
|
assertThat(httpGet("127.0.0.1", bind.getPort()), equalTo(200));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldDynamicallyForwardPortForAllProtocols() throws IOException {
|
public void shouldDynamicallyForwardPortForAllProtocols() throws IOException {
|
||||||
SSHClient sshClient = getFixtureClient();
|
SSHClient sshClient = getFixtureClient();
|
||||||
RemotePortForwarder.Forward bind = forwardPort(sshClient, "", new SinglePort(0));
|
RemotePortForwarder.Forward bind = forwardPort(sshClient, "", new SinglePort(0));
|
||||||
httpGet("127.0.0.1", bind.getPort());
|
assertThat(httpGet("127.0.0.1", bind.getPort()), equalTo(200));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldForwardPortForLocalhost() throws IOException {
|
public void shouldForwardPortForLocalhost() throws IOException {
|
||||||
SSHClient sshClient = getFixtureClient();
|
SSHClient sshClient = getFixtureClient();
|
||||||
RemotePortForwarder.Forward bind = forwardPort(sshClient, "127.0.0.1", RANGE);
|
RemotePortForwarder.Forward bind = forwardPort(sshClient, "127.0.0.1", RANGE);
|
||||||
httpGet("127.0.0.1", bind.getPort());
|
assertThat(httpGet("127.0.0.1", bind.getPort()), equalTo(200));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldForwardPortForAllIPv4() throws IOException {
|
public void shouldForwardPortForAllIPv4() throws IOException {
|
||||||
SSHClient sshClient = getFixtureClient();
|
SSHClient sshClient = getFixtureClient();
|
||||||
RemotePortForwarder.Forward bind = forwardPort(sshClient, "0.0.0.0", RANGE);
|
RemotePortForwarder.Forward bind = forwardPort(sshClient, "0.0.0.0", RANGE);
|
||||||
httpGet("127.0.0.1", bind.getPort());
|
assertThat(httpGet("127.0.0.1", bind.getPort()), equalTo(200));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldForwardPortForAllProtocols() throws IOException {
|
public void shouldForwardPortForAllProtocols() throws IOException {
|
||||||
SSHClient sshClient = getFixtureClient();
|
SSHClient sshClient = getFixtureClient();
|
||||||
RemotePortForwarder.Forward bind = forwardPort(sshClient, "", RANGE);
|
RemotePortForwarder.Forward bind = forwardPort(sshClient, "", RANGE);
|
||||||
httpGet("127.0.0.1", bind.getPort());
|
assertThat(httpGet("127.0.0.1", bind.getPort()), equalTo(200));
|
||||||
}
|
}
|
||||||
|
|
||||||
private RemotePortForwarder.Forward forwardPort(SSHClient sshClient, String address, PortRange portRange) throws IOException {
|
private RemotePortForwarder.Forward forwardPort(SSHClient sshClient, String address, PortRange portRange) throws IOException {
|
||||||
@@ -122,12 +122,12 @@ public class RemotePortForwarderTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void httpGet(String server, int port) throws IOException {
|
private int httpGet(String server, int port) throws IOException {
|
||||||
HttpClient client = HttpClientBuilder.create().build();
|
HttpClient client = HttpClientBuilder.create().build();
|
||||||
String urlString = "http://" + server + ":" + port;
|
String urlString = "http://" + server + ":" + port;
|
||||||
System.out.println("Trying: GET " + urlString);
|
System.out.println("Trying: GET " + urlString);
|
||||||
HttpResponse execute = client.execute(new HttpGet(urlString));
|
HttpResponse execute = client.execute(new HttpGet(urlString));
|
||||||
assertThat(execute.getStatusLine().getStatusCode(), equalTo(200));
|
return execute.getStatusLine().getStatusCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
private SSHClient getFixtureClient() throws IOException {
|
private SSHClient getFixtureClient() throws IOException {
|
||||||
|
|||||||
@@ -42,25 +42,17 @@ public abstract class BaseAlgorithmTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldVerifyAlgorithm() throws IOException {
|
public void shouldVerifyAlgorithm() throws IOException {
|
||||||
attempt(100);
|
for (int i = 0; i < 100; i++) {
|
||||||
}
|
|
||||||
|
|
||||||
private void attempt(int times) throws IOException {
|
|
||||||
for (int i = 0; i < times; i++) {
|
|
||||||
logger.info("--> Attempt {}", i);
|
logger.info("--> Attempt {}", i);
|
||||||
verify();
|
configureServer(fixture.getServer());
|
||||||
}
|
fixture.start();
|
||||||
}
|
Config config = getClientConfig(new DefaultConfig());
|
||||||
|
SSHClient sshClient = fixture.connectClient(fixture.setupClient(config));
|
||||||
private void verify() throws IOException {
|
assertThat("should be connected", sshClient.isConnected());
|
||||||
configureServer(fixture.getServer());
|
sshClient.disconnect();
|
||||||
fixture.start();
|
|
||||||
Config config = getClientConfig(new DefaultConfig());
|
|
||||||
SSHClient sshClient = fixture.connectClient(fixture.setupClient(config));
|
|
||||||
assertThat("should be connected", sshClient.isConnected());
|
|
||||||
sshClient.disconnect();
|
|
||||||
// fixture.stopServer();
|
// fixture.stopServer();
|
||||||
fixture.stopClient();
|
fixture.stopClient();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Config getClientConfig(DefaultConfig defaultConfig);
|
protected abstract Config getClientConfig(DefaultConfig defaultConfig);
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class AuthPasswordTest {
|
|||||||
fixture.getServer().setPasswordAuthenticator(new PasswordAuthenticator() {
|
fixture.getServer().setPasswordAuthenticator(new PasswordAuthenticator() {
|
||||||
@Override
|
@Override
|
||||||
public boolean authenticate(String username, String password, ServerSession session) {
|
public boolean authenticate(String username, String password, ServerSession session) {
|
||||||
if (password.equals("changeme")) {
|
if ("changeme".equals(password)) {
|
||||||
throw new PasswordChangeRequiredException("Password was changeme", "Please provide your updated password", "en_US");
|
throw new PasswordChangeRequiredException("Password was changeme", "Please provide your updated password", "en_US");
|
||||||
} else {
|
} else {
|
||||||
return password.equals(username);
|
return password.equals(username);
|
||||||
@@ -84,6 +84,7 @@ public class AuthPasswordTest {
|
|||||||
SSHClient sshClient = fixture.setupConnectedDefaultClient();
|
SSHClient sshClient = fixture.setupConnectedDefaultClient();
|
||||||
expectedException.expect(UserAuthException.class);
|
expectedException.expect(UserAuthException.class);
|
||||||
sshClient.authPassword("jeroen", "changeme");
|
sshClient.authPassword("jeroen", "changeme");
|
||||||
|
assertThat("Should not have authenticated", !sshClient.isAuthenticated());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ public class PathHelperTest {
|
|||||||
@Override
|
@Override
|
||||||
public String canonicalize(String path)
|
public String canonicalize(String path)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (path.equals("") || path.equals(".") || path.equals("./"))
|
if ("".equals(path) || ".".equals(path) || "./".equals(path))
|
||||||
return "/home/me";
|
return "/home/me";
|
||||||
if (path.equals("..") || path.equals("../"))
|
if ("..".equals(path) || "../".equals(path))
|
||||||
return "/home";
|
return "/home";
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user