Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Update message for org-level security policy files #1939

Merged
merged 35 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d53af1c
modified checks/evaluation/security_policy.go (issue #1908)
May 19, 2022
0b6a12c
Merge branch 'main' into issue1908
May 20, 2022
74e0e50
Merge branch 'ossf:main' into issue1908
aidenwang9867 May 20, 2022
ca8f16b
Merge branch 'issue1908' of https://github.com/aidenwang9867/scorecar…
May 20, 2022
08e8b48
issue #1908 fixing temp save 05202022
May 21, 2022
bfbb387
Merge branch 'main' into issue1908
May 21, 2022
21fab62
Merge branch 'ossf:main' into issue1908
aidenwang9867 May 21, 2022
fa32f2c
Merge branch 'issue1908' of https://github.com/aidenwang9867/scorecar…
May 21, 2022
e8065ec
issue #1908 bug fixes
May 22, 2022
36ff709
Merge branch 'ossf:main' into issue1908
aidenwang9867 May 22, 2022
af8019c
Merge branch 'main' into issue1908
aidenwang9867 May 23, 2022
2255b84
debug comments deletion
May 23, 2022
4a78687
minor midifications
May 24, 2022
14e9415
Merge branch 'main' into issue1908
May 24, 2022
1daf61e
Merge branch 'issue1908' into issue1908add
May 24, 2022
fb7ff0e
temp save 0524-1
May 24, 2022
1e6ace6
Merge branch 'ossf:main' into issue1908add
aidenwang9867 May 24, 2022
9fe5ac8
Merge branch 'issue1908add' of https://github.com/aidenwang9867/score…
May 24, 2022
08b11c6
temp save 0524-2
May 24, 2022
e15309a
Merge branch 'issue1908add' into issue1908
May 24, 2022
c3f340a
Merge branch 'ossf:main' into issue1908
aidenwang9867 May 24, 2022
ef17336
Merge branch 'issue1908' of https://github.com/aidenwang9867/scorecar…
May 24, 2022
053283b
bug fix #1908
May 24, 2022
925797b
Merge branch 'main' into issue1908
May 24, 2022
eeb4bde
bug fix #1908 (2)
May 24, 2022
9d7a48e
bug fix #1908 (3)
May 24, 2022
6e4765c
#1908
May 25, 2022
49d4800
Merge remote-tracking branch 'origin/main' into issue1908
May 25, 2022
eed9854
merge from upstream/main & minor changes
May 25, 2022
c8e5a96
minor changes -2
May 25, 2022
99581f3
Merge branch 'main' into issue1908
laurentsimon May 25, 2022
a459ac2
Merge branch 'ossf:main' into issue1908
aidenwang9867 May 25, 2022
0196433
Update security_policy.go
aidenwang9867 May 25, 2022
e870c10
Update security_policy.go
aidenwang9867 May 25, 2022
57722f1
Update security_policy.go (linter error fix)
aidenwang9867 May 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions checks/evaluation/security_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func SecurityPolicy(name string, dl checker.DetailLogger, r *checker.SecurityPol

// Apply the policy evaluation.
if r.Files == nil || len(r.Files) == 0 {
// If the file is null or has zero lengths, directly return as not detected.
return checker.CreateMinScoreResult(name, "security policy file not detected")
}

Expand All @@ -39,11 +40,11 @@ func SecurityPolicy(name string, dl checker.DetailLogger, r *checker.SecurityPol
}
if msg.Type == checker.FileTypeURL {
msg.Text = "security policy detected in org repo"

} else {
msg.Text = "security policy detected"
msg.Text = "security policy detected in current repo"
}
dl.Info(&msg)
}

return checker.CreateMaxScoreResult(name, "security policy file detected")
aidenwang9867 marked this conversation as resolved.
Show resolved Hide resolved
}
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
40 changes: 27 additions & 13 deletions checks/raw/security_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package raw
import (
"errors"
"fmt"
"path"
"strings"

"github.com/ossf/scorecard/v4/checker"
Expand All @@ -27,17 +28,24 @@ import (
"github.com/ossf/scorecard/v4/log"
)

type securityPolicyFilesWithURI struct {
uri string
files []checker.File
}

// SecurityPolicy checks for presence of security policy.
func SecurityPolicy(c *checker.CheckRequest) (checker.SecurityPolicyData, error) {
files := make([]checker.File, 0)
err := fileparser.OnAllFilesDo(c.RepoClient, isSecurityPolicyFile, &files)
data := securityPolicyFilesWithURI{
uri: "",
laurentsimon marked this conversation as resolved.
Show resolved Hide resolved
files: make([]checker.File, 0),
}
err := fileparser.OnAllFilesDo(c.RepoClient, isSecurityPolicyFile, &data)
if err != nil {
return checker.SecurityPolicyData{}, err
}

// If we found files in the repo, return immediately.
if len(files) > 0 {
return checker.SecurityPolicyData{Files: files}, nil
if len(data.files) > 0 {
return checker.SecurityPolicyData{Files: data.files}, nil
}

// Check if present in parent org.
Expand All @@ -49,8 +57,8 @@ func SecurityPolicy(c *checker.CheckRequest) (checker.SecurityPolicyData, error)
switch {
case err == nil:
defer dotGitHubClient.Close()

err = fileparser.OnAllFilesDo(dotGitHubClient, isSecurityPolicyFile, &files)
data.uri = dotGitHubClient.URI()
err = fileparser.OnAllFilesDo(dotGitHubClient, isSecurityPolicyFile, &data)
if err != nil {
return checker.SecurityPolicyData{}, err
}
Expand All @@ -62,7 +70,7 @@ func SecurityPolicy(c *checker.CheckRequest) (checker.SecurityPolicyData, error)
}

// Return raw results.
return checker.SecurityPolicyData{Files: files}, nil
return checker.SecurityPolicyData{Files: data.files}, nil
}

// Check repository for repository-specific policy.
Expand All @@ -71,14 +79,20 @@ var isSecurityPolicyFile fileparser.DoWhileTrueOnFilename = func(name string, ar
if len(args) != 1 {
return false, fmt.Errorf("isSecurityPolicyFile requires exactly one argument: %w", errInvalidArgLength)
}
pfiles, ok := args[0].(*[]checker.File)
pdata, ok := args[0].(*securityPolicyFilesWithURI)
if !ok {
return false, fmt.Errorf("isSecurityPolicyFile expects arg of type: *[]checker.File: %w", errInvalidArgType)
return false, fmt.Errorf("invalid arg type: %w", errInvalidArgType)
}
if isSecurityPolicyFilename(name) {
*pfiles = append(*pfiles, checker.File{
Path: name,
Type: checker.FileTypeSource,
tempPath := name
tempType := checker.FileTypeSource
if pdata.uri != "" {
tempPath = path.Join(pdata.uri, tempPath)
tempType = checker.FileTypeURL
}
pdata.files = append(pdata.files, checker.File{
Path: tempPath,
Type: tempType,
Offset: checker.OffsetDefault,
})
return false, nil
Expand Down
10 changes: 10 additions & 0 deletions checks/security_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ func TestSecurityPolicy(t *testing.T) {
NumberOfInfo: 1,
},
},
{
name: "Pass Case: Case-insensitive testing",
files: []string{
"dOCs/SeCuRIty.rsT",
},
want: scut.TestReturn{
Score: 10,
NumberOfInfo: 1,
},
},
}
for _, tt := range tests {
tt := tt
Expand Down