Skip to content

Commit

Permalink
Use java 17 for SonarCloud
Browse files Browse the repository at this point in the history
WE2-841

Signed-off-by: Raul Metsma <raul@metsma.ee>
  • Loading branch information
metsma authored and mrts committed Feb 16, 2024
1 parent c919aa5 commit 64f05aa
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/sonarcloud-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11
java-version: 17
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
Expand All @@ -28,7 +28,7 @@ jobs:
with:
path: ~/.m2
key: ${{ runner.os }}-m2-v11-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2-v11
restore-keys: ${{ runner.os }}-m2-v17
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<maven-source-plugin.version>3.3.0</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.6.2</maven-javadoc-plugin.version>
<jacoco.version>0.8.5</jacoco.version>
<jacoco.version>0.8.8</jacoco.version>
<sonar.coverage.jacoco.xmlReportPaths>
${project.basedir}/../jacoco-coverage-report/target/site/jacoco-aggregate/jacoco.xml
</sonar.coverage.jacoco.xmlReportPaths>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/eu/webeid/security/util/DateAndTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public static void requirePositiveDuration(Duration duration, String fieldName)

public static class DefaultClock implements Clock {

public static final Clock INSTANCE = new DefaultClock();
protected static Clock instance = new DefaultClock();

public static Clock getInstance() {
return instance;
}

@Override
public Date now() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public SubjectCertificateExpiryValidator(Set<TrustAnchor> trustedCACertificateAn
*/
public void validateCertificateExpiry(X509Certificate subjectCertificate) throws AuthTokenException {
// Use the clock instance so that the date can be mocked in tests.
final Date now = DateAndTime.DefaultClock.INSTANCE.now();
final Date now = DateAndTime.DefaultClock.getInstance().now();
CertificateValidator.trustedCACertificatesAreValidOnDate(trustedCACertificateAnchors, now);
LOG.debug("CA certificates are valid.");
CertificateValidator.certificateIsValidOnDate(subjectCertificate, now, "User");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public SubjectCertificateTrustedValidator(Set<TrustAnchor> trustedCACertificateA
*/
public void validateCertificateTrusted(X509Certificate subjectCertificate) throws AuthTokenException {
// Use the clock instance so that the date can be mocked in tests.
final Date now = DateAndTime.DefaultClock.INSTANCE.now();
final Date now = DateAndTime.DefaultClock.getInstance().now();
subjectCertificateIssuerCertificate = CertificateValidator.validateIsSignedByTrustedCA(
subjectCertificate,
trustedCACertificateAnchors,
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/eu/webeid/security/testutil/Dates.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,18 @@ public static void resetMockedCertificateValidatorDate() throws NoSuchFieldExcep
}

private static void setClockField(Class<? extends Clock> cls, Date date) throws NoSuchFieldException, IllegalAccessException {
final Field clockField = cls.getDeclaredField("INSTANCE");
final Field clockField = cls.getDeclaredField("instance");
setFinalStaticField(clockField, (Clock) () -> date);
}

private static void setFinalStaticField(Field field, Object newValue) throws NoSuchFieldException, IllegalAccessException {
field.setAccessible(true);

/* https://stackoverflow.com/questions/56039341/get-declared-fields-of-java-lang-reflect-fields-in-jdk12
final Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
*/

field.set(null, newValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ void whenOcspUrlIsInvalid_thenThrows() throws Exception {

@Test
void whenOcspRequestFails_thenThrows() throws Exception {
final OcspServiceProvider ocspServiceProvider = getDesignatedOcspServiceProvider("https://web-eid-test.free.beeceptor.com");
final OcspServiceProvider ocspServiceProvider = getDesignatedOcspServiceProvider("http://demo.sk.ee/ocsps");
final SubjectCertificateNotRevokedValidator validator = new SubjectCertificateNotRevokedValidator(trustedValidator, ocspClient, ocspServiceProvider);
assertThatCode(() ->
validator.validateCertificateNotRevoked(estEid2018Cert))
.isInstanceOf(UserCertificateOCSPCheckFailedException.class)
.cause()
.isInstanceOf(IOException.class)
.hasMessageStartingWith("OCSP request was not successful, response: (POST https://web-eid-test.free.beeceptor.com) 404");
.hasMessageStartingWith("OCSP request was not successful, response: (POST http://demo.sk.ee/ocsps) 404");
}

@Test
Expand Down

0 comments on commit 64f05aa

Please sign in to comment.