Skip to content

Commit a1e908b

Browse files
Support Security-Policy with --local (#1822)
Co-authored-by: Azeem Shaikh <azeems@google.com>
1 parent 5860896 commit a1e908b

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

checks/raw/security_policy.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import (
2929

3030
// SecurityPolicy checks for presence of security policy.
3131
func SecurityPolicy(c *checker.CheckRequest) (checker.SecurityPolicyData, error) {
32-
// TODO: not supported for local clients.
33-
3432
files := make([]checker.File, 0)
3533
err := fileparser.OnAllFilesDo(c.RepoClient, isSecurityPolicyFile, &files)
3634
if err != nil {
@@ -42,7 +40,14 @@ func SecurityPolicy(c *checker.CheckRequest) (checker.SecurityPolicyData, error)
4240
return checker.SecurityPolicyData{Files: files}, nil
4341
}
4442

45-
// https://docs.github.com/en/github/building-a-strong-community/creating-a-default-community-health-file.
43+
// Check if present in parent org.
44+
parentOrg := c.Repo.Org()
45+
if parentOrg == nil {
46+
return checker.SecurityPolicyData{}, nil
47+
}
48+
49+
// https#://docs.github.com/en/github/building-a-strong-community/creating-a-default-community-health-file.
50+
// TODO(1491): Make this non-GitHub specific.
4651
logger := log.NewLogger(log.InfoLevel)
4752
dotGitHubClient := githubrepo.CreateGithubRepoClient(c.Ctx, logger)
4853
err = dotGitHubClient.InitRepo(c.Repo.Org(), clients.HeadSHA)

checks/raw/security_policy_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,25 @@ func TestSecurityPolicy(t *testing.T) {
9999
"doc/security.rst",
100100
},
101101
},
102+
{
103+
name: "early return if org is null",
104+
files: []string{},
105+
},
102106
}
103107
for _, tt := range tests {
104108
tt := tt
105109
t.Run(tt.name, func(t *testing.T) {
106110
t.Parallel()
107111
ctrl := gomock.NewController(t)
108-
mockRepo := mockrepo.NewMockRepoClient(ctrl)
112+
mockRepoClient := mockrepo.NewMockRepoClient(ctrl)
113+
mockRepo := mockrepo.NewMockRepo(ctrl)
109114

110-
mockRepo.EXPECT().ListFiles(gomock.Any()).Return(tt.files, nil).AnyTimes()
115+
mockRepoClient.EXPECT().ListFiles(gomock.Any()).Return(tt.files, nil).AnyTimes()
116+
mockRepo.EXPECT().Org().Return(nil).AnyTimes()
111117
dl := scut.TestDetailLogger{}
112118
c := checker.CheckRequest{
113-
RepoClient: mockRepo,
119+
RepoClient: mockRepoClient,
120+
Repo: mockRepo,
114121
Dlogger: &dl,
115122
}
116123

0 commit comments

Comments
 (0)