From e8065eceef4b0f80df3097e918aa9410192ccf08 Mon Sep 17 00:00:00 2001 From: Aiden Wang Date: Sun, 22 May 2022 08:24:12 +0000 Subject: [PATCH] issue #1908 bug fixes --- checks/evaluation/security_policy.go | 21 +++++---------------- checks/evaluation/security_policy_test.go | 2 +- checks/security_policy_test.go | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/checks/evaluation/security_policy.go b/checks/evaluation/security_policy.go index 1b949bfb761..fe894314562 100644 --- a/checks/evaluation/security_policy.go +++ b/checks/evaluation/security_policy.go @@ -32,33 +32,22 @@ func SecurityPolicy(name string, dl checker.DetailLogger, r *checker.SecurityPol return checker.CreateMinScoreResult(name, "security policy file not detected") } - orgFlag := false - msg := checker.LogMessage{} for _, f := range r.Files { - msg = checker.LogMessage{ + msg := checker.LogMessage{ Path: f.Path, Type: f.Type, Offset: f.Offset, } if msg.Type == checker.FileTypeURL { msg.Text = "security policy detected in org global repo" - if orgFlag == false { - // in case there are multiple security policies in the org repo - // so that we don't need to set the flag to true everytime - orgFlag = true - } + dl.Info(&msg) } else { - // security policy detected in repo, return earlier since it has higher priority + // security policy detected in repo, return immediately since it has higher priority msg.Text = "security policy file detected in current repo" dl.Info(&msg) return checker.CreateMaxScoreResult(name, "security policy file detected in current repo") } } - - if orgFlag == true { - dl.Info(&msg) - return checker.CreateMaxScoreResult(name, "security policy file detected in org global repo") - } else { - return checker.CreateMinScoreResult(name, "security policy file not detected") - } + // if not returned yet - indicating there is only an org global repo policy + return checker.CreateMaxScoreResult(name, "security policy file detected in org global repo") } diff --git a/checks/evaluation/security_policy_test.go b/checks/evaluation/security_policy_test.go index 3c2c7b266f2..2c6c2df1957 100644 --- a/checks/evaluation/security_policy_test.go +++ b/checks/evaluation/security_policy_test.go @@ -74,7 +74,7 @@ func TestSecurityPolicy(t *testing.T) { { name: "test_security_policy_4", args: args{ - name: "test_security_policy_3", + name: "test_security_policy_4", r: &checker.SecurityPolicyData{ Files: []checker.File{ { diff --git a/checks/security_policy_test.go b/checks/security_policy_test.go index e4d12dc521d..c1698047cc1 100644 --- a/checks/security_policy_test.go +++ b/checks/security_policy_test.go @@ -113,6 +113,29 @@ func TestSecurityPolicy(t *testing.T) { NumberOfInfo: 1, }, }, + { + name: "pass_case_testing_case_insensitive", + files: []string{ + "dOCs/SeCuRIty.rsT", + }, + want: scut.TestReturn{ + Score: 10, + NumberOfInfo: 1, + }, + }, + // { + // // this case is expected to get a zero score since it's not a security policy file + // // however, it triggers a segmentation violation error + // // TODO: to be reported in future issues + // name: "fail_case_not_a_security_policy", + // files: []string{ + // "not_a_security_policy.go", + // }, + // want: scut.TestReturn{ + // Score: 0, + // NumberOfInfo: 0, + // }, + // }, } for _, tt := range tests { tt := tt