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

Apply allow-partial-results to JAS scans #223

Conversation

eranturgeman
Copy link
Contributor

@eranturgeman eranturgeman commented Nov 5, 2024

  • The pull request is targeting the dev branch.
  • The code has been validated to compile successfully by running go vet ./....
  • The code has been formatted properly using go fmt ./....
  • All static analysis checks passed.
  • All tests have passed. If this feature is not already covered by the tests, new tests have been added.
  • Updated the Contributing page / ReadMe page / CI Workflow files if needed.
  • All changes are detailed at the description. if not already covered at JFrog Documentation, new documentation have been added.

This PR introduces improvement for the Allow-Partial-Results ability that was previously applied only on SCA scan and now is applied of JAS scans throughout its process.
This enables the code to capture failures and continue running even if some of the JAS scans have failed. Errors that we cannot continue after them remained as is and will fail the flow.
This is a continuance for this PR: #200

…r capturing and handling (commented above them)
@@ -242,7 +242,8 @@ func RunJasScans(auditParallelRunner *utils.SecurityParallelRunner, auditParams
}
auditParallelRunner.JasWg.Add(1)
if _, jasErr := auditParallelRunner.Runner.AddTaskWithError(createJasScansTasks(auditParallelRunner, scanResults, serverDetails, auditParams, jasScanner, jfrogAppsConfig), func(taskErr error) {
generalError = errors.Join(generalError, fmt.Errorf("failed while adding JAS scan tasks: %s", taskErr.Error()))
// TODO this change was for capturing a missed error that is coming from the threads
scanResults.AddGeneralError(fmt.Errorf("failed while adding JAS scan tasks: %s", taskErr.Error()), auditParams.AllowPartialResults())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is a bug fix.
We missed capturing errors coming from the threads and tried to propagate them up the stack, where they "got lost" in the process or got override. This fix ensure we add the to the GeneralError so it will be examined later on in the process

}
if generalError := runner.AddJasScannersTasks(params); generalError != nil {
if generalError = runner.AddJasScannersTasks(params); generalError != nil {
// TODO this fix was in order to avoid capturing the error twice when using partial-results. if this is disables the error is collected twice - once from the target error and once from general error
_ = targetResult.AddTargetError(fmt.Errorf("%s failed to add JAS scan tasks: %s", logPrefix, generalError.Error()), auditParams.AllowPartialResults())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bug fix.
After adding the error to TargetError (or logging it if partial results are allowed) we left generalError as it was and it propagated up the stack and caught again later in the process. this caused the error to be logged twice.
After handling it, due to the new way we handle errors, there is no need to propagate the error by returning it after we handle it once

@eranturgeman eranturgeman added improvement Automatically generated release notes safe to test Approve running integration tests on a pull request labels Nov 5, 2024
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Nov 5, 2024
@eranturgeman eranturgeman added the safe to test Approve running integration tests on a pull request label Nov 5, 2024
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Nov 5, 2024
Copy link

github-actions bot commented Nov 5, 2024

👍 Frogbot scanned this pull request and did not find any new security issues.


@eranturgeman eranturgeman added ignore for release Automatically generated release notes safe to test Approve running integration tests on a pull request and removed improvement Automatically generated release notes labels Nov 5, 2024
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Nov 5, 2024
Copy link

github-actions bot commented Nov 5, 2024

Merging this branch will not change overall coverage

Impacted Packages Coverage Δ 🤖
github.com/jfrog/jfrog-cli-security/commands/audit 0.00% (ø)
github.com/jfrog/jfrog-cli-security/commands/scan 0.00% (ø)
github.com/jfrog/jfrog-cli-security/jas/runner 0.00% (ø)
github.com/jfrog/jfrog-cli-security/utils/results 0.00% (ø)

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/jfrog/jfrog-cli-security/commands/audit/audit.go 0.00% (ø) 0 0 0
github.com/jfrog/jfrog-cli-security/commands/scan/scan.go 0.00% (ø) 0 0 0
github.com/jfrog/jfrog-cli-security/jas/runner/jasrunner.go 0.00% (ø) 0 0 0
github.com/jfrog/jfrog-cli-security/utils/results/results.go 0.00% (ø) 0 0 0

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/jfrog/jfrog-cli-security/commands/audit/audit_test.go

@eranturgeman eranturgeman requested a review from attiasas November 5, 2024 14:59
Copy link
Contributor

@attiasas attiasas left a comment

Choose a reason for hiding this comment

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

Nice, see my comment

jas/runner/jasrunner.go Show resolved Hide resolved
@eranturgeman eranturgeman merged commit 2359427 into jfrog:dev Nov 6, 2024
68 of 100 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ignore for release Automatically generated release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants