-
-
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.
Integrity analysis if enabled (#399)
- Loading branch information
Showing
5 changed files
with
132 additions
and
19 deletions.
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
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 |
---|---|---|
|
@@ -319,7 +319,7 @@ public void testIntegrityCheckWithDataInDb() { | |
} | ||
|
||
@Test | ||
public void testIntegrityCheckWillNotBeDoneIfComponentUuidIsMissing() { | ||
public void testIntegrityCheckWillNotBeDoneIfComponentUuidAndIntegrityDataIsMissing() { | ||
// 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(); | ||
|
@@ -356,6 +356,48 @@ public void testIntegrityCheckWillNotBeDoneIfComponentUuidIsMissing() { | |
assertThat(analysis).isNull(); | ||
} | ||
|
||
@Test | ||
public void testIntegrityIfResultHasIntegrityDataAndComponentUuidIsMissing() { | ||
// 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() | ||
.setPurl("pkg:maven/foo/[email protected]")) | ||
.setIntegrityMeta(IntegrityMeta.newBuilder() | ||
.setMd5("098f6bcd4621d373cade4e832627b4f6") | ||
.setSha1("a94a8fe5ccb19ba61c4c0873d391e987982fbbd3") | ||
.build()) | ||
//component uuid has not been set | ||
.build(); | ||
|
||
inputTopic.pipeInput(new TestRecord<>("pkg:maven/foo/[email protected]", result, Instant.now())); | ||
|
||
IntegrityAnalysis analysis = qm.getIntegrityAnalysisByComponentUuid(c.getUuid()); | ||
assertThat(analysis).isNotNull(); | ||
assertThat(analysis.getComponent()).isEqualTo(c); | ||
assertThat(analysis.getIntegrityCheckStatus()).isEqualTo(IntegrityMatchStatus.HASH_MATCH_PASSED); | ||
} | ||
|
||
|
||
@Test | ||
public void testIntegrityCheckWillNotBeDoneIfComponentIsNotInDb() { | ||
|
||
|
@@ -612,7 +654,6 @@ public void processBothMetaModelAndIntegrityMeta() { | |
|
||
inputTopic.pipeInput("pkg:maven/foo/bar", result); | ||
qm.getPersistenceManager().refresh(integrityMetaComponent); | ||
qm.getPersistenceManager().refresh(integrityMetaComponent); | ||
final RepositoryMetaComponent metaComponent = | ||
qm.getRepositoryMetaComponent(RepositoryType.MAVEN, "foo", "bar"); | ||
assertThat(metaComponent).isNotNull(); | ||
|
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
|
||
import javax.jdo.JDOObjectNotFoundException; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
|
@@ -105,4 +106,45 @@ public void recursivelyDeleteTest() { | |
assertThatNoException().isThrownBy(() -> qm.getObjectById(PolicyCondition.class, policyCondition.getId())); | ||
assertThatNoException().isThrownBy(() -> qm.getObjectById(Policy.class, policy.getId())); | ||
} | ||
|
||
@Test | ||
public void testGetComponentsByPurl() { | ||
final var project = new Project(); | ||
project.setName("acme-app"); | ||
project.setVersion("1.0.0"); | ||
qm.persist(project); | ||
|
||
final var component1 = new Component(); | ||
component1.setProject(project); | ||
component1.setName("acme-lib-a"); | ||
component1.setVersion("1.0.1"); | ||
component1.setPurl("pkg:maven/foo/[email protected]"); | ||
component1.setPurlCoordinates("pkg:maven/foo/[email protected]"); | ||
component1.setMd5("098f6bcd4621d373cade4e832627b4f6"); | ||
component1.setSha1("a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"); | ||
qm.persist(component1); | ||
|
||
final var component2 = new Component(); | ||
component2.setProject(project); | ||
component2.setProject(project); | ||
component2.setName("acme-lib"); | ||
component2.setVersion("1.0.1"); | ||
component2.setPurl("pkg:maven/foo/[email protected]"); | ||
component2.setPurlCoordinates("pkg:maven/foo/[email protected]"); | ||
component2.setMd5("098f6bcd4621d373cade4e832627b4f6"); | ||
component2.setSha1("a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"); | ||
qm.persist(component2); | ||
|
||
List<Component> components = qm.getComponentsByPurl("pkg:maven/foo/[email protected]"); | ||
assertThat(components).isNotNull(); | ||
assertThat(components).hasSize(2); | ||
assertThat(components).satisfiesExactlyInAnyOrder(component -> { | ||
assertThat(component.getMd5()).isEqualTo("098f6bcd4621d373cade4e832627b4f6"); | ||
assertThat(component.getSha1()).isEqualTo("a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"); | ||
}, | ||
component -> { | ||
assertThat(component.getMd5()).isEqualTo("098f6bcd4621d373cade4e832627b4f6"); | ||
assertThat(component.getSha1()).isEqualTo("a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"); | ||
}); | ||
} | ||
} |