1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 22:32:07 +01:00

Add tests for message inspection

This commit is contained in:
Paul Schaub 2021-10-27 15:54:50 +02:00
parent aed06fc832
commit e8bf2ea9e7
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -8,9 +8,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -29,8 +27,7 @@ public class MessageInspectorTest {
"=IICf\n" + "=IICf\n" +
"-----END PGP MESSAGE-----\n"; "-----END PGP MESSAGE-----\n";
MessageInspector.EncryptionInfo info = MessageInspector.determineEncryptionInfoForMessage( MessageInspector.EncryptionInfo info = MessageInspector.determineEncryptionInfoForMessage(message);
new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)));
assertFalse(info.isPassphraseEncrypted()); assertFalse(info.isPassphraseEncrypted());
assertFalse(info.isSignedOnly()); assertFalse(info.isSignedOnly());
@ -55,7 +52,7 @@ public class MessageInspectorTest {
"=z6e0\n" + "=z6e0\n" +
"-----END PGP MESSAGE-----"; "-----END PGP MESSAGE-----";
MessageInspector.EncryptionInfo info = MessageInspector.determineEncryptionInfoForMessage(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8))); MessageInspector.EncryptionInfo info = MessageInspector.determineEncryptionInfoForMessage(message);
assertTrue(info.isEncrypted()); assertTrue(info.isEncrypted());
assertTrue(info.isPassphraseEncrypted()); assertTrue(info.isPassphraseEncrypted());
@ -77,7 +74,7 @@ public class MessageInspectorTest {
"=nt5n\n" + "=nt5n\n" +
"-----END PGP MESSAGE-----"; "-----END PGP MESSAGE-----";
MessageInspector.EncryptionInfo info = MessageInspector.determineEncryptionInfoForMessage(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8))); MessageInspector.EncryptionInfo info = MessageInspector.determineEncryptionInfoForMessage(message);
assertTrue(info.isSignedOnly()); assertTrue(info.isSignedOnly());
@ -100,7 +97,7 @@ public class MessageInspectorTest {
"KK0Ymg5GrsBTEGFm4jb1p+V85PPhsIioX3np/N3fkIfxFguTGZza33/GHy61+DTy\n" + "KK0Ymg5GrsBTEGFm4jb1p+V85PPhsIioX3np/N3fkIfxFguTGZza33/GHy61+DTy\n" +
"=SZU6\n" + "=SZU6\n" +
"-----END PGP MESSAGE-----"; "-----END PGP MESSAGE-----";
MessageInspector.EncryptionInfo info = MessageInspector.determineEncryptionInfoForMessage(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8))); MessageInspector.EncryptionInfo info = MessageInspector.determineEncryptionInfoForMessage(message);
// Message is encrypted, so we cannot determine if it is signed or not. // Message is encrypted, so we cannot determine if it is signed or not.
// It is not signed only // It is not signed only
@ -110,4 +107,39 @@ public class MessageInspectorTest {
assertTrue(info.isPassphraseEncrypted()); assertTrue(info.isPassphraseEncrypted());
assertEquals(1, info.getKeyIds().size()); assertEquals(1, info.getKeyIds().size());
} }
@Test
public void testPlaintextMessage() throws IOException, PGPException {
String message = "-----BEGIN PGP MESSAGE-----\n" +
"Version: PGPainless\n" +
"Comment: Literal Data\n" +
"\n" +
"yyl0CF9DT05TT0xFYXlXgUp1c3Qgc29tZSB1bmVuY3J5cHRlZCBkYXRhLg==\n" +
"=jVNT\n" +
"-----END PGP MESSAGE-----";
MessageInspector.EncryptionInfo info = MessageInspector.determineEncryptionInfoForMessage(message);
assertFalse(info.isEncrypted());
assertFalse(info.isSignedOnly());
assertFalse(info.isPassphraseEncrypted());
assertTrue(info.getKeyIds().isEmpty());
}
@Test
public void testCompressedPlaintextMessage() throws IOException, PGPException {
String message = "-----BEGIN PGP MESSAGE-----\n" +
"Version: PGPainless\n" +
"Comment: Compressed Literal Data\n" +
"\n" +
"owE7HVDCEe/s7xfs7+OaWBmxJDw1L08hIzOvJLVIwS0nMzU9NQ9Op0FoHRgDQ0Fe\n" +
"YnKGHgA=\n" +
"=jw3E\n" +
"-----END PGP MESSAGE-----";
MessageInspector.EncryptionInfo info = MessageInspector.determineEncryptionInfoForMessage(message);
assertFalse(info.isEncrypted());
assertFalse(info.isSignedOnly());
assertFalse(info.isPassphraseEncrypted());
assertTrue(info.getKeyIds().isEmpty());
}
} }