Skip to content
Snippets Groups Projects
Unverified Commit dfd716e1 authored by Jérôme Charaoui's avatar Jérôme Charaoui
Browse files

d/patches: drop patch merged upstream

parent 7db50b64
No related branches found
No related tags found
No related merge requests found
From: Paul Schaub <vanitasvitae@fsfe.org>
Date: Fri, 4 Nov 2022 09:04:54 -0400
Subject: Increase timeframe for some tests which check expiration dates
Cherry-picked patch from v1.3.8 to fix armel tests.
Forwarded: not-needed
---
.../GenerateKeyWithAdditionalUserIdTest.java | 10 ++++----
.../generation/GenerateKeyWithoutUserIdTest.java | 24 ++++++++++++++-----
.../timeframe/TestTimeFrameProvider.java | 28 ++++++++++++++++++++++
.../org/pgpainless/timeframe/package-info.java | 8 +++++++
4 files changed, 60 insertions(+), 10 deletions(-)
create mode 100644 pgpainless-core/src/test/java/org/pgpainless/timeframe/TestTimeFrameProvider.java
create mode 100644 pgpainless-core/src/test/java/org/pgpainless/timeframe/package-info.java
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java
index b05dbe1..2e2ffc8 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java
@@ -25,7 +25,7 @@ import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.rsa.RsaLength;
import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.key.util.UserId;
-import org.pgpainless.util.DateUtil;
+import org.pgpainless.timeframe.TestTimeFrameProvider;
import org.pgpainless.util.TestAllImplementations;
public class GenerateKeyWithAdditionalUserIdTest {
@@ -33,11 +33,13 @@ public class GenerateKeyWithAdditionalUserIdTest {
@TestTemplate
@ExtendWith(TestAllImplementations.class)
public void test() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
- Date expiration = new Date(DateUtil.now().getTime() + 60 * 1000);
+ Date now = new Date();
+ Date expiration = TestTimeFrameProvider.defaultExpirationForCreationDate(now);
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder(
KeyType.RSA(RsaLength._3072),
- KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS))
+ KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS)
+ .setKeyCreationDate(now))
.addUserId(UserId.onlyEmail("primary@user.id"))
.addUserId(UserId.onlyEmail("additional@user.id"))
.addUserId(UserId.onlyEmail("additional2@user.id"))
@@ -46,7 +48,7 @@ public class GenerateKeyWithAdditionalUserIdTest {
.build();
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
- JUtils.assertEquals(expiration.getTime(), PGPainless.inspectKeyRing(publicKeys).getPrimaryKeyExpirationDate().getTime(), 2000);
+ JUtils.assertDateEquals(expiration, PGPainless.inspectKeyRing(publicKeys).getPrimaryKeyExpirationDate());
Iterator<String> userIds = publicKeys.getPublicKey().getUserIDs();
assertEquals("primary@user.id", userIds.next());
diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithoutUserIdTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithoutUserIdTest.java
index 8b022a2..24484cd 100644
--- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithoutUserIdTest.java
+++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithoutUserIdTest.java
@@ -15,6 +15,7 @@ import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.decryption_verification.ConsumerOptions;
import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.decryption_verification.OpenPgpMetadata;
+import org.pgpainless.decryption_verification.SignatureVerification;
import org.pgpainless.encryption_signing.EncryptionOptions;
import org.pgpainless.encryption_signing.EncryptionResult;
import org.pgpainless.encryption_signing.EncryptionStream;
@@ -25,7 +26,7 @@ import org.pgpainless.key.generation.type.eddsa.EdDSACurve;
import org.pgpainless.key.generation.type.xdh.XDHSpec;
import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.protection.SecretKeyRingProtector;
-import org.pgpainless.util.DateUtil;
+import org.pgpainless.timeframe.TestTimeFrameProvider;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -34,6 +35,7 @@ import java.io.InputStream;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
+import java.util.List;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -42,11 +44,12 @@ public class GenerateKeyWithoutUserIdTest {
@Test
public void generateKeyWithoutUserId() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException {
- Date expirationDate = DateUtil.toSecondsPrecision(new Date(DateUtil.now().getTime() + 1000 * 6000));
+ Date now = new Date();
+ Date expirationDate = TestTimeFrameProvider.defaultExpirationForCreationDate(now);
PGPSecretKeyRing secretKey = PGPainless.buildKeyRing()
- .setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.CERTIFY_OTHER))
- .addSubkey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.SIGN_DATA))
- .addSubkey(KeySpec.getBuilder(KeyType.XDH(XDHSpec._X25519), KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE))
+ .setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.CERTIFY_OTHER).setKeyCreationDate(now))
+ .addSubkey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.SIGN_DATA).setKeyCreationDate(now))
+ .addSubkey(KeySpec.getBuilder(KeyType.XDH(XDHSpec._X25519), KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE).setKeyCreationDate(now))
.setExpirationDate(expirationDate)
.build();
@@ -87,7 +90,16 @@ public class GenerateKeyWithoutUserIdTest {
OpenPgpMetadata metadata = decryptionStream.getResult();
- assertTrue(metadata.containsVerifiedSignatureFrom(certificate));
+ assertTrue(metadata.containsVerifiedSignatureFrom(certificate),
+ failuresToString(metadata.getInvalidInbandSignatures()));
assertTrue(metadata.isEncrypted());
}
+
+ private static String failuresToString(List<SignatureVerification.Failure> failureList) {
+ StringBuilder sb = new StringBuilder();
+ for (SignatureVerification.Failure failure : failureList) {
+ sb.append(failure.toString()).append('\n');
+ }
+ return sb.toString();
+ }
}
diff --git a/pgpainless-core/src/test/java/org/pgpainless/timeframe/TestTimeFrameProvider.java b/pgpainless-core/src/test/java/org/pgpainless/timeframe/TestTimeFrameProvider.java
new file mode 100644
index 0000000..9d32a40
--- /dev/null
+++ b/pgpainless-core/src/test/java/org/pgpainless/timeframe/TestTimeFrameProvider.java
@@ -0,0 +1,28 @@
+// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
+//
+// SPDX-License-Identifier: Apache-2.0
+
+package org.pgpainless.timeframe;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
+public class TestTimeFrameProvider {
+
+ /**
+ * Return an expiration date which is 7h 13m and 31s from the given date.
+ *
+ * @param now t0
+ * @return t1 which is t0 +7h13m31s
+ */
+ public static Date defaultExpirationForCreationDate(Date now) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
+ calendar.setTime(now);
+ calendar.add(Calendar.HOUR, 7);
+ calendar.add(Calendar.MINUTE, 13);
+ calendar.add(Calendar.SECOND, 31);
+ return calendar.getTime();
+ }
+}
diff --git a/pgpainless-core/src/test/java/org/pgpainless/timeframe/package-info.java b/pgpainless-core/src/test/java/org/pgpainless/timeframe/package-info.java
new file mode 100644
index 0000000..dfada70
--- /dev/null
+++ b/pgpainless-core/src/test/java/org/pgpainless/timeframe/package-info.java
@@ -0,0 +1,8 @@
+// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
+//
+// SPDX-License-Identifier: Apache-2.0
+
+/**
+ * Test classes for timeframes.
+ */
+package org.pgpainless.timeframe;
......@@ -9,4 +9,3 @@
0009-fix-application-plugin-config.patch
0010-fix-maven-plugin-config.patch
0011-remove-mockito-based-tests.patch
0012-Increase-timeframe-for-some-tests-which-check-expira.patch
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment