summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorManuel Bentele2021-03-12 10:35:51 +0100
committerManuel Bentele2021-03-12 10:35:51 +0100
commit3c0cfc6c05ee60e89f539a06214b36d4b2900b30 (patch)
tree5aef655cbe3cfd636e921c5cb875c6cb866df44c /src
parentFix warnings (diff)
downloadmasterserver-3c0cfc6c05ee60e89f539a06214b36d4b2900b30.tar.gz
masterserver-3c0cfc6c05ee60e89f539a06214b36d4b2900b30.tar.xz
masterserver-3c0cfc6c05ee60e89f539a06214b36d4b2900b30.zip
Add support of Junit 5 and refactor unit tests
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/openslx/imagemaster/util/Sha512Crypt.java9
-rw-r--r--src/test/java/org/openslx/imagemaster/AppTest.java69
-rw-r--r--src/test/java/org/openslx/imagemaster/util/Sha512CryptTest.java38
3 files changed, 38 insertions, 78 deletions
diff --git a/src/main/java/org/openslx/imagemaster/util/Sha512Crypt.java b/src/main/java/org/openslx/imagemaster/util/Sha512Crypt.java
index c4a4b61..0f89dbb 100644
--- a/src/main/java/org/openslx/imagemaster/util/Sha512Crypt.java
+++ b/src/main/java/org/openslx/imagemaster/util/Sha512Crypt.java
@@ -496,13 +496,4 @@ public final class Sha512Crypt
}
}
}
-
- /**
- * Test rig
- */
-
- public static void main(String arg[])
- {
- selfTest();
- }
}
diff --git a/src/test/java/org/openslx/imagemaster/AppTest.java b/src/test/java/org/openslx/imagemaster/AppTest.java
deleted file mode 100644
index 079d0c2..0000000
--- a/src/test/java/org/openslx/imagemaster/AppTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package org.openslx.imagemaster;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.openslx.imagemaster.util.Sha512Crypt;
-
-/**
- * Unit test for simple App.
- */
-public class AppTest extends TestCase
-{
-
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public AppTest(String testName)
- {
- super( testName );
- }
-
- /**
- * @return the suite of tests being tested
- */
- public static Test suite()
- {
- return new TestSuite( AppTest.class );
- }
-
- /**
- * Rigourous Test :-)
- */
- public void testApp()
- {
- assertTrue( true );
- }
-
- public void testSha512_Crypt()
- {
- Sha512Crypt.selfTest();
- }
-
- /* Fails...
- public void testImageProcessor() {
- ImageData imageData = new ImageData(UUID.randomUUID().toString(), 1, "windows7.vmdk",
- System.currentTimeMillis(), System.currentTimeMillis(), "ns202@uni-freiburg.de", "win7",
- true, false, "Windows 7", "Das ist ein tolles Windows 7", 40*16*1024*1024L); // exactly 40 blocks
-
- UploadInfos uploadInfos = ImageProcessor.getUploadInfos( "asdfasdfasdf", imageData );
- assertEquals( "Not the right number of blocks", 20, uploadInfos.missingBlocks.size() );
- for (int i = 0; i < uploadInfos.missingBlocks.size(); i++) {
- assertEquals(i, uploadInfos.missingBlocks.remove( 0 ).intValue());
- }
-
- String token = uploadInfos.getToken();
-
- uploadInfos = ImageProcessor.getUploadInfos( "asdfasdfasdf", imageData );
- assertEquals( "Not the right number of blocks", 20, uploadInfos.missingBlocks.size() );
- for (int i = 0; i < uploadInfos.missingBlocks.size(); i++) {
- assertEquals(i, uploadInfos.missingBlocks.remove( 0 ).intValue());
- }
-
- assertEquals("Wrong token was sent back.", token, uploadInfos.getToken());
- }
- */
-}
diff --git a/src/test/java/org/openslx/imagemaster/util/Sha512CryptTest.java b/src/test/java/org/openslx/imagemaster/util/Sha512CryptTest.java
new file mode 100644
index 0000000..af26b4c
--- /dev/null
+++ b/src/test/java/org/openslx/imagemaster/util/Sha512CryptTest.java
@@ -0,0 +1,38 @@
+package org.openslx.imagemaster.util;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.stream.Stream;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+public class Sha512CryptTest
+{
+ @ParameterizedTest
+ @MethodSource( "providePlainAndCryptText" )
+ public void testSha512Crypt( final String plainText, final String cryptText )
+ {
+ final String resultCryptText = Sha512Crypt.Sha512_crypt( plainText, cryptText, 0 );
+
+ assertEquals( cryptText, resultCryptText );
+ assertTrue( Sha512Crypt.verifyPassword( plainText, cryptText ) );
+ }
+
+ private static Stream<Arguments> providePlainAndCryptText()
+ {
+ // @formatter:off
+ return Stream.of(
+ Arguments.of( "Hello world!", "$6$saltstring$svn8UoSVapNtMuq1ukKS4tPQd8iKwSMHWjl/O817G3uBnIFNjnQJuesI68u4OTLiBFdcbYEdFCoEOfaS35inz1" ),
+ Arguments.of( "geheim", "$6$xxxxxxxx$wuSdyeOvQXjj/nNoWnjjo.6OxUWrQFRIj019kh1cDpun6l6cpr3ywSrBprYRYZXcm4Kv9lboCEFI3GzBkdNAz/" ),
+ Arguments.of( "Hello world!", "$6$rounds=10000$saltstringsaltst$OW1/O6BYHV6BcXZu8QVeXbDWra3Oeqh0sbHbbMCVNSnCM/UrjmM0Dp8vOuZeHBy/YTBmSK6H9qs/y3RnOaw5v." ),
+ Arguments.of( "This is just a test", "$6$rounds=5000$toolongsaltstrin$lQ8jolhgVRVhY4b5pZKaysCLi0QBxGoNeKQzQ3glMhwllF7oGDZxUhx1yxdYcz/e1JSbq3y6JMxxl8audkUEm0" ),
+ Arguments.of( "a very much longer text to encrypt. This one even stretches over morethan one line.", "$6$rounds=1400$anotherlongsalts$POfYwTEok97VWcjxIiSOjiykti.o/pQs.wPvMxQ6Fm7I6IoYN3CmLs66x9t0oSwbtEW7o7UmJEiDwGqd8p4ur1" ),
+ Arguments.of( "we have a short salt string but not a short password", "$6$rounds=77777$short$WuQyW2YR.hBNpjjRhpYD/ifIw05xdfeEyQoMxIXbkvr0gge1a1x3yRULJ5CCaUeOxFmtlcGZelFl5CxtgfiAc0" ),
+ Arguments.of( "a short string", "$6$rounds=123456$asaltof16chars..$BtCwjqMJGx5hrJhZywWvt0RLE8uZ4oPwcelCjmw2kSYu.Ec6ycULevoBK25fs2xXgMNrCzIMVcgEJAstJeonj1" ),
+ Arguments.of( "the minimum number is still observed", "$6$rounds=1000$roundstoolow$kUMsbe306n21p9R.FRkW3IGn.S9NPN0x50YhH1xhLsPuWGsUSklZt58jaTfF4ZEQpyUNGc0dqbpBYYBaHHrsX." ) );
+ // @formatter:on
+ }
+}