diff options
author | Nils Schwabe | 2014-04-28 18:18:59 +0200 |
---|---|---|
committer | Nils Schwabe | 2014-04-28 18:18:59 +0200 |
commit | 287ad92152c530b400a5405a4672a41d92e4d368 (patch) | |
tree | 42dcb2c698672ae371d70a81ea5c49f3280db9c6 /src/test/java/org/openslx/imagemaster | |
parent | Add remove image from process list (when user gets deleted after timeout) (diff) | |
download | masterserver-287ad92152c530b400a5405a4672a41d92e4d368.tar.gz masterserver-287ad92152c530b400a5405a4672a41d92e4d368.tar.xz masterserver-287ad92152c530b400a5405a4672a41d92e4d368.zip |
Add ftp users and images in processing list are remembered
Diffstat (limited to 'src/test/java/org/openslx/imagemaster')
-rw-r--r-- | src/test/java/org/openslx/imagemaster/ServerTest.java | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/src/test/java/org/openslx/imagemaster/ServerTest.java b/src/test/java/org/openslx/imagemaster/ServerTest.java index bb81432..de3bc04 100644 --- a/src/test/java/org/openslx/imagemaster/ServerTest.java +++ b/src/test/java/org/openslx/imagemaster/ServerTest.java @@ -1,12 +1,15 @@ package org.openslx.imagemaster; +import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.net.ConnectException; import java.net.SocketException; import java.nio.ByteBuffer; +import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.KeyStore; import java.security.KeyStoreException; @@ -14,18 +17,18 @@ import java.security.NoSuchAlgorithmException; import java.security.SignatureException; import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; -import java.util.Date; import java.util.UUID; +import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; -import javax.net.ssl.X509TrustManager; + +import junit.framework.TestCase; import org.apache.commons.net.ftp.FTP; -import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPReply; import org.apache.commons.net.ftp.FTPSClient; +import org.apache.log4j.Logger; import org.apache.thrift.TException; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocol; @@ -33,17 +36,17 @@ import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TTransport; 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.ServerSessionData; import org.openslx.imagemaster.thrift.iface.SessionData; import org.openslx.imagemaster.thrift.iface.UserInfo; -import org.openslx.imagemaster.thrift.iface.ImageServer.Client; import org.openslx.imagemaster.util.AsymMessageSign; -import junit.framework.TestCase; - public class ServerTest extends TestCase { + private static Logger log = Logger.getLogger( ServerTest.class ); + @Override public void setUp() throws Exception { // start the server @@ -63,8 +66,9 @@ public class ServerTest extends TestCase * Test the authentication * * @throws TException + * @throws IOException */ - public void testAuthentication() throws TException + public void testAuthentication() throws TException, IOException { TTransport transport = new TSocket( "localhost", 9090 ); transport.open(); @@ -73,8 +77,14 @@ public class ServerTest extends TestCase Client client = new Client( protocol ); assertTrue( "Could not ping server", client.ping() ); + + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + System.out.print("Enter username: "); + String username = reader.readLine(); + System.out.print("Enter password: "); + String password = reader.readLine(); - SessionData sessionData = client.authenticate( "ns202", "xxxxxxxxxxxx" ); + SessionData sessionData = client.authenticate( username, password ); UserInfo userInfo = client.getUserFromToken( sessionData.getAuthToken() ); System.out.println( "User info: " + userInfo ); System.out.println( "Server address from MySQL: " + sessionData.serverAddress ); @@ -92,8 +102,9 @@ public class ServerTest extends TestCase * @throws UnrecoverableKeyException * @throws SignatureException * @throws InvalidKeyException + * @throws InvalidAlgorithmParameterException */ - public void testServerAuthAndFtpUpload() throws TException, SocketException, IOException, UnrecoverableKeyException, NoSuchAlgorithmException, CertificateException, KeyStoreException, InvalidKeyException, SignatureException + public void testServerAuthAndFtpUpload() throws TException, SocketException, IOException, UnrecoverableKeyException, NoSuchAlgorithmException, CertificateException, KeyStoreException, InvalidKeyException, SignatureException, InvalidAlgorithmParameterException { TTransport transport = new TSocket( "localhost", 9090 ); transport.open(); @@ -127,19 +138,21 @@ public class ServerTest extends TestCase boolean statusIsDeleted = false; String imageShortDescrption = "EIN SUPER TOLLES IMAGE!"; String imageLongDescription = "Lorem ipsum dolor sit amet."; + + String fileName = "/home/nils/file_to_upload.bin"; ImageData imageData = new ImageData( uuid.toString(), version, imageName, imageCreateTime, imageUpdateTime, imageOwner, contentOperatingSystem, - statusIsValid, statusIsDeleted, imageShortDescrption, imageLongDescription ); + statusIsValid, statusIsDeleted, imageShortDescrption, imageLongDescription, new File(fileName).getTotalSpace() ); System.out.println( "Created imageData..." ); FtpCredentials ftpCredentials = client.submitImage( data.sessionId, imageData ); System.out.println( "Got FTP credentials. User: " + ftpCredentials.username + ", password: " + ftpCredentials.password ); - FTPSClient FtpClient = new FTPSClient( "SSL" ); + FTPSClient FtpClient = new FTPSClient( "SSL", true ); System.out.println("Created new ftpsclient..."); - TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance( "JKS" ); + TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance( KeyManagerFactory.getDefaultAlgorithm() ); KeyStore keystore = KeyStore.getInstance( "JKS" ); keystore.load( new FileInputStream( new File( "./config/keystore.jks" ) ), "password".toCharArray() ); System.out.println("Loaded keystore.."); @@ -153,18 +166,15 @@ public class ServerTest extends TestCase 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; + throw new ConnectException( "No positive reply code." ); } if ( !FtpClient.login( user, password ) ) { - ConnectException ce = new ConnectException( "Could not login." ); - throw ce; + throw new ConnectException( "Could not login." ); } System.out.println( "Logged in with user: " + user ); FtpClient.setFileType( FTP.BINARY_FILE_TYPE ); @@ -175,12 +185,15 @@ public class ServerTest extends TestCase FtpClient.storeFile( "xcvb.vmdk", input ); System.out.println( "done." ); FtpClient.noop(); - client.finshedUpload( data.sessionId, imageData ); + } catch (Exception e) { + e.printStackTrace(); } finally { if ( FtpClient.isConnected() ) { try { FtpClient.logout(); FtpClient.disconnect(); + boolean result = client.finshedUpload( ftpCredentials.username, imageData ); + System.out.println("Telling server that upload finished: " + result); } catch ( IOException e ) { e.printStackTrace(); } |