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

Fixes incorrect filepath reporting in sarif output & added e2e tests for sarif output #863

Merged
merged 9 commits into from
Jun 28, 2021

Conversation

devang-gaur
Copy link
Contributor

fixes #861

@codecov
Copy link

codecov bot commented Jun 15, 2021

Codecov Report

Merging #863 (72638fb) into master (a74765d) will decrease coverage by 0.18%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #863      +/-   ##
==========================================
- Coverage   78.59%   78.41%   -0.19%     
==========================================
  Files         167      168       +1     
  Lines        4452     4470      +18     
==========================================
+ Hits         3499     3505       +6     
- Misses        732      741       +9     
- Partials      221      224       +3     
Impacted Files Coverage Δ
pkg/utils/file.go 33.33% <33.33%> (ø)
pkg/writer/sarif.go 82.97% <50.00%> (-11.90%) ⬇️
pkg/utils/json.go 69.69% <66.66%> (+0.94%) ⬆️
pkg/utils/dir.go 81.81% <100.00%> (ø)

Copy link
Contributor

@kanchwala-yusuf kanchwala-yusuf left a comment

Choose a reason for hiding this comment

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

Please run go mod tidy on this PR as well

pkg/utils/dir.go Outdated
@@ -30,7 +30,7 @@ func GenerateTempDir() string {
func IsDirExists(dir string) bool {
_, err := os.Stat(dir)
if os.IsNotExist(err) {
zap.S().Debug("Directory %s does not exist.", dir)
zap.S().Errorf("Directory %s does not exist.", dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

error string should not start with a capital alphabet

zap.S().Errorf("file %s does not exist.", path)
} else {
zap.S().Errorf("unable to fetch file info for path %s.", path)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This method may panic. os.Stat() returns nil file info on an error and we are just logging the error and not returning.

@@ -0,0 +1,19 @@
package utils
Copy link
Contributor

Choose a reason for hiding this comment

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

missing copyright header?

@@ -73,3 +73,23 @@ func AreEqualJSON(s1, s2 string) (bool, error) {

return reflect.DeepEqual(o1, o2), nil
}

// AreEqualJSONBytes validate if two json byte arrays are equal
func AreEqualJSONBytes(b1, b2 []byte) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to use AreEqualJSON already present in the file?
If not, I think we can refactor AreEqualJSON func.


func getAbsoluteFilePath(resourcePath, filePath string) string {
if !filepath.IsAbs(resourcePath) {
resourcePath, _ = filepath.Abs(resourcePath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Even though error seems unlikely here, I think we should handle error case too !!

}

// SarifTemplateAWSAMIViolation string
const SarifTemplateAWSAMIViolation = `{
Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering if we can use golden text files instead of a template. Is it possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think It'll unnecessary add another step of file processing. Maybe we can take this point up in some other refactor phase as such templates are being used in other places as well.

// GetAbsoluteFilePathForSarif helper for sarif path
func GetAbsoluteFilePathForSarif(resourcePath, filePath string) string {
if !filepath.IsAbs(resourcePath) {
resourcePath, _ = filepath.Abs(resourcePath)
Copy link
Contributor

Choose a reason for hiding this comment

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

we should handle the error case here too.

@sonarcloud
Copy link

sonarcloud bot commented Jun 26, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@devang-gaur devang-gaur merged commit b8fda7c into tenable:master Jun 28, 2021
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.

Sarif output has wrong file path value for file scans
4 participants