diff --git a/core/src/test/groovy/jenkins/security/CryptoConfidentialKeyTest.groovy b/core/src/test/groovy/jenkins/security/CryptoConfidentialKeyTest.groovy deleted file mode 100644 index e3816a342c4e76e04469993ab0a9ea61a3af57c3..0000000000000000000000000000000000000000 --- a/core/src/test/groovy/jenkins/security/CryptoConfidentialKeyTest.groovy +++ /dev/null @@ -1,37 +0,0 @@ -package jenkins.security - -import org.junit.Rule -import org.junit.Test - -/** - * - * - * @author Kohsuke Kawaguchi - */ -class CryptoConfidentialKeyTest { - @Rule - public ConfidentialStoreRule store = new ConfidentialStoreRule() - - def key = new CryptoConfidentialKey("test") - - @Test - void decryptGetsPlainTextBack() { - ["Hello world","","\u0000"].each { str -> - assert key.decrypt().doFinal(key.encrypt().doFinal(str.bytes))==str.bytes - } - } - - @Test - void multipleEncryptsAreIdempotent() { - def str = "Hello world".bytes - assert key.encrypt().doFinal(str)==key.encrypt().doFinal(str) - } - - @Test - void loadingExistingKey() { - def key2 = new CryptoConfidentialKey("test") // this will cause the key to be loaded from the disk - ["Hello world","","\u0000"].each { str -> - assert key2.decrypt().doFinal(key.encrypt().doFinal(str.bytes))==str.bytes - } - } -} diff --git a/core/src/test/java/jenkins/security/CryptoConfidentialKeyTest.java b/core/src/test/java/jenkins/security/CryptoConfidentialKeyTest.java new file mode 100644 index 0000000000000000000000000000000000000000..1b302a358bf960c19472fb8e857496de9bf10841 --- /dev/null +++ b/core/src/test/java/jenkins/security/CryptoConfidentialKeyTest.java @@ -0,0 +1,35 @@ +package jenkins.security; + +import static org.junit.Assert.*; +import org.junit.Rule; +import org.junit.Test; + +public class CryptoConfidentialKeyTest { + + @Rule + public ConfidentialStoreRule store = new ConfidentialStoreRule(); + + private CryptoConfidentialKey key = new CryptoConfidentialKey("test"); + + @Test + public void decryptGetsPlainTextBack() throws Exception { + for (String str : new String[] {"Hello world", "", "\u0000"}) { + assertArrayEquals(str.getBytes(), key.decrypt().doFinal(key.encrypt().doFinal(str.getBytes()))); + } + } + + @Test + public void multipleEncryptsAreIdempotent() throws Exception { + byte[] str = "Hello world".getBytes(); + assertArrayEquals(key.encrypt().doFinal(str), key.encrypt().doFinal(str)); + } + + @Test + public void loadingExistingKey() throws Exception { + CryptoConfidentialKey key2 = new CryptoConfidentialKey("test"); // this will cause the key to be loaded from the disk + for (String str : new String[] {"Hello world", "", "\u0000"}) { + assertArrayEquals(str.getBytes(), key2.decrypt().doFinal(key.encrypt().doFinal(str.getBytes()))); + } + } + +}