Skip to content

Commit

Permalink
issue #1908 bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiden Wang committed May 22, 2022
1 parent fa32f2c commit e8065ec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
21 changes: 5 additions & 16 deletions checks/evaluation/security_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion checks/evaluation/security_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down
23 changes: 23 additions & 0 deletions checks/security_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e8065ec

Please sign in to comment.