Skip to content

Commit

Permalink
Support Security-Policy with --local (#1822)
Browse files Browse the repository at this point in the history
Co-authored-by: Azeem Shaikh <[email protected]>
  • Loading branch information
azeemshaikh38 and azeemsgoogle authored Apr 7, 2022
1 parent 5860896 commit a1e908b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
11 changes: 8 additions & 3 deletions checks/raw/security_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (

// SecurityPolicy checks for presence of security policy.
func SecurityPolicy(c *checker.CheckRequest) (checker.SecurityPolicyData, error) {
// TODO: not supported for local clients.

files := make([]checker.File, 0)
err := fileparser.OnAllFilesDo(c.RepoClient, isSecurityPolicyFile, &files)
if err != nil {
Expand All @@ -42,7 +40,14 @@ func SecurityPolicy(c *checker.CheckRequest) (checker.SecurityPolicyData, error)
return checker.SecurityPolicyData{Files: files}, nil
}

// https://docs.github.com/en/github/building-a-strong-community/creating-a-default-community-health-file.
// Check if present in parent org.
parentOrg := c.Repo.Org()
if parentOrg == nil {
return checker.SecurityPolicyData{}, nil
}

// https#://docs.github.com/en/github/building-a-strong-community/creating-a-default-community-health-file.
// TODO(1491): Make this non-GitHub specific.
logger := log.NewLogger(log.InfoLevel)
dotGitHubClient := githubrepo.CreateGithubRepoClient(c.Ctx, logger)
err = dotGitHubClient.InitRepo(c.Repo.Org(), clients.HeadSHA)
Expand Down
13 changes: 10 additions & 3 deletions checks/raw/security_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,25 @@ func TestSecurityPolicy(t *testing.T) {
"doc/security.rst",
},
},
{
name: "early return if org is null",
files: []string{},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
mockRepo := mockrepo.NewMockRepoClient(ctrl)
mockRepoClient := mockrepo.NewMockRepoClient(ctrl)
mockRepo := mockrepo.NewMockRepo(ctrl)

mockRepo.EXPECT().ListFiles(gomock.Any()).Return(tt.files, nil).AnyTimes()
mockRepoClient.EXPECT().ListFiles(gomock.Any()).Return(tt.files, nil).AnyTimes()
mockRepo.EXPECT().Org().Return(nil).AnyTimes()
dl := scut.TestDetailLogger{}
c := checker.CheckRequest{
RepoClient: mockRepo,
RepoClient: mockRepoClient,
Repo: mockRepo,
Dlogger: &dl,
}

Expand Down

0 comments on commit a1e908b

Please sign in to comment.