From 31bd848a463e4a1303ea5828e5e32e1f96f693a2 Mon Sep 17 00:00:00 2001 From: Azeem Shaikh Date: Fri, 4 Mar 2022 08:39:12 -0800 Subject: [PATCH] Mark `License`, `Security-Policy` as commit-based --- checks/license.go | 1 + checks/security_policy.go | 1 + e2e/license_test.go | 28 +++++++++++++++++ e2e/security_policy_test.go | 60 +++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+) diff --git a/checks/license.go b/checks/license.go index 0bd19ebde3d..a3b242f27c8 100644 --- a/checks/license.go +++ b/checks/license.go @@ -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 diff --git a/checks/security_policy.go b/checks/security_policy.go index 7aa2b588826..0505a58cf6e 100644 --- a/checks/security_policy.go +++ b/checks/security_policy.go @@ -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. diff --git a/e2e/license_test.go b/e2e/license_test.go index c19ab68a611..f70bd2f0356 100644 --- a/e2e/license_test.go +++ b/e2e/license_test.go @@ -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()) }) diff --git a/e2e/security_policy_test.go b/e2e/security_policy_test.go index 96e83becbb4..b1cdcd78642 100644 --- a/e2e/security_policy_test.go +++ b/e2e/security_policy_test.go @@ -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") @@ -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,