Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds audit trail comments for all fields of new analysis #3551

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

sebD
Copy link
Contributor

@sebD sebD commented Mar 14, 2024

Description

Adds audit comments for all properties of a newly created analysis entry.

Addressed Issue

Fixes: #3470

Additional Details

This fix proposition changes the current behavior a bit when audits are performed manually via the UI. At the moment, setting the Analysis state only adds a comment about this particular field even though justification and vendor response are also set with default values. The proposed fix would add comments for those too.

This behavior seem coherent with what I understood from the Vex import feature (cf CycloneDXVexImporter.

This is a quick fix solution, a better approach would be to create a dedicated AnalysisService that would be called from the CycloneDXVexImporter and the AnalysisResource. Currently these two classes have too many responsabilities. Moreover, they share the analysis creation responsability and do it in a different manner.

I'll be happy to discuss this refactor further if deemed interesting.

Checklist

  • I have read and understand the contributing guidelines
  • This PR fixes a defect, and I have provided tests to verify that the fix is effective
  • This PR implements an enhancement, and I have provided tests to verify that it works as intended
  • This PR introduces changes to the database model, and I have added corresponding update logic
  • This PR introduces new or alters existing behavior, and I have updated the documentation accordingly

Copy link

codacy-production bot commented Mar 18, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 757a9661 94.34% (target: 70.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (757a966) Report Missing Report Missing Report Missing
Head commit (5dffd9f) 21728 16113 74.16%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#3551) 212 200 94.34%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

You may notice some variations in coverage metrics with the latest Coverage engine update. For more details, visit the documentation

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@sebD sebD marked this pull request as ready for review March 18, 2024 02:58
Copy link
Member

@nscuro nscuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @sebD! A few suggestions.

a better approach would be to create a dedicated AnalysisService that would be called from the CycloneDXVexImporter and the AnalysisResource. Currently these two classes have too many responsabilities. Moreover, they share the analysis creation responsability and do it in a different manner.

Indeed it would be great to have this logic centralized. Would you like to take a shot at that in this PR?


public static void makeFirstStateComment(final QueryManager qm, final Analysis analysis, final String commenter) {
if (analysis.getAnalysisState() != null) {
addAnalysisStateComment(qm, analysis, null, analysis.getAnalysisState(), commenter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use NOT_SET here instead of null. null should not be exposed to users.

Suggested change
addAnalysisStateComment(qm, analysis, null, analysis.getAnalysisState(), commenter);
addAnalysisStateComment(qm, analysis, AnalysisState.NOT_SET, analysis.getAnalysisState(), commenter);

Comment on lines 352 to 356
Condition<String> elfBearer = new Condition<String>() {
public boolean matches(String value) {
return value.contains("toto");
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Good catch

assertThat(responseJson.getJsonArray("analysisComments").getJsonObject(0))
.hasFieldOrPropertyWithValue("comment", Json.createValue("Analysis: NOT_SET → NOT_AFFECTED"))
.hasFieldOrPropertyWithValue("comment", Json.createValue("Analysis: null → NOT_AFFECTED"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a regression and would be resolved by passing NOT_SET instead of null when creating the comment.


public static void makeFirstAnalysisResponseComment(QueryManager qm, Analysis analysis, String commenter) {
if (analysis.getAnalysisResponse() != null) {
addAnalysisResponseComment(qm, analysis, null, analysis.getAnalysisResponse(), commenter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
addAnalysisResponseComment(qm, analysis, null, analysis.getAnalysisResponse(), commenter);
addAnalysisResponseComment(qm, analysis, AnalysisResponse.NOT_SET, analysis.getAnalysisResponse(), commenter);


public static void makeFirstJustificationComment(QueryManager qm, Analysis analysis, String commenter) {
if (analysis.getAnalysisJustification() != null) {
addAnalysisJustificationComment(qm, analysis, null, analysis.getAnalysisJustification(), commenter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
addAnalysisJustificationComment(qm, analysis, null, analysis.getAnalysisJustification(), commenter);
addAnalysisJustificationComment(qm, analysis, AnalysisJustification.NOT_SET, analysis.getAnalysisJustification(), commenter);

@sebD
Copy link
Contributor Author

sebD commented Mar 19, 2024

I'll have a look.

@sebD sebD force-pushed the 3470-analysis-details-missing branch from 1030f44 to 315ad3e Compare March 20, 2024 22:23
@sebD sebD marked this pull request as draft March 20, 2024 22:57
@sebD
Copy link
Contributor Author

sebD commented Mar 22, 2024

@nscuro I am currently working on fixing some tests. Do not hesitate to give me any remarks on the proposed solution. I have taken some initiatives that differ a bit from the rest of the app. As I'm a new contributor, I remain open to make any change in the design.

@sebD sebD force-pushed the 3470-analysis-details-missing branch 2 times, most recently from 067338c to 5dffd9f Compare April 7, 2024 10:55
@sebD
Copy link
Contributor Author

sebD commented Apr 7, 2024

@nscuro PR ready for second review round

@nscuro
Copy link
Member

nscuro commented Apr 10, 2024

Thanks @sebD I'll have a look over the coming days. Trying to wrap up remaining work for v4.11 at the moment.

@sebD
Copy link
Contributor Author

sebD commented Apr 10, 2024

No problem. Take your time.

…nalysis added either via UI or directly via REST call.

Does add more comments when using the UI but reflects state of the vulnerability audit better.

Fixes: DependencyTrack#3470

Signed-off-by: Sebastien Delcoigne <sebastien.delcoigne@gmail.com>
…d service

Adds analysis comments for justification, state and details for new analysis added either via UI or directly via REST call.

 Fixes DependencyTrack#3470

Signed-off-by: Sebastien Delcoigne <sebastien.delcoigne@gmail.com>
Signed-off-by: Sebastien Delcoigne <sebastien.delcoigne@gmail.com>
… AnalysisService to avoid "Object with id 'x' is managed by a different persistence manager" error types

Signed-off-by: Sebastien Delcoigne <sebastien.delcoigne@gmail.com>
@sebD sebD force-pushed the 3470-analysis-details-missing branch from 5dffd9f to 62bf367 Compare April 12, 2024 00:42
Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.13% (target: -1.00%) 94.34% (target: 70.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (3e8f93f) 21657 16127 74.47%
Head commit (62bf367) 21762 (+105) 16233 (+106) 74.59% (+0.13%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#3551) 212 200 94.34%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

You may notice some variations in coverage metrics with the latest Coverage engine update. For more details, visit the documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API /api/v1/analysis - PUT call does not populate analisisDetail
2 participants