Skip to content

Commit

Permalink
Merge pull request #3323 from nscuro/backport-pr-3322
Browse files Browse the repository at this point in the history
Backport: Fix NVD API's last modified timestamp requiring restart to be applied
  • Loading branch information
nscuro authored Dec 18, 2023
2 parents d55746a + 9f01f3c commit 485c982
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ private static boolean updateLastModified(final ZonedDateTime lastModifiedDateTi
}

LOGGER.debug("Latest captured modification date: %s".formatted(lastModifiedDateTime));
try (final var qm = new QueryManager().withL2CacheDisabled()) {
try (final var qm = new QueryManager()) {
qm.runInTransaction(() -> {
final ConfigProperty property = qm.getConfigProperty(
VULNERABILITY_SOURCE_NVD_API_LAST_MODIFIED_EPOCH_SECONDS.getGroupName(),
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/dependencytrack/tasks/NistApiMirrorTaskTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.dependencytrack.tasks;

import alpine.model.ConfigProperty;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import org.dependencytrack.PersistenceCapableTest;
import org.dependencytrack.event.NistApiMirrorEvent;
Expand Down Expand Up @@ -233,6 +234,16 @@ public void testInformWithNewVulnerability() throws Exception {
assertThat(qm.hasAffectedVersionAttribution(vuln, vs, Source.NVD)).isTrue();
}
);

// Property is in L1 cache because it was created in the test's setUp method.
// Evict L1 cache to reach L2 cache / datastore instead.
qm.getPersistenceManager().evictAll();
final ConfigProperty lastModifiedProperty = qm.getConfigProperty(
VULNERABILITY_SOURCE_NVD_API_LAST_MODIFIED_EPOCH_SECONDS.getGroupName(),
VULNERABILITY_SOURCE_NVD_API_LAST_MODIFIED_EPOCH_SECONDS.getPropertyName()
);
assertThat(lastModifiedProperty).isNotNull();
assertThat(lastModifiedProperty.getPropertyValue()).isEqualTo("1691504544");
}

@Test
Expand Down

0 comments on commit 485c982

Please sign in to comment.