-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add REST API endpoints for component integrity metadata (#377)
* changes for end points with integrity meta Signed-off-by: mehab <[email protected]> * unit tests completed Signed-off-by: mehab <[email protected]> * refactoring Signed-off-by: mehab <[email protected]> * address pr review comments Signed-off-by: mehab <[email protected]> * more refactoring Signed-off-by: mehab <[email protected]> --------- Signed-off-by: mehab <[email protected]> Signed-off-by: meha <[email protected]>
- Loading branch information
Showing
9 changed files
with
380 additions
and
32 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
7 changes: 7 additions & 0 deletions
7
src/main/java/org/dependencytrack/model/ComponentMetaInformation.java
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.dependencytrack.model; | ||
|
||
import java.util.Date; | ||
|
||
public record ComponentMetaInformation(Date publishedDate, IntegrityMatchStatus integrityMatchStatus, | ||
Date lastFetched) { | ||
} |
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
50 changes: 50 additions & 0 deletions
50
src/test/java/org/dependencytrack/persistence/QueryManagerTest.java
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.dependencytrack.persistence; | ||
|
||
import org.dependencytrack.PersistenceCapableTest; | ||
import org.dependencytrack.model.Component; | ||
import org.dependencytrack.model.ComponentMetaInformation; | ||
import org.dependencytrack.model.FetchStatus; | ||
import org.dependencytrack.model.IntegrityAnalysis; | ||
import org.dependencytrack.model.IntegrityMatchStatus; | ||
import org.dependencytrack.model.IntegrityMetaComponent; | ||
import org.dependencytrack.model.Project; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.Date; | ||
|
||
import static org.dependencytrack.model.IntegrityMatchStatus.HASH_MATCH_PASSED; | ||
import static org.dependencytrack.model.IntegrityMatchStatus.HASH_MATCH_UNKNOWN; | ||
|
||
public class QueryManagerTest extends PersistenceCapableTest { | ||
@Test | ||
public void testGetMetaInformation() { | ||
Project project = qm.createProject("Acme Application", null, null, null, null, null, true, false); | ||
Component component = new Component(); | ||
component.setProject(project); | ||
component.setName("ABC"); | ||
component.setPurl("pkg:maven/org.acme/abc"); | ||
IntegrityAnalysis integrityAnalysis = new IntegrityAnalysis(); | ||
integrityAnalysis.setComponent(component); | ||
integrityAnalysis.setIntegrityCheckStatus(IntegrityMatchStatus.HASH_MATCH_PASSED); | ||
Date published = new Date(); | ||
integrityAnalysis.setUpdatedAt(published); | ||
integrityAnalysis.setId(component.getId()); | ||
integrityAnalysis.setMd5HashMatchStatus(IntegrityMatchStatus.HASH_MATCH_PASSED); | ||
integrityAnalysis.setSha1HashMatchStatus(HASH_MATCH_UNKNOWN); | ||
integrityAnalysis.setSha256HashMatchStatus(HASH_MATCH_UNKNOWN); | ||
integrityAnalysis.setSha512HashMatchStatus(HASH_MATCH_PASSED); | ||
qm.persist(integrityAnalysis); | ||
IntegrityMetaComponent integrityMetaComponent = new IntegrityMetaComponent(); | ||
integrityMetaComponent.setPurl(component.getPurl().toString()); | ||
integrityMetaComponent.setPublishedAt(published); | ||
integrityMetaComponent.setLastFetch(published); | ||
integrityMetaComponent.setStatus(FetchStatus.PROCESSED); | ||
qm.createIntegrityMetaComponent(integrityMetaComponent); | ||
component = qm.createComponent(component, false); | ||
ComponentMetaInformation componentMetaInformation = qm.getMetaInformation(component.getPurl(), component.getUuid()); | ||
Assert.assertEquals(HASH_MATCH_PASSED, componentMetaInformation.integrityMatchStatus()); | ||
Assert.assertEquals(integrityMetaComponent.getPublishedAt(), componentMetaInformation.publishedDate()); | ||
Assert.assertEquals(integrityMetaComponent.getLastFetch(), componentMetaInformation.lastFetched()); | ||
} | ||
} |
Oops, something went wrong.