Skip to content

Commit

Permalink
Add e2e tests for remaining checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
inferno-chromium authored and naveensrinivasan committed Jan 15, 2021
1 parent bcaa2e7 commit c00aa4b
Show file tree
Hide file tree
Showing 14 changed files with 314 additions and 7 deletions.
4 changes: 2 additions & 2 deletions checks/active.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
var lookbackDays int = 90

func init() {
registerCheck("Active", PeriodicCommits)
registerCheck("Active", IsActive)
}

func PeriodicCommits(c checker.Checker) checker.CheckResult {
func IsActive(c checker.Checker) checker.CheckResult {
commits, _, err := c.Client.Repositories.ListCommits(c.Ctx, c.Owner, c.Repo, &github.CommitsListOptions{})
if err != nil {
return checker.RetryResult(err)
Expand Down
4 changes: 2 additions & 2 deletions checks/cii_best_practices.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (
)

func init() {
registerCheck("CII-Best-Practices", CiiBestPractices)
registerCheck("CII-Best-Practices", CIIBestPractices)
}

type response struct {
BadgeLevel string `json:"badge_level"`
}

func CiiBestPractices(c checker.Checker) checker.CheckResult {
func CIIBestPractices(c checker.Checker) checker.CheckResult {
repoUrl := fmt.Sprintf("https://github.com/%s/%s", c.Owner, c.Repo)
url := fmt.Sprintf("https://bestpractices.coreinfrastructure.org/projects.json?url=%s", repoUrl)
resp, err := c.HttpClient.Get(url)
Expand Down
9 changes: 8 additions & 1 deletion checks/sast.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ import (
var sastTools map[string]bool = map[string]bool{"github-code-scanning": true, "sonarcloud": true}

func init() {
registerCheck("SAST", checker.MultiCheck(CodeQLInCheckDefinitions, SASTToolInCheckRuns))
registerCheck("SAST", SAST)
}

func SAST(c checker.Checker) checker.CheckResult {
return checker.MultiCheck(
CodeQLInCheckDefinitions,
SASTToolInCheckRuns,
)(c)
}

func SASTToolInCheckRuns(c checker.Checker) checker.CheckResult {
Expand Down
30 changes: 30 additions & 0 deletions e2e/active_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package e2e

import (
"context"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/ossf/scorecard/checker"
"github.com/ossf/scorecard/checks"
)

var _ = Describe("E2E TEST:Active", func() {
Context("E2E TEST:Validating active status", func() {
It("Should return valid active status", func() {
l := log{}
checker := checker.Checker{
Ctx: context.Background(),
Client: ghClient,
HttpClient: client,
Owner: "apache",
Repo: "airflow",
GraphClient: graphClient,
Logf: l.Logf,
}
result := checks.IsActive(checker)
Expect(result.Error).Should(BeNil())
Expect(result.Pass).Should(BeTrue())
})
})
})
30 changes: 30 additions & 0 deletions e2e/ci_tests_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package e2e

import (
"context"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/ossf/scorecard/checker"
"github.com/ossf/scorecard/checks"
)

var _ = Describe("E2E TEST:CITests", func() {
Context("E2E TEST:Validating use of CI tests", func() {
It("Should return use of CI tests", func() {
l := log{}
checker := checker.Checker{
Ctx: context.Background(),
Client: ghClient,
HttpClient: client,
Owner: "apache",
Repo: "airflow",
GraphClient: graphClient,
Logf: l.Logf,
}
result := checks.CITests(checker)
Expect(result.Error).Should(BeNil())
Expect(result.Pass).Should(BeTrue())
})
})
})
30 changes: 30 additions & 0 deletions e2e/cii_best_practices_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package e2e

import (
"context"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/ossf/scorecard/checker"
"github.com/ossf/scorecard/checks"
)

var _ = Describe("E2E TEST:CIIBestPractices", func() {
Context("E2E TEST:Validating use of CII Best Practices", func() {
It("Should return use of CII Best Practices", func() {
l := log{}
checker := checker.Checker{
Ctx: context.Background(),
Client: ghClient,
HttpClient: client,
Owner: "tensorflow",
Repo: "tensorflow",
GraphClient: graphClient,
Logf: l.Logf,
}
result := checks.CIIBestPractices(checker)
Expect(result.Error).Should(BeNil())
Expect(result.Pass).Should(BeTrue())
})
})
})
30 changes: 30 additions & 0 deletions e2e/code_review_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package e2e

import (
"context"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/ossf/scorecard/checker"
"github.com/ossf/scorecard/checks"
)

var _ = Describe("E2E TEST:CodeReview", func() {
Context("E2E TEST:Validating use of code reviews", func() {
It("Should return use of code reviews", func() {
l := log{}
checker := checker.Checker{
Ctx: context.Background(),
Client: ghClient,
HttpClient: client,
Owner: "apache",
Repo: "airflow",
GraphClient: graphClient,
Logf: l.Logf,
}
result := checks.DoesCodeReview(checker)
Expect(result.Error).Should(BeNil())
Expect(result.Pass).Should(BeTrue())
})
})
})
30 changes: 30 additions & 0 deletions e2e/contributors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package e2e

import (
"context"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/ossf/scorecard/checker"
"github.com/ossf/scorecard/checks"
)

var _ = Describe("E2E TEST:CodeReview", func() {
Context("E2E TEST:Validating project contributors", func() {
It("Should return valid project contributors", func() {
l := log{}
checker := checker.Checker{
Ctx: context.Background(),
Client: ghClient,
HttpClient: client,
Owner: "apache",
Repo: "airflow",
GraphClient: graphClient,
Logf: l.Logf,
}
result := checks.Contributors(checker)
Expect(result.Error).Should(BeNil())
Expect(result.Pass).Should(BeTrue())
})
})
})
30 changes: 30 additions & 0 deletions e2e/frozen_deps_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package e2e

import (
"context"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/ossf/scorecard/checker"
"github.com/ossf/scorecard/checks"
)

var _ = Describe("E2E TEST:FrozenDeps", func() {
Context("E2E TEST:Validating deps are frozen", func() {
It("Should return deps are frozen", func() {
l := log{}
checker := checker.Checker{
Ctx: context.Background(),
Client: ghClient,
HttpClient: client,
Owner: "tensorflow",
Repo: "tensorflow",
GraphClient: graphClient,
Logf: l.Logf,
}
result := checks.FrozenDeps(checker)
Expect(result.Error).Should(BeNil())
Expect(result.Pass).Should(BeTrue())
})
})
})
30 changes: 30 additions & 0 deletions e2e/fuzzing_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package e2e

import (
"context"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/ossf/scorecard/checker"
"github.com/ossf/scorecard/checks"
)

var _ = Describe("E2E TEST:Fuzzing", func() {
Context("E2E TEST:Validating use of fuzzing tools", func() {
It("Should return use of fuzzing tools", func() {
l := log{}
checker := checker.Checker{
Ctx: context.Background(),
Client: ghClient,
HttpClient: client,
Owner: "tensorflow",
Repo: "tensorflow",
GraphClient: graphClient,
Logf: l.Logf,
}
result := checks.Fuzzing(checker)
Expect(result.Error).Should(BeNil())
Expect(result.Pass).Should(BeTrue())
})
})
})
4 changes: 2 additions & 2 deletions e2e/packaging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

var _ = Describe("E2E TEST:Packaging", func() {
Context("E2E TEST:Validating packaging", func() {
It("Should return valid packaging workflow", func() {
Context("E2E TEST:Validating use of packaging in CI/CD", func() {
It("Should return use of packaging in CI/CD", func() {
l := log{}
checker := checker.Checker{
Ctx: context.Background(),
Expand Down
30 changes: 30 additions & 0 deletions e2e/pull_requests_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package e2e

import (
"context"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/ossf/scorecard/checker"
"github.com/ossf/scorecard/checks"
)

var _ = Describe("E2E TEST:PullRequests", func() {
Context("E2E TEST:Validating use of pull requests", func() {
It("Should return use of pull requests", func() {
l := log{}
checker := checker.Checker{
Ctx: context.Background(),
Client: ghClient,
HttpClient: client,
Owner: "apache",
Repo: "airflow",
GraphClient: graphClient,
Logf: l.Logf,
}
result := checks.PullRequests(checker)
Expect(result.Error).Should(BeNil())
Expect(result.Pass).Should(BeTrue())
})
})
})
30 changes: 30 additions & 0 deletions e2e/sast_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package e2e

import (
"context"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/ossf/scorecard/checker"
"github.com/ossf/scorecard/checks"
)

var _ = Describe("E2E TEST:SAST", func() {
Context("E2E TEST:Validating use of SAST tools", func() {
It("Should return use of SAST tools", func() {
l := log{}
checker := checker.Checker{
Ctx: context.Background(),
Client: ghClient,
HttpClient: client,
Owner: "apache",
Repo: "airflow",
GraphClient: graphClient,
Logf: l.Logf,
}
result := checks.SAST(checker)
Expect(result.Error).Should(BeNil())
Expect(result.Pass).Should(BeTrue())
})
})
})
30 changes: 30 additions & 0 deletions e2e/security_policy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package e2e

import (
"context"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/ossf/scorecard/checker"
"github.com/ossf/scorecard/checks"
)

var _ = Describe("E2E TEST:SecurityPolicy", func() {
Context("E2E TEST:Validating security policy", func() {
It("Should return valid security policy", func() {
l := log{}
checker := checker.Checker{
Ctx: context.Background(),
Client: ghClient,
HttpClient: client,
Owner: "tensorflow",
Repo: "tensorflow",
GraphClient: graphClient,
Logf: l.Logf,
}
result := checks.SecurityPolicy(checker)
Expect(result.Error).Should(BeNil())
Expect(result.Pass).Should(BeTrue())
})
})
})

0 comments on commit c00aa4b

Please sign in to comment.