未验证 提交 1cad7b5f 编写于 作者: J Jesse Glick

HMACConfidentialKeyTest

上级 e094f01e
package jenkins.security
import org.junit.Rule
import org.junit.Test
/**
*
*
* @author Kohsuke Kawaguchi
*/
class HMACConfidentialKeyTest {
@Rule
public ConfidentialStoreRule store = new ConfidentialStoreRule()
def key = new HMACConfidentialKey("test",16)
@Test
void basics() {
def unique = [] as TreeSet
["Hello world","","\u0000"].each { str ->
def mac = key.mac(str)
unique.add(mac)
assert mac =~ /[0-9A-Fa-f]{32}/
assert key.checkMac(str,mac)
assert !key.checkMac("garbage",mac)
}
assert unique.size()==3 // make sure all 3 MAC are different
}
@Test
void loadingExistingKey() {
// this second key of the same ID will cause it to load the key from the disk
def key2 = new HMACConfidentialKey("test",16)
["Hello world","","\u0000"].each { str ->
assert key.mac(str)==key2.mac(str)
}
}
}
package jenkins.security;
import java.util.Set;
import java.util.TreeSet;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.Test;
public class HMACConfidentialKeyTest {
@Rule
public ConfidentialStoreRule store = new ConfidentialStoreRule();
private HMACConfidentialKey key = new HMACConfidentialKey("test", 16);
@Test
public void basics() {
Set<String> unique = new TreeSet<>();
for (String str : new String[] {"Hello world", "", "\u0000"}) {
String mac = key.mac(str);
unique.add(mac);
assertTrue(mac, mac.matches("[0-9A-Fa-f]{32}"));
assertTrue(key.checkMac(str, mac));
assertFalse(key.checkMac("garbage", mac));
}
assertEquals("all 3 MAC are different", 3, unique.size());
}
@Test
public void loadingExistingKey() {
// this second key of the same ID will cause it to load the key from the disk
HMACConfidentialKey key2 = new HMACConfidentialKey("test", 16);
for (String str : new String[] {"Hello world", "", "\u0000"}) {
assertEquals(key.mac(str), key2.mac(str));
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册