1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 06:12:06 +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.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Date;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing; 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.DecryptionStream;
import org.pgpainless.decryption_verification.MessageMetadata; import org.pgpainless.decryption_verification.MessageMetadata;
import org.pgpainless.exception.KeyException; import org.pgpainless.exception.KeyException;
import org.pgpainless.util.DateUtil;
public class EncryptionWithMissingKeyFlagsTest { public class EncryptionWithMissingKeyFlagsTest {
@ -135,6 +137,8 @@ public class EncryptionWithMissingKeyFlagsTest {
"=TKhx\n" + "=TKhx\n" +
"-----END PGP PRIVATE KEY BLOCK-----"; "-----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"; private static final String MESSAGE = "Hello, World!\n";
@Test @Test
@ -145,7 +149,9 @@ public class EncryptionWithMissingKeyFlagsTest {
PGPPublicKeyRing publicKeys = PGPainless.extractCertificate(secretKeys); PGPPublicKeyRing publicKeys = PGPainless.extractCertificate(secretKeys);
assertThrows(KeyException.UnacceptableEncryptionKeyException.class, () -> 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() EncryptionStream encOut = PGPainless.encryptAndOrSign()
.onOutputStream(out) .onOutputStream(out)
.withOptions(ProducerOptions.encrypt(EncryptionOptions.get() .withOptions(ProducerOptions.encrypt(EncryptionOptions.get()
.setEvaluationDate(evaluationDate)
.setAllowEncryptionWithMissingKeyFlags() // Workaround .setAllowEncryptionWithMissingKeyFlags() // Workaround
.addRecipient(publicKeys))); .addRecipient(publicKeys)));