From 3b2fdf883cedbc37ac46cd9dbf367aa893c0d849 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 16:49:59 +0200 Subject: [PATCH] Update dependency org.sonatype.gradle.plugins.scan to v2.8.2 {patch} (#985) * Update dependency org.sonatype.gradle.plugins.scan to v2.8.2 {patch} Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Fixes flaky tests {patch} Signed-off-by: Esta Nagy --------- Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Esta Nagy Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Esta Nagy --- gradle/libs.versions.toml | 2 +- gradle/verification-metadata.xml | 39 +++++++++++++++ .../impl/VaultFakeImplIntegrationTest.java | 47 ++++++++++++++----- 3 files changed, 75 insertions(+), 13 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 02c2ac89..6150d5c7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -26,7 +26,7 @@ openApiUi = "2.5.0" abortMissionPlugin = "5.0.34" dockerPlugin = "0.36.0" -indexScanPlugin = "2.8.1" +indexScanPlugin = "2.8.2" lombokPlugin = "8.6" springBootPlugin = "3.2.5" gitVersionerPlugin = "1.6.7" diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index cf3e6869..fb074595 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -18,6 +18,14 @@ + + + + + + + + @@ -90,6 +98,14 @@ + + + + + + + + @@ -159,6 +175,11 @@ + + + + + @@ -1923,6 +1944,14 @@ + + + + + + + + @@ -5749,6 +5778,11 @@ + + + + + @@ -5769,6 +5803,11 @@ + + + + + diff --git a/lowkey-vault-app/src/test/java/com/github/nagyesta/lowkeyvault/service/vault/impl/VaultFakeImplIntegrationTest.java b/lowkey-vault-app/src/test/java/com/github/nagyesta/lowkeyvault/service/vault/impl/VaultFakeImplIntegrationTest.java index 1f7d6175..e164805b 100644 --- a/lowkey-vault-app/src/test/java/com/github/nagyesta/lowkeyvault/service/vault/impl/VaultFakeImplIntegrationTest.java +++ b/lowkey-vault-app/src/test/java/com/github/nagyesta/lowkeyvault/service/vault/impl/VaultFakeImplIntegrationTest.java @@ -12,13 +12,14 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.time.Instant; +import java.time.Month; import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.util.Deque; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; import static com.github.nagyesta.lowkeyvault.TestConstantsCertificates.CERT_NAME_1; import static com.github.nagyesta.lowkeyvault.TestConstantsUri.HTTPS_LOCALHOST; @@ -30,9 +31,11 @@ class VaultFakeImplIntegrationTest { - private static final int INT_800 = 800; + private static final int INITIAL_OFFSET_IN_DAYS = 800; + private static final int EXTRA_OFFSET_IN_DAYS = 15; + private static final int INT_MORE_THAN_TWO_YEARS_IN_DAYS = getMoreThanTwoYearsAvoidingLeapYear(); private static final int SECONDS_IN_1_DAY = 24 * 3600; - private static final int SECONDS_IN_800_DAYS = INT_800 * SECONDS_IN_1_DAY; + private static final int SECONDS_IN_MORE_THAN_TWO_YEARS = INT_MORE_THAN_TWO_YEARS_IN_DAYS * SECONDS_IN_1_DAY; public static final int EXPECTED_VERSIONS_AFTER_RENEWAL = 3; @Test @@ -58,19 +61,19 @@ void testTimeShiftShouldCreateNewVersionsWhenAutoRotateIsTriggeredWithActiveCert )); //when - underTest.timeShift(SECONDS_IN_800_DAYS, true); + underTest.timeShift(SECONDS_IN_MORE_THAN_TWO_YEARS, true); //then final Deque versions = underTest.certificateVaultFake().getEntities().getVersions(originalCertId); final List entities = versions.stream() .map(v -> new VersionedCertificateEntityId(originalCertId.vault(), originalCertId.id(), v)) .map(certificateVaultFake.getEntities()::getReadOnlyEntity) - .collect(Collectors.toList()); + .toList(); Assertions.assertEquals(EXPECTED_VERSIONS_AFTER_RENEWAL, entities.size()); final ReadOnlyKeyVaultCertificateEntity recreatedOriginal = entities.get(0); final ReadOnlyKeyVaultCertificateEntity firstRenewal = entities.get(1); final ReadOnlyKeyVaultCertificateEntity secondRenewal = entities.get(2); - assertTimestampsAreAdjustedAsExpected(approxNow, recreatedOriginal, INT_800); + assertTimestampsAreAdjustedAsExpected(approxNow, recreatedOriginal, INT_MORE_THAN_TWO_YEARS_IN_DAYS); final OffsetDateTime firstRenewalDay = recreatedOriginal.getExpiry().map(v -> v.minusDays(triggerThresholdDays)).orElseThrow(); assertTimestampsAreAdjustedAsExpected(approxNow, firstRenewal, DAYS.between(firstRenewalDay, approxNow)); final OffsetDateTime secondRenewalDay = firstRenewal.getExpiry().map(v -> v.minusDays(triggerThresholdDays)).orElseThrow(); @@ -106,14 +109,14 @@ void testTimeShiftShouldCreateNewVersionsWhenAutoRotateIsTriggeredWithDifferentC issuancePolicy.setContentType(CertContentType.PEM); //when - underTest.timeShift(SECONDS_IN_800_DAYS, true); + underTest.timeShift(SECONDS_IN_MORE_THAN_TWO_YEARS, true); //then final Deque versions = underTest.certificateVaultFake().getEntities().getVersions(originalCertId); final List entities = versions.stream() .map(v -> new VersionedCertificateEntityId(originalCertId.vault(), originalCertId.id(), v)) .map(certificateVaultFake.getEntities()::getReadOnlyEntity) - .collect(Collectors.toList()); + .toList(); Assertions.assertEquals(EXPECTED_VERSIONS_AFTER_RENEWAL, entities.size()); assertRenewalUsedPem(underTest, entities.get(1)); assertRenewalUsedPem(underTest, entities.get(2)); @@ -143,19 +146,19 @@ void testTimeShiftShouldCreateNewVersionsUsingSameKeyWhenAutoRotateIsTriggeredWi )); //when - underTest.timeShift(SECONDS_IN_800_DAYS, true); + underTest.timeShift(SECONDS_IN_MORE_THAN_TWO_YEARS, true); //then final Deque versions = underTest.certificateVaultFake().getEntities().getVersions(originalCertId); final List entities = versions.stream() .map(v -> new VersionedCertificateEntityId(originalCertId.vault(), originalCertId.id(), v)) .map(certificateVaultFake.getEntities()::getReadOnlyEntity) - .collect(Collectors.toList()); + .toList(); Assertions.assertEquals(EXPECTED_VERSIONS_AFTER_RENEWAL, entities.size()); final ReadOnlyKeyVaultCertificateEntity recreatedOriginal = entities.get(0); final ReadOnlyKeyVaultCertificateEntity firstRenewal = entities.get(1); final ReadOnlyKeyVaultCertificateEntity secondRenewal = entities.get(2); - assertTimestampsAreAdjustedAsExpected(approxNow, recreatedOriginal, INT_800); + assertTimestampsAreAdjustedAsExpected(approxNow, recreatedOriginal, INT_MORE_THAN_TWO_YEARS_IN_DAYS); final OffsetDateTime firstRenewalDay = recreatedOriginal.getExpiry().map(v -> v.minusDays(triggerThresholdDays)).orElseThrow(); assertTimestampsAreAdjustedAsExpected(approxNow, firstRenewal, DAYS.between(firstRenewalDay, approxNow)); final OffsetDateTime secondRenewalDay = firstRenewal.getExpiry().map(v -> v.minusDays(triggerThresholdDays)).orElseThrow(); @@ -189,7 +192,7 @@ void testTimeShiftShouldNotCreateNewVersionsWhenAutoRotateIsTriggeredWithDeleted certificateVaultFake.delete(originalCertId); //when - underTest.timeShift(SECONDS_IN_800_DAYS, true); + underTest.timeShift(SECONDS_IN_MORE_THAN_TWO_YEARS, true); //then final boolean exists = underTest.certificateVaultFake().getDeletedEntities().containsName(originalCertId.id()); @@ -244,4 +247,24 @@ private static void assertTimestampsAreAdjustedAsExpected( Assertions.assertEquals(DEFAULT_VALIDITY_MONTHS, MONTHS .between(recreatedOriginal.getNotBefore().orElseThrow(), recreatedOriginal.getExpiry().orElseThrow())); } + + private static int getMoreThanTwoYearsAvoidingLeapYear() { + final Instant moreThanTwoYearsAgo = Instant.now().minus(INITIAL_OFFSET_IN_DAYS, DAYS); + if (isEndOfFebruary(moreThanTwoYearsAgo) || isBeginningOfMarch(moreThanTwoYearsAgo)) { + return INITIAL_OFFSET_IN_DAYS + EXTRA_OFFSET_IN_DAYS; + } + return INITIAL_OFFSET_IN_DAYS; + } + + @SuppressWarnings("checkstyle:MagicNumber") + private static boolean isBeginningOfMarch(final Instant instant) { + return instant.atOffset(ZoneOffset.UTC).getMonth() == Month.MARCH + && instant.atOffset(ZoneOffset.UTC).getDayOfMonth() < 5; + } + + @SuppressWarnings("checkstyle:MagicNumber") + private static boolean isEndOfFebruary(final Instant instant) { + return instant.atOffset(ZoneOffset.UTC).getMonth() == Month.FEBRUARY + && instant.atOffset(ZoneOffset.UTC).getDayOfMonth() > 27; + } }