-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #359 from DependencyTrack/integrity-check-mop-up
- Loading branch information
Showing
4 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,6 +224,56 @@ public void processUpdateIntegrityResultTest() { | |
assertThat(analysis.getComponent().getPurl().toString()).isEqualTo("pkg:maven/foo/[email protected]"); | ||
} | ||
|
||
@Test | ||
public void testIntegrityCheckWhenComponentHashIsMissing() { | ||
// Create an active project with one component. | ||
final var projectA = qm.createProject("acme-app-a", null, "1.0.0", null, null, null, true, false); | ||
final var componentProjectA = new Component(); | ||
UUID uuid = UUID.randomUUID(); | ||
componentProjectA.setProject(projectA); | ||
componentProjectA.setName("acme-lib-a"); | ||
componentProjectA.setVersion("1.0.1"); | ||
componentProjectA.setPurl("pkg:maven/foo/[email protected]"); | ||
componentProjectA.setPurlCoordinates("pkg:maven/foo/[email protected]"); | ||
componentProjectA.setUuid(uuid); | ||
componentProjectA.setMd5("098f6bcd4621d373cade4e832627b4f6"); | ||
componentProjectA.setSha1("a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"); | ||
|
||
Component c = qm.persist(componentProjectA); | ||
|
||
var integrityMetaComponent = new IntegrityMetaComponent(); | ||
integrityMetaComponent.setPurl("pkg:maven/foo/[email protected]"); | ||
integrityMetaComponent.setStatus(FetchStatus.IN_PROGRESS); | ||
Date date = Date.from(Instant.now().minus(15, ChronoUnit.MINUTES)); | ||
integrityMetaComponent.setLastFetch(date); | ||
qm.persist(integrityMetaComponent); | ||
|
||
final var result = AnalysisResult.newBuilder() | ||
.setComponent(org.hyades.proto.repometaanalysis.v1.Component.newBuilder() | ||
.setUuid(c.getUuid().toString()) | ||
.setPurl("pkg:maven/foo/[email protected]")) | ||
.setIntegrityMeta(IntegrityMeta.newBuilder() | ||
.setMetaSourceUrl("test").build()) | ||
.build(); | ||
|
||
inputTopic.pipeInput(new TestRecord<>("pkg:maven/foo/[email protected]", result, Instant.now())); | ||
qm.getPersistenceManager().refresh(integrityMetaComponent); | ||
integrityMetaComponent = qm.getIntegrityMetaComponent("pkg:maven/foo/[email protected]"); | ||
assertThat(integrityMetaComponent).isNotNull(); | ||
assertThat(integrityMetaComponent.getRepositoryUrl()).isEqualTo("test"); | ||
assertThat(integrityMetaComponent.getLastFetch()).isAfter(date); | ||
assertThat(integrityMetaComponent.getStatus()).isEqualTo(FetchStatus.NOT_AVAILABLE); | ||
|
||
IntegrityAnalysis analysis = qm.getIntegrityAnalysisByComponentUuid(c.getUuid()); | ||
assertThat(analysis.getIntegrityCheckStatus()).isEqualTo(IntegrityMatchStatus.HASH_MATCH_UNKNOWN); | ||
assertThat(analysis.getMd5HashMatchStatus()).isEqualTo(IntegrityMatchStatus.HASH_MATCH_UNKNOWN); | ||
assertThat(analysis.getSha1HashMatchStatus()).isEqualTo(IntegrityMatchStatus.HASH_MATCH_UNKNOWN); | ||
assertThat(analysis.getSha256HashMatchStatus()).isEqualTo(IntegrityMatchStatus.COMPONENT_MISSING_HASH_AND_MATCH_UNKNOWN); | ||
assertThat(analysis.getSha512HashMatchStatus()).isEqualTo(IntegrityMatchStatus.COMPONENT_MISSING_HASH_AND_MATCH_UNKNOWN); | ||
assertThat(analysis.getUpdatedAt()).isNotNull(); | ||
assertThat(analysis.getComponent().getPurl().toString()).isEqualTo("pkg:maven/foo/[email protected]"); | ||
} | ||
|
||
@Test | ||
public void testIntegrityCheckWithDataInDb() { | ||
// Create an active project with one component. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters