summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/openslx/imagemaster
diff options
context:
space:
mode:
authorSimon Rettberg2014-04-19 16:44:55 +0200
committerSimon Rettberg2014-04-19 16:44:55 +0200
commit494a977ab1004c480e60c57183be4e130372e72e (patch)
tree373f29a6967c91830e890e9b1ee878277008ee86 /src/test/java/org/openslx/imagemaster
parentAdd doc-comments to ApiServer and Hash, some TODO comments (diff)
downloadmasterserver-494a977ab1004c480e60c57183be4e130372e72e.tar.gz
masterserver-494a977ab1004c480e60c57183be4e130372e72e.tar.xz
masterserver-494a977ab1004c480e60c57183be4e130372e72e.zip
Added test case for sha512crypt, removed try/catch blocks from other tests, so they actually fail if something is wrong.
Diffstat (limited to 'src/test/java/org/openslx/imagemaster')
-rw-r--r--src/test/java/org/openslx/imagemaster/AppTest.java200
1 files changed, 91 insertions, 109 deletions
diff --git a/src/test/java/org/openslx/imagemaster/AppTest.java b/src/test/java/org/openslx/imagemaster/AppTest.java
index 5b5988b..120bd9e 100644
--- a/src/test/java/org/openslx/imagemaster/AppTest.java
+++ b/src/test/java/org/openslx/imagemaster/AppTest.java
@@ -4,11 +4,10 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ConnectException;
+import java.net.SocketException;
import java.util.Date;
import java.util.UUID;
-import javax.swing.text.html.ImageView;
-
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -21,13 +20,13 @@ import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
-import org.apache.thrift.transport.TTransportException;
+import org.openslx.imagemaster.thrift.iface.FtpCredentials;
import org.openslx.imagemaster.thrift.iface.ImageData;
import org.openslx.imagemaster.thrift.iface.ImageServer.Client;
-import org.openslx.imagemaster.thrift.iface.FtpCredentials;
import org.openslx.imagemaster.thrift.iface.ServerSessionData;
import org.openslx.imagemaster.thrift.iface.SessionData;
import org.openslx.imagemaster.thrift.iface.UserInfo;
+import org.openslx.imagemaster.util.Sha512Crypt;
/**
* Unit test for simple App.
@@ -63,128 +62,111 @@ public class AppTest
/**
* Test the authentication
+ * @throws TException
*/
- public void testAuthentication() {
+ public void testAuthentication() throws TException {
TTransport transport = new TSocket("localhost", 9090);
- try {
- transport.open();
- } catch (TTransportException e) {
- assertTrue("Could not connect", false);
- }
+ transport.open();
TProtocol protocol = new TBinaryProtocol(transport);
Client client = new Client(protocol);
- try {
- assertTrue("Could not ping server", client.ping());
- } catch (TException e) {
- assertTrue("Could not ping server", false);
- }
- try {
- SessionData sessionData = client.authenticate("ns202", "xxxxxxxxxxxx");
- UserInfo userInfo = client.getUserFromToken(sessionData.getAuthToken());
- System.out.println("User info: " + userInfo);
- System.out.println("Server address from MySQL: " + sessionData.serverAddress);
- } catch (TException e) {
- //e.printStackTrace();
- //assertTrue("Could not login", false);
- }
+ assertTrue("Could not ping server", client.ping());
+
+ SessionData sessionData = client.authenticate("ns202", "xxxxxxxxxxxx");
+ UserInfo userInfo = client.getUserFromToken(sessionData.getAuthToken());
+ System.out.println("User info: " + userInfo);
+ System.out.println("Server address from MySQL: " + sessionData.serverAddress);
}
/**
- * Test the server authentification.
+ * Test the server authentication.
+ * @throws TException
+ * @throws IOException
+ * @throws SocketException
*/
- public void testServerAuth() {
+ public void testServerAuth() throws TException, SocketException, IOException {
TTransport transport = new TSocket("localhost", 9090);
- try {
- transport.open();
- } catch (TTransportException e) {
- assertTrue("Could not connect", false);
- }
+ transport.open();
TProtocol protocol = new TBinaryProtocol(transport);
Client client = new Client(protocol);
- try {
- assertTrue("Could not ping server", client.ping());
- } catch (TException e) {
- assertTrue("Could not ping server", false);
- }
+ assertTrue("Could not ping server", client.ping());
+
+ String stringToEncrypt = client.startServerAuthentication("Test Organization");
+ System.out.println("Authentication started. Got string: " + stringToEncrypt);
+
+ String response = stringToEncrypt;
+
+ ServerSessionData data = client.serverAuthenticate("Test Organization", response);
+ System.out.println("Authenticated and got sid: '" + data.getSessionId() + "'");
+
+
+ // Create ImageData
+ int version = 1;
+ String imageName = "maschine.vmkd";
+ UUID uuid = UUID.randomUUID();
+ int imageCreateTime = (int) new Date().getTime();
+ int imageUpdateTime = imageCreateTime;
+ String imageOwner = "ns202";
+ String contentOperatingSystem = "win7";
+ boolean statusIsValid = true;
+ boolean statusIsDeleted = false;
+ String imageShortDescrption = "EIN SUPER TOLLES IMAGE!";
+ String imageLongDescription = "Lorem ipsum dolor sit amet.";
+
+ ImageData imageData = new ImageData(uuid.toString(), version, imageName,
+ imageCreateTime, imageUpdateTime, imageOwner, contentOperatingSystem,
+ statusIsValid, statusIsDeleted, imageShortDescrption, imageLongDescription);
+
+ System.out.println("Created imageData");
+
+ FtpCredentials ftpCredentials = client.submitImage(imageData, data);
+ System.out.println("Got FTP credentials. User: " + ftpCredentials.username + ", password: " + ftpCredentials.password);
+
+ FTPClient FtpClient = new FTPClient();
+ String host = "localhost";
+ int port = 2221;
+ String user = ftpCredentials.username;
+ String password = ftpCredentials.password;
+ String fileName = "/home/nils/file_to_upload.bin";
try {
- String stringToEncrypt = client.startServerAuthentication("Test Organization");
- System.out.println("Authentication started. Got string: " + stringToEncrypt);
-
- String response = stringToEncrypt;
-
- ServerSessionData data = client.serverAuthenticate("Test Organization", response);
- System.out.println("Authenticated and got sid: '" + data.getSessionId() + "'");
-
-
- // Create ImageData
- int version = 1;
- String imageName = "maschine.vmkd";
- UUID uuid = UUID.randomUUID();
- int imageCreateTime = (int) new Date().getTime();
- int imageUpdateTime = imageCreateTime;
- String imageOwner = "ns202";
- String contentOperatingSystem = "win7";
- boolean statusIsValid = true;
- boolean statusIsDeleted = false;
- String imageShortDescrption = "EIN SUPER TOLLES IMAGE!";
- String imageLongDescription = "Lorem ipsum dolor sit amet.";
-
- ImageData imageData = new ImageData(uuid.toString(), version, imageName,
- imageCreateTime, imageUpdateTime, imageOwner, contentOperatingSystem,
- statusIsValid, statusIsDeleted, imageShortDescrption, imageLongDescription);
-
- System.out.println("Created imageData");
-
- FtpCredentials ftpCredentials = client.submitImage(imageData, data);
- System.out.println("Got FTP credentials. User: " + ftpCredentials.username + ", password: " + ftpCredentials.password);
-
- FTPClient FtpClient = new FTPClient();
- String host = "localhost";
- int port = 2221;
- String user = ftpCredentials.username;
- String password = ftpCredentials.password;
- String fileName = "/home/nils/file_to_upload.bin";
-
- try {
- FtpClient.connect(host, port);
- System.out.println("Connected to " + host + ":" + port + ". Reply code: " + FtpClient.getReplyCode());
- if ( !FTPReply.isPositiveCompletion( FtpClient.getReplyCode() ) ) {
- ConnectException ce = new ConnectException("No positive reply code.");
- throw ce;
- }
- if ( !FtpClient.login(user, password) ) {
- ConnectException ce = new ConnectException("Could not login.");
- throw ce;
- }
- System.out.println("Logged in with user: " + user);
- FtpClient.setFileType(FTP.BINARY_FILE_TYPE);
- FtpClient.enterLocalPassiveMode();
- System.out.println("Entered PASSIVE MODE");
- InputStream input = new FileInputStream(fileName);
- System.out.print("Starting file upload ... ");
- FtpClient.storeFile("xcvb.vmdk", input);
- System.out.println("done.");
- FtpClient.noop();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (FtpClient.isConnected()) {
- try {
- FtpClient.logout();
- FtpClient.disconnect();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ FtpClient.connect(host, port);
+ System.out.println("Connected to " + host + ":" + port + ". Reply code: " + FtpClient.getReplyCode());
+ if ( !FTPReply.isPositiveCompletion( FtpClient.getReplyCode() ) ) {
+ ConnectException ce = new ConnectException("No positive reply code.");
+ throw ce;
+ }
+ if ( !FtpClient.login(user, password) ) {
+ ConnectException ce = new ConnectException("Could not login.");
+ throw ce;
+ }
+ System.out.println("Logged in with user: " + user);
+ FtpClient.setFileType(FTP.BINARY_FILE_TYPE);
+ FtpClient.enterLocalPassiveMode();
+ System.out.println("Entered PASSIVE MODE");
+ InputStream input = new FileInputStream(fileName);
+ System.out.print("Starting file upload ... ");
+ FtpClient.storeFile("xcvb.vmdk", input);
+ System.out.println("done.");
+ FtpClient.noop();
+ } finally {
+ if (FtpClient.isConnected()) {
+ try {
+ FtpClient.logout();
+ FtpClient.disconnect();
+ } catch (IOException e) {
+ e.printStackTrace();
}
- }
-
- } catch (TException e) {
- e.printStackTrace();
- }
+ }
+ }
+
+ }
+
+ public void testSha512_Crypt()
+ {
+ Sha512Crypt.selfTest();
}
}