Skip to content

Commit

Permalink
fix: result scope following testing (#1024)
Browse files Browse the repository at this point in the history
* fix: result scope following testing

* refactor: review

Co-authored-by: elsapet <elizabeth@bearer.sh>

* test: remove conflict due to parallelism

---------

Co-authored-by: elsapet <elizabeth@bearer.sh>
  • Loading branch information
didroe and elsapet committed May 31, 2023
1 parent 5e3dfcb commit 077a311
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion new/detector/composition/java/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (composition *Composition) DetectFromFileWithTypes(file *file.FileInfo, det
tree.RootNode(),
detectorType,
sanitizerRuleID,
settings.NESTED_SCOPE,
settings.DefaultScope,
false,
)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions new/detector/composition/java/java_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ var loggerRule []byte
var scopeRule []byte

func TestFlow(t *testing.T) {
t.Parallel()
testhelper.GetRunner(t, loggerRule, "Java").RunTest(t, "./testdata/testcases/flow", ".snapshots/flow/")
}

func TestScope(t *testing.T) {
t.Parallel()
testhelper.GetRunner(t, scopeRule, "Java").RunTest(t, "./testdata/scope", ".snapshots/")
}
2 changes: 1 addition & 1 deletion new/detector/composition/javascript/javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (composition *Composition) DetectFromFileWithTypes(file *file.FileInfo, det
tree.RootNode(),
detectorType,
sanitizerRuleID,
settings.NESTED_SCOPE,
settings.DefaultScope,
false,
)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions new/detector/composition/javascript/javascript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@ var deconstructingRule []byte
var scopeRule []byte

func TestFlow(t *testing.T) {
t.Parallel()
testhelper.GetRunner(t, datatypeRule, "Javascript").RunTest(t, "./testdata/testcases/flow", ".snapshots/flow/")
}

func TestObjectDeconstructing(t *testing.T) {
t.Parallel()
testhelper.GetRunner(t, deconstructingRule, "Javascript").RunTest(t, "./testdata/testcases/object-deconstructing", ".snapshots/object-deconstructing/")
}

func TestString(t *testing.T) {
t.Parallel()
testhelper.GetRunner(t, insecureURLRule, "Javascript").RunTest(t, "./testdata/testcases/string", ".snapshots/string/")
}

func TestScope(t *testing.T) {
t.Parallel()
testhelper.GetRunner(t, scopeRule, "Javascript").RunTest(t, "./testdata/scope", ".snapshots/")
}
2 changes: 1 addition & 1 deletion new/detector/composition/ruby/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (composition *Composition) DetectFromFileWithTypes(file *file.FileInfo, det
tree.RootNode(),
detectorType,
sanitizerRuleID,
settings.NESTED_SCOPE,
settings.DefaultScope,
false,
)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions new/detector/composition/ruby/ruby_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ var loggerRule []byte
var scopeRule []byte

func TestRuby(t *testing.T) {
t.Parallel()
testhelper.GetRunner(t, loggerRule, "Ruby").RunTest(t, "./testdata/testcases", ".snapshots/")
}

func TestScope(t *testing.T) {
t.Parallel()
testhelper.GetRunner(t, scopeRule, "Ruby").RunTest(t, "./testdata/scope", ".snapshots/")
}
2 changes: 1 addition & 1 deletion new/detector/evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (evaluator *evaluator) sanitizedNodeDetections(
scope settings.RuleReferenceScope,
) ([]*types.Detection, bool, error) {
if sanitizerDetectorType != "" {
sanitizerDetections, err := evaluator.nonUnifiedNodeDetections(node, sanitizerDetectorType, scope)
sanitizerDetections, err := evaluator.nonUnifiedNodeDetections(node, sanitizerDetectorType, settings.DefaultScope)
if len(sanitizerDetections) != 0 || err != nil {
return nil, true, err
}
Expand Down
4 changes: 2 additions & 2 deletions new/detector/implementation/custom/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (detector *customDetector) Name() string {

func (detector *customDetector) DetectAt(
node *tree.Node,
ruleReferenceType settings.RuleReferenceScope,
scope settings.RuleReferenceScope,
evaluator types.Evaluator,
) ([]interface{}, error) {
var detectionsData []interface{}
Expand All @@ -75,7 +75,7 @@ func (detector *customDetector) DetectAt(

for _, result := range results {
filtersMatch, datatypeDetections, variableNodes, err := matchAllFilters(
ruleReferenceType,
scope,
result,
evaluator,
pattern.Filters,
Expand Down
2 changes: 1 addition & 1 deletion new/detector/implementation/custom/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func matchFilter(

if filter.Detection != "" {
effectiveScope := filter.Scope
if scope == settings.RESULT_SCOPE {
if effectiveScope == settings.NESTED_SCOPE && scope == settings.RESULT_SCOPE {
effectiveScope = settings.RESULT_SCOPE
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/commands/process/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const (
CURSOR_SCOPE RuleReferenceScope = "cursor"
NESTED_SCOPE RuleReferenceScope = "nested"
RESULT_SCOPE RuleReferenceScope = "result"

DefaultScope = NESTED_SCOPE
)

type LoadRulesResult struct {
Expand Down

0 comments on commit 077a311

Please sign in to comment.