1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-22 19:08:00 +01:00

Override evaluation date in test with expiring key

This commit is contained in:
Paul Schaub 2023-08-03 14:51:43 +02:00
parent f0e59ecef5
commit 16a4836f8a
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -12,6 +12,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
@ -23,6 +24,7 @@ import org.pgpainless.decryption_verification.ConsumerOptions;
import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.decryption_verification.MessageMetadata;
import org.pgpainless.exception.KeyException;
import org.pgpainless.util.DateUtil;
public class EncryptionWithMissingKeyFlagsTest {
@ -135,6 +137,8 @@ public class EncryptionWithMissingKeyFlagsTest {
"=TKhx\n" +
"-----END PGP PRIVATE KEY BLOCK-----";
// Above key expires in 5 years, so we fix the evaluation date to a known-good value
private static final Date evaluationDate = DateUtil.parseUTCDate("2023-08-03 12:50:06 UTC");
private static final String MESSAGE = "Hello, World!\n";
@Test
@ -145,7 +149,9 @@ public class EncryptionWithMissingKeyFlagsTest {
PGPPublicKeyRing publicKeys = PGPainless.extractCertificate(secretKeys);
assertThrows(KeyException.UnacceptableEncryptionKeyException.class, () ->
EncryptionOptions.get().addRecipient(publicKeys));
EncryptionOptions.get()
.setEvaluationDate(evaluationDate)
.addRecipient(publicKeys));
}
@ -161,6 +167,7 @@ public class EncryptionWithMissingKeyFlagsTest {
EncryptionStream encOut = PGPainless.encryptAndOrSign()
.onOutputStream(out)
.withOptions(ProducerOptions.encrypt(EncryptionOptions.get()
.setEvaluationDate(evaluationDate)
.setAllowEncryptionWithMissingKeyFlags() // Workaround
.addRecipient(publicKeys)));