Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions checks/evaluation/ci_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func CITests(name string, c *checker.CITestData, dl checker.DetailLogger) checke
if !foundCI {
// Log message says commit, but really we only care about PRs, and
// use only one commit (branch HEAD) to refer to all commits in a PR
dl.Debug(&checker.LogMessage{
Text: fmt.Sprintf("merged PR without CI test at HEAD: %s", r.HeadSHA),
dl.Info(&checker.LogMessage{
Text: fmt.Sprintf("merged PR %d without CI test at sha: %s", r.PullRequestNumber, r.HeadSHA),
})
}
}
Expand Down
11 changes: 5 additions & 6 deletions clients/gitlabrepo/checkruns.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package gitlabrepo

import (
"fmt"
"strings"

"github.com/xanzy/go-gitlab"

Expand Down Expand Up @@ -46,12 +45,12 @@ func (handler *checkrunsHandler) listCheckRunsForRef(ref string) ([]clients.Chec
func checkRunsFrom(data []*gitlab.PipelineInfo, ref string) []clients.CheckRun {
var checkRuns []clients.CheckRun
for _, pipelineInfo := range data {
if strings.EqualFold(pipelineInfo.Ref, ref) {
if pipelineInfo.SHA == ref {
// TODO: Can get more info from GitLab API here (e.g. pipeline name, URL)
// https://docs.gitlab.com/ee/api/pipelines.html#get-a-pipelines-test-report
checkRuns = append(checkRuns, clients.CheckRun{
Status: pipelineInfo.Status,
Conclusion: "",
URL: pipelineInfo.WebURL,
App: clients.CheckRunApp{Slug: pipelineInfo.Source},
Status: pipelineInfo.Status,
URL: pipelineInfo.WebURL,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion clients/gitlabrepo/statuses.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func statusFromData(commitStatuses []*gitlab.CommitStatus) []clients.Status {
for _, commitStatus := range commitStatuses {
statuses = append(statuses, clients.Status{
State: commitStatus.Status,
Context: fmt.Sprint(commitStatus.ID),
Context: commitStatus.Name,
URL: commitStatus.TargetURL,
TargetURL: commitStatus.TargetURL,
})
Expand Down
3 changes: 2 additions & 1 deletion docs/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ Risk: `Low` (possible unknown vulnerabilities)

This check tries to determine if the project runs tests before pull requests are
merged. It is currently limited to repositories hosted on GitHub, and does not
support other source hosting repositories (i.e., Forges).
support other source hosting repositories (i.e., Forges). All commits that are
part of a PR must be tested by a CI Test for the check to pass.

Running tests helps developers catch mistakes early on, which can reduce the
number of vulnerabilities that find their way into a project.
Expand Down
60 changes: 60 additions & 0 deletions e2e/ci_tests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package e2e

import (
"context"
"os"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -24,6 +25,7 @@ import (
"github.com/ossf/scorecard/v4/checks"
"github.com/ossf/scorecard/v4/clients"
"github.com/ossf/scorecard/v4/clients/githubrepo"
"github.com/ossf/scorecard/v4/clients/gitlabrepo"
scut "github.com/ossf/scorecard/v4/utests"
)

Expand Down Expand Up @@ -101,5 +103,63 @@ var _ = Describe("E2E TEST:"+checks.CheckCITests, func() {
Expect(scut.ValidateTestReturn(nil, "CI tests run", &expected, &result, &dl)).Should(BeTrue())
Expect(repoClient.Close()).Should(BeNil())
})
It("Should return use of CI tests at commit - GitLab", func() {
skipIfTokenIsNot(gitlabPATTokenType, "GitLab only")

dl := scut.TestDetailLogger{}
repo, err := gitlabrepo.MakeGitlabRepo("gitlab.com/gitlab-org/gitlab")
Expect(err).Should(BeNil())
repoClient, err := gitlabrepo.CreateGitlabClientWithToken(context.Background(), os.Getenv("GITLAB_AUTH_TOKEN"), repo)
Expect(err).Should(BeNil())
// url to commit is https://gitlab.com/gitlab-org/gitlab/-/commit/8ae23fa220d73fa07501aabd94214c9e83fe61a0
err = repoClient.InitRepo(repo, "8ae23fa220d73fa07501aabd94214c9e83fe61a0", 0)
Expect(err).Should(BeNil())
req := checker.CheckRequest{
Ctx: context.Background(),
RepoClient: repoClient,
Repo: repo,
Dlogger: &dl,
}
expected := scut.TestReturn{
Error: nil,
Score: 0,
NumberOfWarn: 0,
NumberOfInfo: 0,
NumberOfDebug: 13,
}
result := checks.CITests(&req)
Expect(result.Score).Should(BeNumerically("==", expected.Score))
Expect(result.Error).Should(BeNil())
Expect(repoClient.Close()).Should(BeNil())
})
It("Should return use of CI tests at commit - GitLab", func() {
skipIfTokenIsNot(gitlabPATTokenType, "GitLab only")

dl := scut.TestDetailLogger{}
repo, err := gitlabrepo.MakeGitlabRepo("gitlab.com/fdroid/fdroidclient")
Expect(err).Should(BeNil())
repoClient, err := gitlabrepo.CreateGitlabClientWithToken(context.Background(), os.Getenv("GITLAB_AUTH_TOKEN"), repo)
Expect(err).Should(BeNil())
// url to commit is https://gitlab.com/fdroid/fdroidclient/-/commit/a1d33881902cee33586a4fd4ee1538042a7bdedf
err = repoClient.InitRepo(repo, "a1d33881902cee33586a4fd4ee1538042a7bdedf", 0)
Expect(err).Should(BeNil())
req := checker.CheckRequest{
Ctx: context.Background(),
RepoClient: repoClient,
Repo: repo,
Dlogger: &dl,
}
expected := scut.TestReturn{
Error: nil,
Score: 2,
NumberOfWarn: 0,
NumberOfInfo: 0,
NumberOfDebug: 1,
}
result := checks.CITests(&req)
Expect(result.Score).Should(BeNumerically("==", expected.Score))
Expect(result.Error).Should(BeNil())
Expect(repoClient.Close()).Should(BeNil())
})
})
})
30 changes: 30 additions & 0 deletions e2e/sast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package e2e

import (
"context"
"os"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -24,6 +25,7 @@ import (
"github.com/ossf/scorecard/v4/checks"
"github.com/ossf/scorecard/v4/clients"
"github.com/ossf/scorecard/v4/clients/githubrepo"
"github.com/ossf/scorecard/v4/clients/gitlabrepo"
scut "github.com/ossf/scorecard/v4/utests"
)

Expand Down Expand Up @@ -54,5 +56,33 @@ var _ = Describe("E2E TEST:"+checks.CheckSAST, func() {
Expect(scut.ValidateTestReturn(nil, "sast used", &expected, &result, &dl)).Should(BeTrue())
Expect(repoClient.Close()).Should(BeNil())
})
It("Should return use of SAST tools - GitLab", func() {
skipIfTokenIsNot(gitlabPATTokenType, "GitLab only")

dl := scut.TestDetailLogger{}
repo, err := gitlabrepo.MakeGitlabRepo("gitlab.com/ossf-tests/airflow")
Expect(err).Should(BeNil())
repoClient, err := gitlabrepo.CreateGitlabClientWithToken(context.Background(), os.Getenv("GITLAB_AUTH_TOKEN"), repo)
Expect(err).Should(BeNil())
err = repoClient.InitRepo(repo, clients.HeadSHA, 0)
Expect(err).Should(BeNil())
req := checker.CheckRequest{
Ctx: context.Background(),
RepoClient: repoClient,
Repo: repo,
Dlogger: &dl,
}
expected := scut.TestReturn{
Error: nil,
Score: 0,
NumberOfWarn: 2,
NumberOfInfo: 0,
NumberOfDebug: 0,
}
result := checks.SAST(&req)
// New version.
Expect(scut.ValidateTestReturn(nil, "sast used", &expected, &result, &dl)).Should(BeTrue())
Expect(repoClient.Close()).Should(BeNil())
})
})
})