methods = pkr.getAcceptableKeyTypes();
assertEquals("[rsa, dsa]", methods.toString());
}
public void testGetGranularityPattern() {
PublicKeyRecord pkr = new PublicKeyRecordImpl(
"k=rsa; h=sha1:sha256; p=XXXXXXXX=;");
pkr.validate();
Pattern pattern = pkr.getGranularityPattern();
assertEquals("^\\Q\\E.*\\Q\\E$", pattern.pattern());
assertTrue(pattern.matcher("something").matches());
assertTrue(pattern.matcher("").matches());
pkr = new PublicKeyRecordImpl("k=rsa; g=; h=sha1:sha256; p=XXXXXXXX=;");
pkr.validate();
pattern = pkr.getGranularityPattern();
assertEquals("@", pattern.pattern());
assertFalse(pattern.matcher("something").matches());
assertFalse(pattern.matcher("").matches());
pkr = new PublicKeyRecordImpl(
"k=rsa; g=some*; h=sha1:sha256; p=XXXXXXXX=;");
pkr.validate();
pattern = pkr.getGranularityPattern();
assertTrue(pattern.matcher("something").matches());
assertTrue(pattern.matcher("some").matches());
assertFalse(pattern.matcher("som").matches());
assertFalse(pattern.matcher("awesome").matches());
assertEquals("^\\Qsome\\E.*\\Q\\E$", pattern.pattern());
pkr = new PublicKeyRecordImpl(
"k=rsa; g=*+test; h=sha1:sha256; p=XXXXXXXX=;");
pkr.validate();
pattern = pkr.getGranularityPattern();
assertEquals("^\\Q\\E.*\\Q+test\\E$", pattern.pattern());
assertTrue(pattern.matcher("a+test").matches());
assertTrue(pattern.matcher("+test").matches());
assertFalse(pattern.matcher("atest").matches());
assertFalse(pattern.matcher("+tested").matches());
pkr = new PublicKeyRecordImpl(
"k=rsa; g=test; h=sha1:sha256; p=XXXXXXXX=;");
pkr.validate();
pattern = pkr.getGranularityPattern();
assertEquals("^\\Qtest\\E$", pattern.pattern());
assertTrue(pattern.matcher("test").matches());
assertFalse(pattern.matcher("atest").matches());
assertFalse(pattern.matcher("testa").matches());
try {
pkr = new PublicKeyRecordImpl(
"k=rsa; g=*\\+test; h=sha1:sha256; p=XXXXXXXX=;");
pkr.validate();
pattern = pkr.getGranularityPattern();
fail("Expected syntax error");
} catch (IllegalStateException e) {
}
try {
pkr = new PublicKeyRecordImpl(
"k=rsa; g=*test*; h=sha1:sha256; p=XXXXXXXX=;");
pkr.validate();
pattern = pkr.getGranularityPattern();
fail("Expected syntax error");
} catch (IllegalStateException e) {
}
}