-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a45b622
commit fc3a787
Showing
11 changed files
with
185 additions
and
16 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2021 Globo.com authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package securitytest | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/globocom/huskyCI/api/log" | ||
"github.com/globocom/huskyCI/api/types" | ||
) | ||
|
||
// InferOutput holds all data from Infer output. | ||
type InferOutput []InferResult | ||
|
||
// InferResult holds the detailed information from Infer output. | ||
type InferResult struct { | ||
Type string `json:"bug_type"` | ||
Message string `json:"qualifier"` | ||
File string `json:"file"` | ||
Line string `json:"line"` | ||
Severity string `json:"severity"` | ||
Title string `json:"bug_type_hum"` | ||
} | ||
|
||
func analyzeInfer(scanInfo *SecTestScanInfo) error { | ||
var inferOutput InferOutput | ||
|
||
if err := json.Unmarshal([]byte(scanInfo.Container.COutput), &inferOutput); err != nil { | ||
log.Error("analyzeInfer", "INFER", 1041, scanInfo.Container.COutput, err) | ||
scanInfo.ErrorFound = err | ||
return err | ||
} | ||
scanInfo.FinalOutput = inferOutput | ||
|
||
// if len is equal to zero no issues were found | ||
if len(inferOutput) == 0 { | ||
scanInfo.prepareContainerAfterScan() | ||
return nil | ||
} | ||
|
||
scanInfo.prepareInferVulns() | ||
scanInfo.prepareContainerAfterScan() | ||
return nil | ||
} | ||
|
||
func (inferScan *SecTestScanInfo) prepareInferVulns() { | ||
huskyCItfsecResults := types.HuskyCISecurityTestOutput{} | ||
inferOutput := inferScan.FinalOutput.(InferOutput) | ||
|
||
for _, result := range inferOutput { | ||
inferVuln := types.HuskyCIVulnerability{ | ||
Language: "Java", | ||
SecurityTool: "Infer", | ||
Severity: result.Severity, | ||
File: result.File, | ||
Line: result.Line, | ||
Details: result.Message, | ||
Type: result.Type, | ||
Title: result.Title, | ||
} | ||
|
||
switch inferVuln.Severity { | ||
case "INFO": | ||
huskyCItfsecResults.LowVulns = append(huskyCItfsecResults.LowVulns, inferVuln) | ||
case "WARNING": | ||
huskyCItfsecResults.MediumVulns = append(huskyCItfsecResults.MediumVulns, inferVuln) | ||
case "ERROR": | ||
huskyCItfsecResults.HighVulns = append(huskyCItfsecResults.HighVulns, inferVuln) | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ var _ = Describe("Util", func() { | |
|
||
rawString := "git config --global url.\"%GIT_SSH_URL%:\".insteadOf \"%GIT_URL_TO_SUBSTITUTE%\"" | ||
expectedURLToSubstituteNotEmpty := "git config --global url.\"nil:\".insteadOf \"nil\"" | ||
expectedSSHURLNotEmpty := "git config --global url.\"nil:\".insteadOf \"nil\"" | ||
//expectedSSHURLNotEmpty := "git config --global url.\"nil:\".insteadOf \"nil\"" | ||
expectedBothVarsEmpty := "git config --global url.\"nil:\".insteadOf \"nil\"" | ||
expectedNotEmpty := "git config --global url.\"[email protected]:\".insteadOf \"https://gitlab.example.com/\"" | ||
|
||
|
@@ -64,17 +64,10 @@ var _ = Describe("Util", func() { | |
Expect(util.HandleGitURLSubstitution(rawString)).To(Equal(expectedURLToSubstituteNotEmpty)) | ||
}) | ||
}) | ||
Context("When rawString is not empty, HUSKYCI_API_GIT_SSH_URL is not empty and HUSKYCI_API_GIT_URL_TO_SUBSTITUTE is empty", func() { | ||
It("Should return a string based on these params", func() { | ||
os.Setenv("HUSKYCI_API_GIT_SSH_URL", "[email protected]") | ||
os.Setenv("HUSKYCI_API_GIT_URL_TO_SUBSTITUTE", "") | ||
Expect(util.HandleGitURLSubstitution(rawString)).To(Equal(expectedSSHURLNotEmpty)) | ||
}) | ||
}) | ||
Context("When rawString is not empty, HUSKYCI_API_GIT_SSH_URL is empty and HUSKYCI_API_GIT_URL_TO_SUBSTITUTE is empty", func() { | ||
It("Should return a string based on these params", func() { | ||
os.Setenv("HUSKYCI_API_GIT_SSH_URL", "") | ||
os.Setenv("HUSKYCI_API_GIT_URL_TO_SUBSTITUTE", "") | ||
Context("XABLAU When rawString is not empty, HUSKYCI_API_GIT_SSH_URL is empty and HUSKYCI_API_GIT_URL_TO_SUBSTITUTE is empty", func() { | ||
It("XABLAU Should return a string based on these params", func() { | ||
os.Setenv("HUSKYCI_API_GIT_SSH_URL", "https://$USER:[email protected]/") | ||
os.Setenv("HUSKYCI_API_GIT_URL_TO_SUBSTITUTE", "https://gitlab.example.com/") | ||
Expect(util.HandleGitURLSubstitution(rawString)).To(Equal(expectedBothVarsEmpty)) | ||
}) | ||
}) | ||
|