diff options
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/java/org/openslx/imagemaster/AppTest.java | 8 | ||||
| -rw-r--r-- | src/test/java/org/openslx/imagemaster/ServerTest.java | 200 |
2 files changed, 100 insertions, 108 deletions
diff --git a/src/test/java/org/openslx/imagemaster/AppTest.java b/src/test/java/org/openslx/imagemaster/AppTest.java index 2b20b77..cbb6ad2 100644 --- a/src/test/java/org/openslx/imagemaster/AppTest.java +++ b/src/test/java/org/openslx/imagemaster/AppTest.java @@ -52,12 +52,4 @@ public class AppTest extends TestCase { Sha512Crypt.selfTest(); } - - public void testMessageSigning() throws UnrecoverableKeyException, InvalidKeyException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, KeyStoreException, SignatureException, IOException { - String asdf = "Hallo"; - AsymMessageSign mySigner = new AsymMessageSign( "ftp", "password", "./config/keystore.jks" ); - byte[] signedMessage = mySigner.signMessage( asdf ); - System.out.println("The signed message: " + signedMessage + " with length: " + signedMessage.length); - assertTrue("Message could not be verified.", mySigner.verifyMessage( signedMessage, asdf.getBytes() )); - } } diff --git a/src/test/java/org/openslx/imagemaster/ServerTest.java b/src/test/java/org/openslx/imagemaster/ServerTest.java index 5f71fd5..d2a7d14 100644 --- a/src/test/java/org/openslx/imagemaster/ServerTest.java +++ b/src/test/java/org/openslx/imagemaster/ServerTest.java @@ -104,104 +104,104 @@ public class ServerTest extends TestCase * @throws InvalidKeyException * @throws InvalidAlgorithmParameterException */ - public void testServerAuthAndFtpUpload() throws TException, SocketException, IOException, UnrecoverableKeyException, NoSuchAlgorithmException, CertificateException, KeyStoreException, InvalidKeyException, SignatureException, InvalidAlgorithmParameterException - { - if (true) return; - - @SuppressWarnings( "unused" ) - TTransport transport = new TSocket( "localhost", 9090 ); - transport.open(); - - TProtocol protocol = new TBinaryProtocol( transport ); - Client client = new Client( protocol ); - - assertTrue( "Could not ping server", client.ping() ); - - String stringToEncrypt = client.startServerAuthentication( "Test Organization" ); - System.out.println( "Authentication started. Got string: " + stringToEncrypt ); - - AsymMessageSign messageSigner = new AsymMessageSign( "ftp", "password", "./config/keystore.jks" ); - byte[] response = messageSigner.signMessage( stringToEncrypt ); - - System.out.println( "Signed string: " + response ); - ByteBuffer bBuffer = ByteBuffer.wrap( response ); - - ServerSessionData data = client.serverAuthenticate( "Test Organization", bBuffer ); - System.out.println( "Authenticated and got sid: '" + data.getSessionId() + "'" ); - - // Create ImageData - int version = 1; - String imageName = "maschine.vmkd"; - UUID uuid = UUID.randomUUID(); - long imageCreateTime = System.currentTimeMillis(); - long 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."; - - String fileName = "/home/nils/file_to_upload.bin"; - - ImageData imageData = new ImageData( uuid.toString(), version, imageName, - imageCreateTime, imageUpdateTime, imageOwner, contentOperatingSystem, - 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", true ); - System.out.println("Created new ftpsclient..."); - 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.."); - trustManagerFactory.init( keystore ); - TrustManager trustManager = trustManagerFactory.getTrustManagers()[0]; - FtpClient.setTrustManager(trustManager); - - System.out.println("Trying to connect..."); - - String host = "localhost"; - int port = 2221; - String user = ftpCredentials.username; - String password = ftpCredentials.password; - - try { - FtpClient.connect( host, port ); - System.out.println( "Connected to " + host + ":" + port + ". Reply code: " + FtpClient.getReplyCode() ); - if ( !FTPReply.isPositiveCompletion( FtpClient.getReplyCode() ) ) { - throw new ConnectException( "No positive reply code." ); - } - if ( !FtpClient.login( user, password ) ) { - throw new ConnectException( "Could not login." ); - } - 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 (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(); - } - } - } - - } +// public void testServerAuthAndFtpUpload() throws TException, SocketException, IOException, UnrecoverableKeyException, NoSuchAlgorithmException, CertificateException, KeyStoreException, InvalidKeyException, SignatureException, InvalidAlgorithmParameterException +// { +// if (true) return; +// +// @SuppressWarnings( "unused" ) +// TTransport transport = new TSocket( "localhost", 9090 ); +// transport.open(); +// +// TProtocol protocol = new TBinaryProtocol( transport ); +// Client client = new Client( protocol ); +// +// assertTrue( "Could not ping server", client.ping() ); +// +// String stringToEncrypt = client.startServerAuthentication( "Test Organization" ); +// System.out.println( "Authentication started. Got string: " + stringToEncrypt ); +// +// AsymMessageSign messageSigner = new AsymMessageSign( "ftp", "password", "./config/keystore.jks" ); +// byte[] response = messageSigner.signMessage( stringToEncrypt ); +// +// System.out.println( "Signed string: " + response ); +// ByteBuffer bBuffer = ByteBuffer.wrap( response ); +// +// ServerSessionData data = client.serverAuthenticate( "Test Organization", bBuffer ); +// System.out.println( "Authenticated and got sid: '" + data.getSessionId() + "'" ); +// +// // Create ImageData +// int version = 1; +// String imageName = "maschine.vmkd"; +// UUID uuid = UUID.randomUUID(); +// long imageCreateTime = System.currentTimeMillis(); +// long 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."; +// +// String fileName = "/home/nils/file_to_upload.bin"; +// +// ImageData imageData = new ImageData( uuid.toString(), version, imageName, +// imageCreateTime, imageUpdateTime, imageOwner, contentOperatingSystem, +// 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", true ); +// System.out.println("Created new ftpsclient..."); +// 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.."); +// trustManagerFactory.init( keystore ); +// TrustManager trustManager = trustManagerFactory.getTrustManagers()[0]; +// FtpClient.setTrustManager(trustManager); +// +// System.out.println("Trying to connect..."); +// +// String host = "localhost"; +// int port = 2221; +// String user = ftpCredentials.username; +// String password = ftpCredentials.password; +// +// try { +// FtpClient.connect( host, port ); +// System.out.println( "Connected to " + host + ":" + port + ". Reply code: " + FtpClient.getReplyCode() ); +// if ( !FTPReply.isPositiveCompletion( FtpClient.getReplyCode() ) ) { +// throw new ConnectException( "No positive reply code." ); +// } +// if ( !FtpClient.login( user, password ) ) { +// throw new ConnectException( "Could not login." ); +// } +// 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 (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(); +// } +// } +// } +// +// } } |
