Skip to content

Commit

Permalink
chore(Test): Adding SSL tests for Java
Browse files Browse the repository at this point in the history
see #4
  • Loading branch information
hypery2k committed Nov 5, 2019
1 parent 7be6ca1 commit 54d1224
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ install:

script:
- ./bin/build.sh
- ./bin/test.sh
35 changes: 35 additions & 0 deletions bin/test-utils/SSLPoke.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;

/** Establish a SSL connection to a host and port, writes a byte and
* prints the response. See
* http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services
*/
public class SSLPoke {
public static void main(String[] args) {
if (args.length != 2) {
System.out.println("Usage: "+SSLPoke.class.getName()+" <host> <port>");
System.exit(1);
}
try {
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket(args[0], Integer.parseInt(args[1]));

InputStream in = sslsocket.getInputStream();
OutputStream out = sslsocket.getOutputStream();

// Write a test byte to get a reaction :)
out.write(1);

while (in.available() > 0) {
System.out.print(in.read());
}
System.out.println("Successfully connected");

} catch (Exception exception) {
exception.printStackTrace();
System.exit(1);
}
}
}
28 changes: 26 additions & 2 deletions bin/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
#!/bin/sh

# FIXME: Run tests ;)
./bin/build.sh
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

function prepareTestImage {
docker run -td --name "test-$1" "toolisticon/$1"
}

function removeTestImage {
docker stop "test-$1"
docker rm "test-$1"
}

function runJavaImageTests {
removeTestImage $1 2>/dev/null || true
prepareTestImage "$1"
docker cp "$CURRENT_DIR/test-utils/SSLPoke.java" "test-$1":/tmp/
docker exec "test-$1" bash -c "cd /tmp && javac SSLPoke.java"
docker exec "test-$1" bash -c "cd /tmp && java SSLPoke google.de 443"
removeTestImage $1
}

# TODO more test

runJavaImageTests 'openjdk8-builder'
runJavaImageTests 'openjdk11-builder'
runJavaImageTests 'oraclejdk12-builder'
runJavaImageTests 'oraclejdk13-builder'

0 comments on commit 54d1224

Please sign in to comment.