Skip to content

Commit 892fa96

Browse files
committed
start cleaning
1 parent a69b532 commit 892fa96

File tree

9 files changed

+108
-174
lines changed

9 files changed

+108
-174
lines changed

commands/audit/audit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (auditCmd *AuditCommand) CommandName() string {
169169
}
170170

171171
func (auditCmd *AuditCommand) HasViolationContext() bool {
172-
return len(auditCmd.watches) > 0 || auditCmd.projectKey != "" || auditCmd.targetRepoPath != ""
172+
return len(auditCmd.watches) > 0 || auditCmd.projectKey != "" || auditCmd.targetRepoPath != "" || (auditCmd.gitInfoContext != nil && auditCmd.gitInfoContext.GitRepoUrl != "")
173173
}
174174

175175
// Runs an audit scan based on the provided auditParams.

commands/audit/audit_test.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ package audit
22

33
import (
44
"fmt"
5-
commonCommands "github.com/jfrog/jfrog-cli-core/v2/common/commands"
6-
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
7-
configTests "github.com/jfrog/jfrog-cli-security/tests"
8-
securityTestUtils "github.com/jfrog/jfrog-cli-security/tests/utils"
9-
clientTests "github.com/jfrog/jfrog-client-go/utils/tests"
105
"net/http"
116
"path/filepath"
127
"sort"
138
"strings"
149
"testing"
1510

11+
commonCommands "github.com/jfrog/jfrog-cli-core/v2/common/commands"
12+
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
13+
configTests "github.com/jfrog/jfrog-cli-security/tests"
14+
securityTestUtils "github.com/jfrog/jfrog-cli-security/tests/utils"
15+
clientTests "github.com/jfrog/jfrog-client-go/utils/tests"
16+
1617
"github.com/stretchr/testify/assert"
1718

1819
"github.com/jfrog/jfrog-cli-security/utils"
@@ -57,14 +58,14 @@ func TestDetectScansToPreform(t *testing.T) {
5758
ScanTarget: results.ScanTarget{
5859
Target: filepath.Join(dir, "Nuget"),
5960
},
60-
JasResultsNew: &results.JasScansResultsNew{},
61+
JasResults: &results.JasScansResults{},
6162
},
6263
{
6364
ScanTarget: results.ScanTarget{
6465
Technology: techutils.Go,
6566
Target: filepath.Join(dir, "dir", "go"),
6667
},
67-
JasResultsNew: &results.JasScansResultsNew{},
68+
JasResults: &results.JasScansResults{},
6869
ScaResults: &results.ScaScanResults{
6970
Descriptors: []string{filepath.Join(dir, "dir", "go", "go.mod")},
7071
},
@@ -74,7 +75,7 @@ func TestDetectScansToPreform(t *testing.T) {
7475
Technology: techutils.Maven,
7576
Target: filepath.Join(dir, "dir", "maven"),
7677
},
77-
JasResultsNew: &results.JasScansResultsNew{},
78+
JasResults: &results.JasScansResults{},
7879
ScaResults: &results.ScaScanResults{
7980
Descriptors: []string{
8081
filepath.Join(dir, "dir", "maven", "maven-sub", "pom.xml"),
@@ -88,7 +89,7 @@ func TestDetectScansToPreform(t *testing.T) {
8889
Technology: techutils.Npm,
8990
Target: filepath.Join(dir, "dir", "npm"),
9091
},
91-
JasResultsNew: &results.JasScansResultsNew{},
92+
JasResults: &results.JasScansResults{},
9293
ScaResults: &results.ScaScanResults{
9394
Descriptors: []string{filepath.Join(dir, "dir", "npm", "package.json")},
9495
},
@@ -98,7 +99,7 @@ func TestDetectScansToPreform(t *testing.T) {
9899
ScanTarget: results.ScanTarget{
99100
Target: filepath.Join(dir, "yarn"),
100101
},
101-
JasResultsNew: &results.JasScansResultsNew{},
102+
JasResults: &results.JasScansResults{},
102103
},
103104
},
104105
},
@@ -116,7 +117,7 @@ func TestDetectScansToPreform(t *testing.T) {
116117
Technology: techutils.Nuget,
117118
Target: filepath.Join(dir, "Nuget"),
118119
},
119-
JasResultsNew: &results.JasScansResultsNew{},
120+
JasResults: &results.JasScansResults{},
120121
ScaResults: &results.ScaScanResults{
121122
Descriptors: []string{filepath.Join(dir, "Nuget", "Nuget-sub", "project.csproj"), filepath.Join(dir, "Nuget", "project.sln")},
122123
},
@@ -126,7 +127,7 @@ func TestDetectScansToPreform(t *testing.T) {
126127
Technology: techutils.Go,
127128
Target: filepath.Join(dir, "dir", "go"),
128129
},
129-
JasResultsNew: &results.JasScansResultsNew{},
130+
JasResults: &results.JasScansResults{},
130131
ScaResults: &results.ScaScanResults{
131132
Descriptors: []string{filepath.Join(dir, "dir", "go", "go.mod")},
132133
},
@@ -136,7 +137,7 @@ func TestDetectScansToPreform(t *testing.T) {
136137
Technology: techutils.Maven,
137138
Target: filepath.Join(dir, "dir", "maven"),
138139
},
139-
JasResultsNew: &results.JasScansResultsNew{},
140+
JasResults: &results.JasScansResults{},
140141
ScaResults: &results.ScaScanResults{
141142
Descriptors: []string{
142143
filepath.Join(dir, "dir", "maven", "maven-sub", "pom.xml"),
@@ -150,7 +151,7 @@ func TestDetectScansToPreform(t *testing.T) {
150151
Technology: techutils.Npm,
151152
Target: filepath.Join(dir, "dir", "npm"),
152153
},
153-
JasResultsNew: &results.JasScansResultsNew{},
154+
JasResults: &results.JasScansResults{},
154155
ScaResults: &results.ScaScanResults{
155156
Descriptors: []string{filepath.Join(dir, "dir", "npm", "package.json")},
156157
},
@@ -160,7 +161,7 @@ func TestDetectScansToPreform(t *testing.T) {
160161
Technology: techutils.Yarn,
161162
Target: filepath.Join(dir, "yarn"),
162163
},
163-
JasResultsNew: &results.JasScansResultsNew{},
164+
JasResults: &results.JasScansResults{},
164165
ScaResults: &results.ScaScanResults{
165166
Descriptors: []string{filepath.Join(dir, "yarn", "package.json")},
166167
},
@@ -170,7 +171,7 @@ func TestDetectScansToPreform(t *testing.T) {
170171
Technology: techutils.Pip,
171172
Target: filepath.Join(dir, "yarn", "Pip"),
172173
},
173-
JasResultsNew: &results.JasScansResultsNew{},
174+
JasResults: &results.JasScansResults{},
174175
ScaResults: &results.ScaScanResults{
175176
Descriptors: []string{filepath.Join(dir, "yarn", "Pip", "requirements.txt")},
176177
},
@@ -180,7 +181,7 @@ func TestDetectScansToPreform(t *testing.T) {
180181
Technology: techutils.Pipenv,
181182
Target: filepath.Join(dir, "yarn", "Pipenv"),
182183
},
183-
JasResultsNew: &results.JasScansResultsNew{},
184+
JasResults: &results.JasScansResults{},
184185
ScaResults: &results.ScaScanResults{
185186
Descriptors: []string{filepath.Join(dir, "yarn", "Pipenv", "Pipfile")},
186187
},

jas/common.go

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package jas
33
import (
44
"errors"
55
"fmt"
6-
"io"
76
"os"
87
"path/filepath"
98
"strconv"
@@ -137,10 +136,10 @@ func ReadJasScanRunsFromFile(fileName, wd, informationUrlSuffix string, minSever
137136
processSarifRuns(vulnerabilitiesSarifRuns, wd, informationUrlSuffix, minSeverity)
138137

139138
// TODO eran delete
140-
err = createViolationsFile(fileName)
141-
if err != nil {
142-
return
143-
}
139+
// err = createViolationsFile(fileName)
140+
// if err != nil {
141+
// return
142+
// }
144143

145144
var violationsSarifExists bool
146145
violationsSarifFileName := fileName + "_violations"
@@ -156,32 +155,32 @@ func ReadJasScanRunsFromFile(fileName, wd, informationUrlSuffix string, minSever
156155
}
157156

158157
// TODO eran delete this func
159-
func createViolationsFile(filePath string) (err error) {
160-
// Open the original file for reading.
161-
originalFile, err := os.Open(filePath)
162-
if err != nil {
163-
return fmt.Errorf("failed to open original file: %w", err)
164-
}
165-
defer originalFile.Close() // Ensure the original file is closed
166-
167-
// Create a new file name by appending "_violations" to the original filename
168-
newFileName := filePath + "_violations" // Simply append "_violations"
169-
170-
// Create the new file for writing
171-
newFile, err := os.Create(newFileName)
172-
if err != nil {
173-
return fmt.Errorf("failed to create copy file: %w", err)
174-
}
175-
defer newFile.Close() // Ensure the new file is closed
176-
177-
// Copy the original file to the new file
178-
_, err = io.Copy(newFile, originalFile)
179-
if err != nil {
180-
return fmt.Errorf("failed to copy file content: %w", err)
181-
}
182-
183-
return nil
184-
}
158+
// func createViolationsFile(filePath string) (err error) {
159+
// // Open the original file for reading.
160+
// originalFile, err := os.Open(filePath)
161+
// if err != nil {
162+
// return fmt.Errorf("failed to open original file: %w", err)
163+
// }
164+
// defer originalFile.Close() // Ensure the original file is closed
165+
166+
// // Create a new file name by appending "_violations" to the original filename
167+
// newFileName := filePath + "_violations" // Simply append "_violations"
168+
169+
// // Create the new file for writing
170+
// newFile, err := os.Create(newFileName)
171+
// if err != nil {
172+
// return fmt.Errorf("failed to create copy file: %w", err)
173+
// }
174+
// defer newFile.Close() // Ensure the new file is closed
175+
176+
// // Copy the original file to the new file
177+
// _, err = io.Copy(newFile, originalFile)
178+
// if err != nil {
179+
// return fmt.Errorf("failed to copy file content: %w", err)
180+
// }
181+
182+
// return nil
183+
// }
185184

186185
// This function processes the Sarif runs results: update invocations, fill missing information, exclude results and adding scores to rules
187186
func processSarifRuns(sarifRuns []*sarif.Run, wd string, informationUrlSuffix string, minSeverity severityutils.Severity) {

jas/runner/jasrunner.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ func AddJasScannersTasks(params JasRunnerParams) (generalError error) {
6363
// Don't execute other scanners when scanning third party dependencies.
6464
return
6565
}
66-
if generalError = addJasScanTaskForModuleIfNeeded(params, utils.SecretsScan, runSecretsScan(params.Runner, params.Scanner, params.ScanResults.JasResultsNew, params.Module, params.SecretsScanType, params.TargetOutputDir)); generalError != nil {
66+
if generalError = addJasScanTaskForModuleIfNeeded(params, utils.SecretsScan, runSecretsScan(params.Runner, params.Scanner, params.ScanResults.JasResults, params.Module, params.SecretsScanType, params.TargetOutputDir)); generalError != nil {
6767
return
6868
}
6969
if !runAllScanners {
7070
return
7171
}
72-
if generalError = addJasScanTaskForModuleIfNeeded(params, utils.IacScan, runIacScan(params.Runner, params.Scanner, params.ScanResults.JasResultsNew, params.Module, params.TargetOutputDir)); generalError != nil {
72+
if generalError = addJasScanTaskForModuleIfNeeded(params, utils.IacScan, runIacScan(params.Runner, params.Scanner, params.ScanResults.JasResults, params.Module, params.TargetOutputDir)); generalError != nil {
7373
return
7474
}
75-
return addJasScanTaskForModuleIfNeeded(params, utils.SastScan, runSastScan(params.Runner, params.Scanner, params.ScanResults.JasResultsNew, params.Module, params.TargetOutputDir, params.SignedDescriptions))
75+
return addJasScanTaskForModuleIfNeeded(params, utils.SastScan, runSastScan(params.Runner, params.Scanner, params.ScanResults.JasResults, params.Module, params.TargetOutputDir, params.SignedDescriptions))
7676
}
7777

7878
func addJasScanTaskForModuleIfNeeded(params JasRunnerParams, subScan utils.SubScanType, task parallel.TaskFunc) (generalError error) {
@@ -127,7 +127,7 @@ func addModuleJasScanTask(scanType jasutils.JasScanType, securityParallelRunner
127127
return
128128
}
129129

130-
func runSecretsScan(securityParallelRunner *utils.SecurityParallelRunner, scanner *jas.JasScanner, extendedScanResults *results.JasScansResultsNew,
130+
func runSecretsScan(securityParallelRunner *utils.SecurityParallelRunner, scanner *jas.JasScanner, extendedScanResults *results.JasScansResults,
131131
module jfrogappsconfig.Module, secretsScanType secrets.SecretsScanType, scansOutputDir string) parallel.TaskFunc {
132132
return func(threadId int) (err error) {
133133
defer func() {
@@ -146,7 +146,7 @@ func runSecretsScan(securityParallelRunner *utils.SecurityParallelRunner, scanne
146146
}
147147
}
148148

149-
func runIacScan(securityParallelRunner *utils.SecurityParallelRunner, scanner *jas.JasScanner, extendedScanResults *results.JasScansResultsNew,
149+
func runIacScan(securityParallelRunner *utils.SecurityParallelRunner, scanner *jas.JasScanner, extendedScanResults *results.JasScansResults,
150150
module jfrogappsconfig.Module, scansOutputDir string) parallel.TaskFunc {
151151
return func(threadId int) (err error) {
152152
defer func() {
@@ -165,7 +165,7 @@ func runIacScan(securityParallelRunner *utils.SecurityParallelRunner, scanner *j
165165
}
166166
}
167167

168-
func runSastScan(securityParallelRunner *utils.SecurityParallelRunner, scanner *jas.JasScanner, extendedScanResults *results.JasScansResultsNew,
168+
func runSastScan(securityParallelRunner *utils.SecurityParallelRunner, scanner *jas.JasScanner, extendedScanResults *results.JasScansResults,
169169
module jfrogappsconfig.Module, scansOutputDir string, signedDescriptions bool) parallel.TaskFunc {
170170
return func(threadId int) (err error) {
171171
defer func() {
@@ -198,7 +198,7 @@ func runContextualScan(securityParallelRunner *utils.SecurityParallelRunner, sca
198198
}
199199
securityParallelRunner.ResultsMu.Lock()
200200
defer securityParallelRunner.ResultsMu.Unlock()
201-
scanResults.JasResultsNew.JasVulnerabilities.ApplicabilityScanResults = append(scanResults.JasResultsNew.JasVulnerabilities.ApplicabilityScanResults, vulnerabilitiesResults...)
201+
scanResults.JasResults.JasVulnerabilities.ApplicabilityScanResults = append(scanResults.JasResults.JasVulnerabilities.ApplicabilityScanResults, vulnerabilitiesResults...)
202202
err = dumpSarifRunToFileIfNeeded(vulnerabilitiesResults, scansOutputDir, jasutils.Applicability)
203203
return
204204
}

tests/utils/test_utils.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ func ReadCmdScanResults(t *testing.T, path string) *results.SecurityCommandResul
127127
targetResults.ScaResults.Descriptors[i] = filepath.FromSlash(descriptor)
128128
}
129129
}
130-
if targetResults.JasResultsNew.JasVulnerabilities != nil {
131-
convertSarifRunPathsForOS(targetResults.JasResultsNew.JasVulnerabilities.ApplicabilityScanResults...)
132-
convertSarifRunPathsForOS(targetResults.JasResultsNew.JasVulnerabilities.SecretsScanResults...)
133-
convertSarifRunPathsForOS(targetResults.JasResultsNew.JasVulnerabilities.IacScanResults...)
134-
convertSarifRunPathsForOS(targetResults.JasResultsNew.JasVulnerabilities.SastScanResults...)
130+
if targetResults.JasResults.JasVulnerabilities != nil {
131+
convertSarifRunPathsForOS(targetResults.JasResults.JasVulnerabilities.ApplicabilityScanResults...)
132+
convertSarifRunPathsForOS(targetResults.JasResults.JasVulnerabilities.SecretsScanResults...)
133+
convertSarifRunPathsForOS(targetResults.JasResults.JasVulnerabilities.IacScanResults...)
134+
convertSarifRunPathsForOS(targetResults.JasResults.JasVulnerabilities.SastScanResults...)
135135
}
136136
}
137137
return cmdResults

utils/formats/simplejsonapi.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package formats
22

3-
import "github.com/jfrog/jfrog-cli-security/utils/techutils"
3+
import (
4+
"fmt"
5+
6+
"github.com/jfrog/jfrog-cli-security/utils/techutils"
7+
)
48

59
// Structs in this file should NOT be changed!
610
// The structs are used as an API for the simple-json format, thus changing their structure or the 'json' annotation will break the API.
@@ -86,6 +90,10 @@ type Location struct {
8690
Snippet string `json:"snippet,omitempty"`
8791
}
8892

93+
func (l Location) ToString() string {
94+
return fmt.Sprintf("%s|%d|%d|%d|%d|%s", l.File, l.StartLine, l.StartColumn, l.EndLine, l.EndColumn, l.Snippet)
95+
}
96+
8997
type ComponentRow struct {
9098
Name string `json:"name"`
9199
Version string `json:"version"`

utils/results/conversion/convertor.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,38 +111,38 @@ func parseCommandResults[T interface{}](params ResultConvertParams, parser Resul
111111

112112
func parseRequiredJasResults[T interface{}](params ResultConvertParams, parser ResultsStreamFormatParser[T], targetResults *results.TargetResults, cmdType utils.CommandType) (err error) {
113113
// Parsing JAS vulnerabilities results
114-
if targetResults.JasResultsNew != nil && targetResults.JasResultsNew.JasVulnerabilities != nil {
114+
if targetResults.JasResults != nil && targetResults.JasResults.JasVulnerabilities != nil {
115115
if utils.IsScanRequested(cmdType, utils.SecretsScan, params.RequestedScans...) {
116-
if err = parser.ParseSecrets(targetResults.ScanTarget, false, targetResults.JasResultsNew.JasVulnerabilities.SecretsScanResults...); err != nil {
116+
if err = parser.ParseSecrets(targetResults.ScanTarget, false, targetResults.JasResults.JasVulnerabilities.SecretsScanResults...); err != nil {
117117
return
118118
}
119119
}
120120
if utils.IsScanRequested(cmdType, utils.IacScan, params.RequestedScans...) {
121-
if err = parser.ParseIacs(targetResults.ScanTarget, false, targetResults.JasResultsNew.JasVulnerabilities.IacScanResults...); err != nil {
121+
if err = parser.ParseIacs(targetResults.ScanTarget, false, targetResults.JasResults.JasVulnerabilities.IacScanResults...); err != nil {
122122
return
123123
}
124124
}
125125
if utils.IsScanRequested(cmdType, utils.SastScan, params.RequestedScans...) {
126-
if err = parser.ParseSast(targetResults.ScanTarget, false, targetResults.JasResultsNew.JasVulnerabilities.SastScanResults...); err != nil {
126+
if err = parser.ParseSast(targetResults.ScanTarget, false, targetResults.JasResults.JasVulnerabilities.SastScanResults...); err != nil {
127127
return
128128
}
129129
}
130130
}
131131

132132
// Parsing JAS violations results
133-
if targetResults.JasResultsNew != nil && targetResults.JasResultsNew.JasViolations != nil && params.HasViolationContext { // TODO eran VERIFY if the last condition is needed
133+
if targetResults.JasResults != nil && targetResults.JasResults.JasViolations != nil && params.HasViolationContext { // TODO eran VERIFY if the last condition is needed
134134
if utils.IsScanRequested(cmdType, utils.SecretsScan, params.RequestedScans...) {
135-
if err = parser.ParseSecrets(targetResults.ScanTarget, true, targetResults.JasResultsNew.JasViolations.SecretsScanResults...); err != nil {
135+
if err = parser.ParseSecrets(targetResults.ScanTarget, true, targetResults.JasResults.JasViolations.SecretsScanResults...); err != nil {
136136
return
137137
}
138138
}
139139
if utils.IsScanRequested(cmdType, utils.IacScan, params.RequestedScans...) {
140-
if err = parser.ParseIacs(targetResults.ScanTarget, true, targetResults.JasResultsNew.JasViolations.IacScanResults...); err != nil {
140+
if err = parser.ParseIacs(targetResults.ScanTarget, true, targetResults.JasResults.JasViolations.IacScanResults...); err != nil {
141141
return
142142
}
143143
}
144144
if utils.IsScanRequested(cmdType, utils.SastScan, params.RequestedScans...) {
145-
if err = parser.ParseSast(targetResults.ScanTarget, true, targetResults.JasResultsNew.JasViolations.SastScanResults...); err != nil {
145+
if err = parser.ParseSast(targetResults.ScanTarget, true, targetResults.JasResults.JasViolations.SastScanResults...); err != nil {
146146
return
147147
}
148148
}
@@ -157,8 +157,8 @@ func parseScaResults[T interface{}](params ResultConvertParams, parser ResultsSt
157157
for _, scaResults := range targetScansResults.ScaResults.XrayResults {
158158
actualTarget := getScaScanTarget(targetScansResults.ScaResults, targetScansResults.ScanTarget)
159159
var applicableRuns []*sarif.Run
160-
if jasEntitled && targetScansResults.JasResultsNew != nil && targetScansResults.JasResultsNew.JasVulnerabilities != nil {
161-
applicableRuns = targetScansResults.JasResultsNew.JasVulnerabilities.ApplicabilityScanResults
160+
if jasEntitled && targetScansResults.JasResults != nil && targetScansResults.JasResults.JasVulnerabilities != nil {
161+
applicableRuns = targetScansResults.JasResults.JasVulnerabilities.ApplicabilityScanResults
162162
}
163163
if params.IncludeVulnerabilities {
164164
if err = parser.ParseScaVulnerabilities(actualTarget, scaResults, applicableRuns...); err != nil {

0 commit comments

Comments
 (0)