mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-23 04:42:06 +01:00
Add test for SignatureUtils.getSignaturesForUserIdBy()
This commit is contained in:
parent
1a37058c66
commit
3a9bfd57ac
1 changed files with 55 additions and 0 deletions
|
@ -10,8 +10,11 @@ import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
|
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||||
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSignature;
|
import org.bouncycastle.openpgp.PGPSignature;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.pgpainless.PGPainless;
|
||||||
|
|
||||||
public class SignatureUtilsTest {
|
public class SignatureUtilsTest {
|
||||||
|
|
||||||
|
@ -83,4 +86,56 @@ public class SignatureUtilsTest {
|
||||||
List<PGPSignature> signatures = SignatureUtils.readSignatures(sigs);
|
List<PGPSignature> signatures = SignatureUtils.readSignatures(sigs);
|
||||||
assertEquals(1, signatures.size()); // first sig gets skipped
|
assertEquals(1, signatures.size()); // first sig gets skipped
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetSignaturesOverUserIdBy() throws IOException {
|
||||||
|
String alice = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
|
||||||
|
"Version: PGPainless\n" +
|
||||||
|
"Comment: 9CA2 8D6D DBA6 BCF1 23A4 2775 0EB5 08CD 1714 B46A\n" +
|
||||||
|
"Comment: Alice <alice@exmaple.com>\n" +
|
||||||
|
"Comment: 1 further identity\n" +
|
||||||
|
"\n" +
|
||||||
|
"mDMEYoPLwhYJKwYBBAHaRw8BAQdAnuduN87Gu2qvsfdRxLP83strq+doPNP8Hx2J\n" +
|
||||||
|
"esvaN0+0GUFsaWNlIDxhbGljZUBleG1hcGxlLmNvb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AO1Wc2gnlXavk2a+0DpyI1QQYFgoAfQUCYoPLwgKeAQKbAgUWAgMBAAQL\n" +
|
||||||
|
"CQgHBRUKCQgLXyAEGRYKAAYFAmKDy8IACgkQchAyuqB7Hn2yOAD/cPA01NO5YJPg\n" +
|
||||||
|
"KUuSDLnk872y+e419bvFizrM4LKYbeoA/0aw12mcpi1smQJ3mm9T/oGidatBQJ74\n" +
|
||||||
|
"JIPqTtwHSTIHAAoJEA61CM0XFLRqzj4A+QGjS6ay2AioirHJ9SCA8Eq6L2f/N3RB\n" +
|
||||||
|
"YBOlV32f3zxyAP9fwXlz0hRbBDnnie2O5eXT9ZurnAKGXPwCtlsqrmeTBg==\n" +
|
||||||
|
"=uC3F\n" +
|
||||||
|
"-----END PGP PUBLIC KEY BLOCK-----\n";
|
||||||
|
|
||||||
|
String aliceId = "Alice <alice@exmaple.com>";
|
||||||
|
String charliesPetNameForAlice = "Alice Example <alice@example.com> [from work]";
|
||||||
|
|
||||||
|
long aliceKeyId = 1059762964264170602L;
|
||||||
|
long bobKeyId = 5610053632031231169L;
|
||||||
|
long charlieKeyId = -5325245004225622857L;
|
||||||
|
|
||||||
|
PGPPublicKeyRing aliceCert = PGPainless.readKeyRing().publicKeyRing(alice);
|
||||||
|
PGPPublicKey aliceKey = aliceCert.getPublicKey();
|
||||||
|
|
||||||
|
// alice self-signed her user-id
|
||||||
|
assertEquals(1, SignatureUtils.getSignaturesOverUserIdBy(aliceKey, aliceId, aliceKeyId).size());
|
||||||
|
// Bob signed alices user-id
|
||||||
|
assertEquals(1, SignatureUtils.getSignaturesOverUserIdBy(aliceKey, aliceId, bobKeyId).size());
|
||||||
|
// charlie gave alice a pet name
|
||||||
|
assertEquals(1, SignatureUtils.getSignaturesOverUserIdBy(aliceKey, charliesPetNameForAlice, charlieKeyId).size());
|
||||||
|
|
||||||
|
// Alice did not certify the petname charlie gave her
|
||||||
|
assertEquals(0, SignatureUtils.getSignaturesOverUserIdBy(aliceKey, charliesPetNameForAlice, aliceKeyId).size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue