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

Remove from system sca json file when using scan create with scaResolver (AST-48074) #922

Closed
wants to merge 2 commits into from

Conversation

Korjen97
Copy link
Contributor

…lver

By submitting a PR to this repository, you agree to the terms within the Checkmarx Code of Conduct. Please see the contributing guidelines for how to create and submit a high-quality PR for this repo.

Description

File Removal Logic: Added _ = os.Remove(scaFile.Name()) at the end of the function to ensure the temporary file created by ioutil.TempFile is deleted after the scan completes.

References

https://checkmarx.atlassian.net/browse/AST-48074

Testing

Unit Test (TestRunScaResolverFileCleanup)
Mock Setup: Defined mock values for sourceDir, scaResolver, and projectName.
Function Execution: Called runScaResolver with the mock inputs.
File Deletion Check: Verified that the temporary file was deleted using os.Stat and os.IsNotExist, ensuring that the cleanup process worked as expected.

Please include any manual steps for testing end-to-end or functionality not covered by unit/integration tests.

Checklist

  • I have added documentation for new/changed functionality in this PR (if applicable).
  • I have updated the CLI help for new/changed functionality in this PR (if applicable).
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used

@OrShamirCM OrShamirCM requested a review from a team October 31, 2024 12:36
@github-actions github-actions bot added the bug Something isn't working label Oct 31, 2024
@@ -1356,6 +1356,7 @@ func runScaResolver(sourceDir, scaResolver, scaResolverParams, projectName strin
if err != nil {
return errors.Errorf("%s", err)
}
_ = os.Remove(scaFile.Name())
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe check the results of this action, and log it
something like:
err = os.Remove(scaFile.Name())
if err != nil {
log.Printf("Failed to remove file %s: %v", scaFile.Name(), err)
} else {
log.Printf("Successfully removed file %s", scaFile.Name())
}


_, err = os.Stat(scaResolverResultsFile)
assert.Assert(t, os.IsNotExist(err), "Expected temp file to be deleted, but it exists")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

As a continuation of the previous comment
check the logs to see that file really deleted

@Korjen97 Korjen97 closed this Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants