1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-23 04:42:06 +01:00

Stabilize expiration dates in revocation tests

This commit is contained in:
Paul Schaub 2021-09-06 15:23:10 +02:00
parent e81ee648d8
commit 90e0f74aea
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -15,8 +15,6 @@
*/
package org.pgpainless.key.modification;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
@ -25,6 +23,7 @@ import java.util.List;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.junit.JUtils;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.pgpainless.PGPainless;
@ -34,6 +33,7 @@ import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.modification.secretkeyring.SecretKeyRingEditorInterface;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.util.DateUtil;
public class RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey {
@ -115,7 +115,7 @@ public class RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey {
@MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories")
public void testChangingExpirationTimeWithKeyWithoutPrefAlgos(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
Date expirationDate = new Date();
Date expirationDate = DateUtil.parseUTCDate(DateUtil.formatUTCDate(new Date()));
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
List<OpenPgpV4Fingerprint> fingerprintList = new ArrayList<>();
for (PGPSecretKey secretKey : secretKeys) {
@ -131,9 +131,10 @@ public class RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey {
secretKeys = modify.done();
KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys);
assertEquals(expirationDate.getTime(), info.getPrimaryKeyExpirationDate().getTime(), 1000);
JUtils.assertDateEquals(expirationDate, info.getPrimaryKeyExpirationDate());
for (OpenPgpV4Fingerprint fingerprint : fingerprintList) {
assertEquals(expirationDate.getTime(), info.getSubkeyExpirationDate(fingerprint).getTime(), 1000);
JUtils.assertDateEquals(expirationDate, info.getSubkeyExpirationDate(fingerprint));
}
}
}