Skip to content

Commit 269218f

Browse files
committed
fix(tests): mock the right date in X5cTest
Signed-off-by: Mart Somermaa <mrts@users.noreply.github.com>
1 parent 94f6565 commit 269218f

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/test/java/org/webeid/security/validator/X5cTest.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020 The Web eID Project
2+
* Copyright (c) 2020, 2021 The Web eID Project
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -22,17 +22,23 @@
2222

2323
package org.webeid.security.validator;
2424

25+
import org.junit.jupiter.api.AfterEach;
2526
import org.junit.jupiter.api.BeforeEach;
2627
import org.junit.jupiter.api.Test;
27-
import org.webeid.security.exceptions.*;
28+
import org.webeid.security.exceptions.TokenParseException;
29+
import org.webeid.security.exceptions.TokenSignatureValidationException;
30+
import org.webeid.security.exceptions.UserCertificateDisallowedPolicyException;
31+
import org.webeid.security.exceptions.UserCertificateMissingPurposeException;
32+
import org.webeid.security.exceptions.UserCertificateWrongPurposeException;
2833
import org.webeid.security.testutil.AbstractTestWithValidatorAndCorrectNonce;
2934
import org.webeid.security.testutil.Dates;
3035
import org.webeid.security.testutil.Tokens;
3136

3237
import java.text.ParseException;
3338

3439
import static org.assertj.core.api.Assertions.assertThatThrownBy;
35-
import static org.webeid.security.testutil.Dates.setMockedDefaultJwtParserDate;
40+
import static org.webeid.security.testutil.Dates.resetMockedFunctionalSubjectCertificateValidatorsDate;
41+
import static org.webeid.security.testutil.Dates.setMockedFunctionalSubjectCertificateValidatorsDate;
3642

3743
class X5cTest extends AbstractTestWithValidatorAndCorrectNonce {
3844

@@ -41,13 +47,24 @@ class X5cTest extends AbstractTestWithValidatorAndCorrectNonce {
4147
protected void setup() {
4248
super.setup();
4349
try {
44-
// Ensure that certificate is valid
45-
setMockedDefaultJwtParserDate(Dates.create("2020-09-25"));
50+
// Ensure that the certificates do not expire.
51+
setMockedFunctionalSubjectCertificateValidatorsDate(Dates.create("2021-01-01"));
4652
} catch (ParseException | NoSuchFieldException | IllegalAccessException e) {
4753
throw new RuntimeException(e);
4854
}
4955
}
5056

57+
@Override
58+
@AfterEach
59+
public void tearDown() {
60+
super.tearDown();
61+
try {
62+
resetMockedFunctionalSubjectCertificateValidatorsDate();
63+
} catch (NoSuchFieldException | IllegalAccessException e) {
64+
throw new RuntimeException(e);
65+
}
66+
}
67+
5168
@Test
5269
void testX5cMissing() {
5370
assertThatThrownBy(() -> validator.validate(Tokens.X5C_MISSING))

0 commit comments

Comments
 (0)