Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func processFlags(rootCmd *cobra.Command) error {
}

// Apply all flag mappings immediately
engineConfigVar.ScanConfig.WithValidation = validateVar
engineConfigVar.WithValidation = validateVar
if len(customRegexRuleVar) > 0 {
engineConfigVar.CustomRegexPatterns = customRegexRuleVar
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestProcessFlags(t *testing.T) {
t.Run("ValidateVarMapping", func(t *testing.T) {
// Reset global variables
validateVar = false
engineConfigVar.ScanConfig.WithValidation = false
engineConfigVar.WithValidation = false

// Set test value
validateVar = true
Expand All @@ -137,7 +137,7 @@ func TestProcessFlags(t *testing.T) {
processFlags(rootCmd)

// Verify mapping
assert.Equal(t, validateVar, engineConfigVar.ScanConfig.WithValidation, "validateVar should be mapped to engineConfigVar.ScanConfig.WithValidation")
assert.Equal(t, validateVar, engineConfigVar.WithValidation, "validateVar should be mapped to engineConfigVar.WithValidation")
})

t.Run("IgnoreListProcessing", func(t *testing.T) {
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestProcessFlags(t *testing.T) {

// Verify all mappings
assert.Equal(t, customRegexRuleVar, engineConfigVar.CustomRegexPatterns, "Custom regex patterns should be mapped")
assert.Equal(t, validateVar, engineConfigVar.ScanConfig.WithValidation, "Validation flag should be mapped")
assert.Equal(t, validateVar, engineConfigVar.WithValidation, "Validation flag should be mapped")
assert.Equal(t, []string{"ignored-rule"}, engineConfigVar.IgnoreList, "IgnoreList should be preserved")
assert.Equal(t, 50, engineConfigVar.MaxTargetMegabytes, "MaxTargetMegabytes should be preserved")
})
Expand All @@ -181,7 +181,7 @@ func TestProcessFlags(t *testing.T) {
validateVar = false
engineConfigVar.IgnoreList = []string{}
engineConfigVar.CustomRegexPatterns = []string{}
engineConfigVar.ScanConfig.WithValidation = false
engineConfigVar.WithValidation = false

// Process flags
rootCmd := &cobra.Command{Use: "test"}
Expand All @@ -190,7 +190,7 @@ func TestProcessFlags(t *testing.T) {

// Verify empty values are handled correctly
assert.Empty(t, engineConfigVar.CustomRegexPatterns, "Empty custom regex patterns should remain empty")
assert.False(t, engineConfigVar.ScanConfig.WithValidation, "Validation should be false by default")
assert.False(t, engineConfigVar.WithValidation, "Validation should be false by default")
assert.Empty(t, engineConfigVar.IgnoreList, "Empty ignore list should remain empty")
})
}
Expand Down Expand Up @@ -220,7 +220,7 @@ max-target-megabytes: 10`
processFlags(rootCmd)

// Verify CLI values take precedence
assert.True(t, engineConfigVar.ScanConfig.WithValidation, "CLI validate flag should override config file")
assert.True(t, engineConfigVar.WithValidation, "CLI validate flag should override config file")
assert.Equal(t, zerolog.DebugLevel, log.Logger.GetLevel(), "CLI log level should override config file")
})
}
Expand Down
5 changes: 1 addition & 4 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/checkmarx/2ms/v5/engine"
"github.com/checkmarx/2ms/v5/engine/rules/ruledefine"
"github.com/checkmarx/2ms/v5/internal/resources"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -44,9 +43,7 @@ func TestPreRun(t *testing.T) {
stdoutFormatVar: "json",
reportPath: []string{"mock.json"},
engineConfigVar: engine.EngineConfig{
ScanConfig: resources.ScanConfig{
WithValidation: true,
},
WithValidation: true,
},
expectedPreRunErr: nil,
},
Expand Down
13 changes: 6 additions & 7 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/checkmarx/2ms/v5/engine/score"
"github.com/checkmarx/2ms/v5/engine/semaphore"
"github.com/checkmarx/2ms/v5/engine/validation"
"github.com/checkmarx/2ms/v5/internal/resources"
"github.com/checkmarx/2ms/v5/internal/workerpool"
"github.com/checkmarx/2ms/v5/lib/reporting"
"github.com/checkmarx/2ms/v5/lib/secrets"
Expand Down Expand Up @@ -88,7 +87,7 @@ type Engine struct {

Report reporting.IReport

ScanConfig resources.ScanConfig
WithValidation bool

wg conc.WaitGroup

Expand Down Expand Up @@ -151,7 +150,7 @@ type EngineConfig struct {

CustomRules []*ruledefine.Rule

ScanConfig resources.ScanConfig
WithValidation bool
}

type EngineOption func(*Engine)
Expand Down Expand Up @@ -185,7 +184,7 @@ func initEngine(engineConfig *EngineConfig, opts ...EngineOption) (*Engine, erro
return nil, ErrNoRulesSelected
}

scorer := score.NewScorer(finalRules, engineConfig.ScanConfig.WithValidation)
scorer := score.NewScorer(finalRules, engineConfig.WithValidation)

fileWalkerWorkerPoolSize := defaultDetectorWorkerPoolSize
if engineConfig.DetectorWorkerPoolSize > 0 {
Expand Down Expand Up @@ -217,7 +216,7 @@ func initEngine(engineConfig *EngineConfig, opts ...EngineOption) (*Engine, erro
ignoredIds: &engineConfig.IgnoredIds,
allowedValues: &engineConfig.AllowedValues,

ScanConfig: engineConfig.ScanConfig,
WithValidation: engineConfig.WithValidation,

secretsChan: make(chan *secrets.Secret, runtime.GOMAXPROCS(0)),
secretsExtrasChan: make(chan *secrets.Secret, runtime.GOMAXPROCS(0)),
Expand Down Expand Up @@ -703,7 +702,7 @@ func (e *Engine) consumeItems(pluginName string) {
}

func (e *Engine) processSecrets() {
if e.ScanConfig.WithValidation {
if e.WithValidation {
e.processSecretsWithValidation()
} else {
e.processSecretsWithoutValidation()
Expand Down Expand Up @@ -756,7 +755,7 @@ func (e *Engine) processEvaluationWithoutValidation() {

// processSecretsEvaluation evaluates the secret's validationStatus, Severity and CVSS score
func (e *Engine) processSecretsEvaluation() {
if e.ScanConfig.WithValidation {
if e.WithValidation {
e.processEvaluationWithValidation()
} else {
e.processEvaluationWithoutValidation()
Expand Down
13 changes: 4 additions & 9 deletions engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/checkmarx/2ms/v5/engine/chunk"
"github.com/checkmarx/2ms/v5/engine/rules"
"github.com/checkmarx/2ms/v5/engine/semaphore"
"github.com/checkmarx/2ms/v5/internal/resources"
"github.com/checkmarx/2ms/v5/lib/secrets"
"github.com/checkmarx/2ms/v5/plugins"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -939,9 +938,7 @@ func TestProcessItems(t *testing.T) {
func TestProcessSecrets(t *testing.T) {
t.Run("Validate flag is enabled", func(t *testing.T) {
instance, err := initEngine(&EngineConfig{
ScanConfig: resources.ScanConfig{
WithValidation: true,
},
WithValidation: true,
})
assert.NoError(t, err)
secretsChan := instance.secretsChan
Expand Down Expand Up @@ -993,9 +990,7 @@ func TestProcessSecrets(t *testing.T) {
})
t.Run("Validate flag is disabled", func(t *testing.T) {
instance, err := initEngine(&EngineConfig{
ScanConfig: resources.ScanConfig{
WithValidation: false,
},
WithValidation: false,
})
assert.NoError(t, err)
secretsChan := instance.secretsChan
Expand Down Expand Up @@ -1207,8 +1202,8 @@ func TestProcessEvaluationWithValidation(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
instance, err := initEngine(
&EngineConfig{
ScanConfig: resources.ScanConfig{WithValidation: true},
CustomRules: tt.customRules},
WithValidation: true,
CustomRules: tt.customRules},
)
assert.NoError(t, err)
validationChan := instance.GetValidationCh()
Expand Down
17 changes: 0 additions & 17 deletions internal/resources/scanner.go

This file was deleted.

11 changes: 5 additions & 6 deletions pkg/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"sync"

"github.com/checkmarx/2ms/v5/internal/resources"
"github.com/checkmarx/2ms/v5/plugins"
"github.com/rs/zerolog/log"
"github.com/sourcegraph/conc"
Expand All @@ -17,7 +16,7 @@ import (

type scanner struct {
engineInstance engine.IEngine
scanConfig resources.ScanConfig
scanConfig ScanConfig
mu sync.RWMutex
}

Expand All @@ -33,7 +32,7 @@ func NewScanner() Scanner {
return &scanner{}
}

func (s *scanner) Reset(scanConfig *resources.ScanConfig, opts ...engine.EngineOption) error {
func (s *scanner) Reset(scanConfig *ScanConfig, opts ...engine.EngineOption) error {
s.mu.Lock()
defer s.mu.Unlock()

Expand All @@ -45,7 +44,7 @@ func (s *scanner) Reset(scanConfig *resources.ScanConfig, opts ...engine.EngineO
MaxFindings: scanConfig.MaxFindings,
MaxRuleMatchesPerFragment: scanConfig.MaxRuleMatchesPerFragment,
MaxSecretSize: scanConfig.MaxSecretSize,
ScanConfig: *scanConfig,
WithValidation: scanConfig.WithValidation,
}, opts...)
if err != nil {
return fmt.Errorf("error initializing engine: %w", err)
Expand All @@ -57,7 +56,7 @@ func (s *scanner) Reset(scanConfig *resources.ScanConfig, opts ...engine.EngineO
return nil
}

func (s *scanner) Scan(scanItems []ScanItem, scanConfig *resources.ScanConfig, opts ...engine.EngineOption) (reporting.IReport, error) {
func (s *scanner) Scan(scanItems []ScanItem, scanConfig *ScanConfig, opts ...engine.EngineOption) (reporting.IReport, error) {
var wg conc.WaitGroup
err := s.Reset(scanConfig, opts...)
if err != nil {
Expand Down Expand Up @@ -109,7 +108,7 @@ func (s *scanner) Scan(scanItems []ScanItem, scanConfig *resources.ScanConfig, o

func (s *scanner) ScanDynamic(
itemsIn <-chan ScanItem,
scanConfig *resources.ScanConfig,
scanConfig *ScanConfig,
opts ...engine.EngineOption,
) (reporting.IReport, error) {
var wg conc.WaitGroup
Expand Down
Loading
Loading