diff options
author | Nils Schwabe | 2014-04-10 15:49:18 +0200 |
---|---|---|
committer | Nils Schwabe | 2014-04-10 15:49:18 +0200 |
commit | 298f7ca2b7e8861a70e31da237a775f45d77b597 (patch) | |
tree | c838288c443d976251a216f6a9318f4860907785 /src/test | |
parent | added some comments (diff) | |
download | masterserver-298f7ca2b7e8861a70e31da237a775f45d77b597.tar.gz masterserver-298f7ca2b7e8861a70e31da237a775f45d77b597.tar.xz masterserver-298f7ca2b7e8861a70e31da237a775f45d77b597.zip |
tried to implement the server auth. (did not work)
added ImageProcessor to process image after ftp upload
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/org/openslx/imagemaster/AppTest.java | 188 |
1 files changed, 134 insertions, 54 deletions
diff --git a/src/test/java/org/openslx/imagemaster/AppTest.java b/src/test/java/org/openslx/imagemaster/AppTest.java index 6c1350c..e978478 100644 --- a/src/test/java/org/openslx/imagemaster/AppTest.java +++ b/src/test/java/org/openslx/imagemaster/AppTest.java @@ -18,7 +18,10 @@ 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.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; @@ -54,10 +57,87 @@ public class AppTest assertTrue( true ); } +// /** +// * Test the authentication +// */ +// public void testAuthentication() { +// TTransport transport = new TSocket("localhost", 9090); +// try { +// transport.open(); +// } catch (TTransportException e) { +// assertTrue("Could not connect", false); +// } +// +// 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); +// } +// } +// +// /** +// * Test FTP connection +// */ +// public void testFtpConnection() { +// FTPClient client = new FTPClient(); +// String host = "localhost"; +// int port = 2221; +// String user = "admin"; +// String password = "SI*HoZCC!]V)p>B2"; +// String fileName = "/home/nils/file_to_upload.bin"; +// +// try { +// client.connect(host, port); +// System.out.println("Connected to " + host + ":" + port + ". Reply code: " + client.getReplyCode()); +// if ( !FTPReply.isPositiveCompletion( client.getReplyCode() ) ) { +// ConnectException ce = new ConnectException("No positive reply code."); +// throw ce; +// } +// if ( !client.login(user, password) ) { +// ConnectException ce = new ConnectException("Could not login."); +// throw ce; +// } +// System.out.println("Logged in with user: " + user); +// client.setFileType(FTP.BINARY_FILE_TYPE); +// client.enterLocalPassiveMode(); +// System.out.println("Entered PASSIVE MODE"); +// InputStream input = new FileInputStream(fileName); +// client.makeDirectory("myFolder"); +// System.out.println("Made directory 'myFolder'"); +// System.out.print("Starting file upload ... "); +// client.storeFile("myFolder/myFile.txt", input); +// System.out.println("done."); +// client.noop(); +// } catch (IOException e) { +// e.printStackTrace(); +// } finally { +// if (client.isConnected()) { +// try { +// client.logout(); +// client.disconnect(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// } +// } + /** - * Test the authentication + * Test the server authentification. */ - public void testAuthentication() { + public void testServerAuth() { TTransport transport = new TSocket("localhost", 9090); try { transport.open(); @@ -73,61 +153,61 @@ public class AppTest } 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); + 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() + "'"); + + FtpCredentials ftpCredentials = client.submitImage(new ImageData("123", "maschine"), 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("maschine.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(); + } + } + } + } catch (TException e) { e.printStackTrace(); - assertTrue("Could not login", false); } } - - /** - * Test FTP connection - */ - public void testFtpConnection() { - FTPClient client = new FTPClient(); - String host = "localhost"; - int port = 2221; - String user = "admin"; - String password = "SI*HoZCC!]V)p>B2"; - String fileName = "/home/nils/file_to_upload.bin"; - - try { - client.connect(host, port); - System.out.println("Connected to " + host + ":" + port + ". Reply code: " + client.getReplyCode()); - if ( !FTPReply.isPositiveCompletion( client.getReplyCode() ) ) { - ConnectException ce = new ConnectException("No positive reply code."); - throw ce; - } - if ( !client.login(user, password) ) { - ConnectException ce = new ConnectException("Could not login."); - throw ce; - } - System.out.println("Logged in with user: " + user); - client.setFileType(FTP.BINARY_FILE_TYPE); - client.enterLocalPassiveMode(); - System.out.println("Entered PASSIVE MODE"); - InputStream input = new FileInputStream(fileName); - client.makeDirectory("myFolder"); - System.out.println("Made directory 'myFolder'"); - System.out.print("Starting file upload ... "); - client.storeFile("myFolder/myFile.txt", input); - System.out.println("done."); - client.noop(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (client.isConnected()) { - try { - client.logout(); - client.disconnect(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - } } |