未验证 提交 27c83f9c 编写于 作者: J Jesse Glick

CryptoConfidentialKeyTest

上级 5b0cca77
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
}
}
}
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())));
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册