Skip to content

Commit

Permalink
Make paths absolute in GetSourceRoots
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi committed Sep 10, 2023
1 parent 5539ea4 commit fcab887
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ require (

replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20230906115540-2c3c91d271d6

replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20230905120411-62d1bdd4eb38
replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20230907115821-300055da003e

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.2.6-0.20230418122323-2bf299dd6d27
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jedib0t/go-pretty/v6 v6.4.7 h1:lwiTJr1DEkAgzljsUsORmWsVn5MQjt1BPJdPCtJ6KXE=
github.com/jedib0t/go-pretty/v6 v6.4.7/go.mod h1:Ndk3ase2CkQbXLLNf5QDHoYb6J9WtVfmHZu9n8rk2xs=
github.com/jfrog/build-info-go v1.8.9-0.20230905120411-62d1bdd4eb38 h1:XyAcwWP2a6a5RL861gkfgQ7MUaQ7mmDkUVoD6kMtUtQ=
github.com/jfrog/build-info-go v1.8.9-0.20230905120411-62d1bdd4eb38/go.mod h1:QEskae5fQpjeY2PBzsjWtUQVskYSNDF2sSmw/Gx44dQ=
github.com/jfrog/build-info-go v1.8.9-0.20230907115821-300055da003e h1:m2XFar8L02NwUoG66rZzVwLopgfxoeOAvOca7bIFtTw=
github.com/jfrog/build-info-go v1.8.9-0.20230907115821-300055da003e/go.mod h1:QEskae5fQpjeY2PBzsjWtUQVskYSNDF2sSmw/Gx44dQ=
github.com/jfrog/gofrog v1.3.0 h1:o4zgsBZE4QyDbz2M7D4K6fXPTBJht+8lE87mS9bw7Gk=
github.com/jfrog/gofrog v1.3.0/go.mod h1:IFMc+V/yf7rA5WZ74CSbXe+Lgf0iApEQLxRZVzKRUR0=
github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYLipdsOFMY=
Expand Down
12 changes: 8 additions & 4 deletions xray/commands/audit/jas/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,19 @@ func ShouldSkipScanner(module jfrogappsconfig.Module, scanType utils.JasScanType
return false
}

func GetSourceRoots(module jfrogappsconfig.Module, scanner *jfrogappsconfig.Scanner) []string {
func GetSourceRoots(module jfrogappsconfig.Module, scanner *jfrogappsconfig.Scanner) ([]string, error) {
root, err := filepath.Abs(module.SourceRoot)
if err != nil {
return []string{}, errorutils.CheckError(err)
}
if scanner == nil || len(scanner.WorkingDirs) == 0 {
return []string{module.SourceRoot}
return []string{root}, errorutils.CheckError(err)
}
var roots []string
for _, workingDir := range scanner.WorkingDirs {
roots = append(roots, filepath.Join(module.SourceRoot, workingDir))
roots = append(roots, filepath.Join(root, workingDir))
}
return roots
return roots, nil
}

func GetExcludePatterns(module jfrogappsconfig.Module, scanner *jfrogappsconfig.Scanner) []string {
Expand Down
15 changes: 13 additions & 2 deletions xray/commands/audit/jas/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,22 @@ var getSourceRootsCases = []struct {
}

func TestGetSourceRoots(t *testing.T) {
module := jfrogappsconfig.Module{SourceRoot: "source-root"}
testGetSourceRoots(t, "source-root")
}

func TestGetSourceRootsEmptySourceRoot(t *testing.T) {
testGetSourceRoots(t, "")
}

func testGetSourceRoots(t *testing.T, sourceRoot string) {
sourceRoot, err := filepath.Abs(sourceRoot)
assert.NoError(t, err)
module := jfrogappsconfig.Module{SourceRoot: sourceRoot}
for _, testCase := range getSourceRootsCases {
t.Run("", func(t *testing.T) {
scanner := testCase.scanner
actualSourceRoots := GetSourceRoots(module, scanner)
actualSourceRoots, err := GetSourceRoots(module, scanner)
assert.NoError(t, err)
if scanner == nil {
assert.ElementsMatch(t, []string{module.SourceRoot}, actualSourceRoots)
return
Expand Down
6 changes: 5 additions & 1 deletion xray/commands/audit/jas/iac/iacscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,14 @@ type iacScanConfiguration struct {
}

func (iac *IacScanManager) createConfigFile(module jfrogappsconfig.Module) error {
roots, err := jas.GetSourceRoots(module, module.Scanners.Iac)
if err != nil {
return err
}
configFileContent := iacScanConfig{
Scans: []iacScanConfiguration{
{
Roots: jas.GetSourceRoots(module, module.Scanners.Iac),
Roots: roots,
Output: iac.scanner.ResultsFileName,
Type: iacScannerType,
SkippedDirs: jas.GetExcludePatterns(module, module.Scanners.Iac),
Expand Down
6 changes: 5 additions & 1 deletion xray/commands/audit/jas/sast/sastscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@ func (ssm *SastScanManager) createConfigFile(module jfrogappsconfig.Module) erro
if sastScanner == nil {
sastScanner = &jfrogappsconfig.SastScanner{}
}
roots, err := jas.GetSourceRoots(module, &sastScanner.Scanner)
if err != nil {
return err
}
configFileContent := sastScanConfig{
Scans: []scanConfiguration{
{
Roots: jas.GetSourceRoots(module, &sastScanner.Scanner),
Roots: roots,
Languages: []string{sastScanner.Language},
ExcludedRules: sastScanner.ExcludedRules,
ExcludePatterns: jas.GetExcludePatterns(module, &sastScanner.Scanner),
Expand Down
6 changes: 5 additions & 1 deletion xray/commands/audit/jas/secrets/secretsscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ type secretsScanConfiguration struct {
}

func (s *SecretScanManager) createConfigFile(module jfrogappsconfig.Module) error {
roots, err := jas.GetSourceRoots(module, module.Scanners.Secrets)
if err != nil {
return err
}
configFileContent := secretsScanConfig{
Scans: []secretsScanConfiguration{
{
Roots: jas.GetSourceRoots(module, module.Scanners.Iac),
Roots: roots,
Output: s.scanner.ResultsFileName,
Type: secretsScannerType,
SkippedDirs: jas.GetExcludePatterns(module, module.Scanners.Secrets),
Expand Down

0 comments on commit fcab887

Please sign in to comment.