Skip to content

Commit

Permalink
Mark License, Security-Policy as commit-based (#1711)
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 Mar 4, 2022
1 parent 3c92dec commit 241b0f4
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions checks/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const CheckLicense = "License"
func init() {
supportedRequestTypes := []checker.RequestType{
checker.FileBased,
checker.CommitBased,
}
if err := registerCheck(CheckLicense, LicenseCheck, supportedRequestTypes); err != nil {
// this should never happen
Expand Down
1 change: 1 addition & 0 deletions checks/security_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const CheckSecurityPolicy = "Security-Policy"
func init() {
supportedRequestTypes := []checker.RequestType{
checker.FileBased,
checker.CommitBased,
}
if err := registerCheck(CheckSecurityPolicy, SecurityPolicy, supportedRequestTypes); err != nil {
// This should never happen.
Expand Down
28 changes: 28 additions & 0 deletions e2e/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,34 @@ var _ = Describe("E2E TEST:"+checks.CheckLicense, func() {
Expect(result.Error).Should(BeNil())
Expect(result.Pass).Should(BeTrue())

Expect(scut.ValidateTestReturn(nil, "license found", &expected, &result,
&dl)).Should(BeTrue())
})
It("Should return license check works at commitSHA", func() {
dl := scut.TestDetailLogger{}
repo, err := githubrepo.MakeGithubRepo("ossf-tests/scorecard-check-license-e2e")
Expect(err).Should(BeNil())
repoClient := githubrepo.CreateGithubRepoClient(context.Background(), logger)
err = repoClient.InitRepo(repo, "c3a8778e73ea95f937c228a34ee57d5e006f7304")
Expect(err).Should(BeNil())
req := checker.CheckRequest{
Ctx: context.Background(),
RepoClient: repoClient,
Repo: repo,
Dlogger: &dl,
}
expected := scut.TestReturn{
Error: nil,
Score: checker.MaxResultScore,
NumberOfWarn: 0,
NumberOfInfo: 1,
NumberOfDebug: 0,
}
result := checks.LicenseCheck(&req)

Expect(result.Error).Should(BeNil())
Expect(result.Pass).Should(BeTrue())

Expect(scut.ValidateTestReturn(nil, "license found", &expected, &result,
&dl)).Should(BeTrue())
})
Expand Down
60 changes: 60 additions & 0 deletions e2e/security_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,36 @@ var _ = Describe("E2E TEST:"+checks.CheckSecurityPolicy, func() {
Expect(scut.ValidateTestReturn(nil, "policy found", &expected, &result, &dl)).Should(BeTrue())
Expect(repoClient.Close()).Should(BeNil())
})
It("Should return valid security policy at commitSHA", func() {
dl := scut.TestDetailLogger{}
repo, err := githubrepo.MakeGithubRepo("tensorflow/tensorflow")
Expect(err).Should(BeNil())
repoClient := githubrepo.CreateGithubRepoClient(context.Background(), logger)
err = repoClient.InitRepo(repo, "e0cb70344e46276b37d65824f95eca478080de4a")
Expect(err).Should(BeNil())

req := checker.CheckRequest{
Ctx: context.Background(),
RepoClient: repoClient,
Repo: repo,
Dlogger: &dl,
}
expected := scut.TestReturn{
Error: nil,
Score: checker.MaxResultScore,
NumberOfWarn: 0,
NumberOfInfo: 1,
NumberOfDebug: 0,
}
result := checks.SecurityPolicy(&req)
// UPGRADEv2: to remove.
// Old version.
Expect(result.Error).Should(BeNil())
Expect(result.Pass).Should(BeTrue())
// New version.
Expect(scut.ValidateTestReturn(nil, "policy found", &expected, &result, &dl)).Should(BeTrue())
Expect(repoClient.Close()).Should(BeNil())
})
It("Should return valid security policy for rust repositories", func() {
dl := scut.TestDetailLogger{}
repo, err := githubrepo.MakeGithubRepo("randombit/botan")
Expand All @@ -66,6 +96,36 @@ var _ = Describe("E2E TEST:"+checks.CheckSecurityPolicy, func() {
err = repoClient.InitRepo(repo, clients.HeadSHA)
Expect(err).Should(BeNil())

req := checker.CheckRequest{
Ctx: context.Background(),
RepoClient: repoClient,
Repo: repo,
Dlogger: &dl,
}
expected := scut.TestReturn{
Error: nil,
Score: checker.MaxResultScore,
NumberOfWarn: 0,
NumberOfInfo: 1,
NumberOfDebug: 0,
}
result := checks.SecurityPolicy(&req)
// UPGRADEv2: to remove.
// Old version.
Expect(result.Error).Should(BeNil())
Expect(result.Pass).Should(BeTrue())
// New version.
Expect(scut.ValidateTestReturn(nil, "policy found", &expected, &result, &dl)).Should(BeTrue())
Expect(repoClient.Close()).Should(BeNil())
})
It("Should return valid security policy for rust repositories at commitSHA", func() {
dl := scut.TestDetailLogger{}
repo, err := githubrepo.MakeGithubRepo("randombit/botan")
Expect(err).Should(BeNil())
repoClient := githubrepo.CreateGithubRepoClient(context.Background(), logger)
err = repoClient.InitRepo(repo, "bab40cdd29d19e0638cf1301dfd355c52b94d1c0")
Expect(err).Should(BeNil())

req := checker.CheckRequest{
Ctx: context.Background(),
RepoClient: repoClient,
Expand Down

0 comments on commit 241b0f4

Please sign in to comment.