Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion checks/dangerous_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const CheckDangerousWorkflow = "Dangerous-Workflow"
//nolint:gochecknoinits
func init() {
supportedRequestTypes := []checker.RequestType{
checker.FileBased,
checker.CommitBased,
checker.FileBased,
}
if err := registerCheck(CheckDangerousWorkflow, DangerousWorkflow, supportedRequestTypes); err != nil {
// this should never happen
Expand Down
5 changes: 4 additions & 1 deletion checks/fuzzing.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ const CheckFuzzing = "Fuzzing"

//nolint:gochecknoinits
func init() {
if err := registerCheck(CheckFuzzing, Fuzzing, nil); err != nil {
supportedRequestTypes := []checker.RequestType{
checker.FileBased,
}
if err := registerCheck(CheckFuzzing, Fuzzing, supportedRequestTypes); err != nil {
// this should never happen
panic(err)
}
Expand Down
1 change: 1 addition & 0 deletions checks/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const CheckLicense = "License"
func init() {
supportedRequestTypes := []checker.RequestType{
checker.CommitBased,
checker.FileBased,
}
if err := registerCheck(CheckLicense, License, supportedRequestTypes); err != nil {
// this should never happen
Expand Down
23 changes: 20 additions & 3 deletions checks/packaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"github.com/ossf/scorecard/v5/checks/raw/gitlab"
"github.com/ossf/scorecard/v5/clients/githubrepo"
"github.com/ossf/scorecard/v5/clients/gitlabrepo"
"github.com/ossf/scorecard/v5/clients/localdir"
sce "github.com/ossf/scorecard/v5/errors"
"github.com/ossf/scorecard/v5/probes"
"github.com/ossf/scorecard/v5/probes/zrunner"
Expand All @@ -31,18 +32,34 @@

//nolint:gochecknoinits
func init() {
if err := registerCheck(CheckPackaging, Packaging, nil); err != nil {
supportedRequestTypes := []checker.RequestType{
checker.FileBased,
}
if err := registerCheck(CheckPackaging, Packaging, supportedRequestTypes); err != nil {
// this should never happen
panic(err)
}
}

// Packaging runs Packaging check.
func Packaging(c *checker.CheckRequest) checker.CheckResult {
var rawData checker.PackagingData
var err error
var rawData, rawDataGithub, rawDataGitlab checker.PackagingData
var err, errGithub, errGitlab error

Check warning on line 47 in checks/packaging.go

View check run for this annotation

Codecov / codecov/patch

checks/packaging.go#L46-L47

Added lines #L46 - L47 were not covered by tests

switch v := c.RepoClient.(type) {
case *localdir.Client:
// Performing both packaging checks since we dont know when local
rawDataGithub, errGithub = github.Packaging(c)
rawDataGitlab, errGitlab = gitlab.Packaging(c)
// Appending results of checks
rawData.Packages = append(rawData.Packages, rawDataGithub.Packages...)
rawData.Packages = append(rawData.Packages, rawDataGitlab.Packages...)
// checking for errors
if errGithub != nil {
err = errGithub
} else if errGitlab != nil {
err = errGitlab
}

Check warning on line 62 in checks/packaging.go

View check run for this annotation

Codecov / codecov/patch

checks/packaging.go#L50-L62

Added lines #L50 - L62 were not covered by tests
case *githubrepo.Client:
rawData, err = github.Packaging(c)
case *gitlabrepo.Client:
Expand Down
2 changes: 1 addition & 1 deletion checks/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const CheckTokenPermissions = "Token-Permissions"
//nolint:gochecknoinits
func init() {
supportedRequestTypes := []checker.RequestType{
checker.FileBased,
checker.CommitBased,
checker.FileBased,
}
if err := registerCheck(CheckTokenPermissions, TokenPermissions, supportedRequestTypes); err != nil {
// This should never happen.
Expand Down
2 changes: 1 addition & 1 deletion checks/pinned_dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const CheckPinnedDependencies = "Pinned-Dependencies"
//nolint:gochecknoinits
func init() {
supportedRequestTypes := []checker.RequestType{
checker.FileBased,
checker.CommitBased,
checker.FileBased,
}
if err := registerCheck(CheckPinnedDependencies, PinningDependencies, supportedRequestTypes); err != nil {
// This should never happen.
Expand Down
10 changes: 10 additions & 0 deletions checks/raw/fuzzing.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@
numLangs := len(langs)
if numLangs == 0 {
return nil
} else if len(langs) == 1 && langs[0].Name == clients.All {
return getAllLanguages()

Check warning on line 342 in checks/raw/fuzzing.go

View check run for this annotation

Codecov / codecov/patch

checks/raw/fuzzing.go#L342

Added line #L342 was not covered by tests
}
totalLoC := 0
// Use a map to record languages and their lines of code to drop potential duplicates.
Expand All @@ -361,6 +363,14 @@
return ret
}

func getAllLanguages() []clients.LanguageName {
allLanguages := make([]clients.LanguageName, 0, len(languageFuzzSpecs))
for l := range languageFuzzSpecs {
allLanguages = append(allLanguages, l)
}
return allLanguages

Check warning on line 371 in checks/raw/fuzzing.go

View check run for this annotation

Codecov / codecov/patch

checks/raw/fuzzing.go#L366-L371

Added lines #L366 - L371 were not covered by tests
}

func propertyBasedDescription(language string) *string {
s := fmt.Sprintf("Property-based testing in %s generates test instances randomly or exhaustively "+
"and test that specific properties are satisfied.", language)
Expand Down
9 changes: 8 additions & 1 deletion checks/raw/github/packaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package github

import (
"errors"
"fmt"
"io"
"path/filepath"
Expand All @@ -23,6 +24,7 @@

"github.com/ossf/scorecard/v5/checker"
"github.com/ossf/scorecard/v5/checks/fileparser"
"github.com/ossf/scorecard/v5/clients"
"github.com/ossf/scorecard/v5/finding"
)

Expand Down Expand Up @@ -73,7 +75,12 @@

runs, err := c.RepoClient.ListSuccessfulWorkflowRuns(filepath.Base(fp))
if err != nil {
return data, fmt.Errorf("Client.Actions.ListWorkflowRunsByFileName: %w", err)
// assume the workflow will have run for localdir client
if errors.Is(err, clients.ErrUnsupportedFeature) {
runs = append(runs, clients.WorkflowRun{})
} else {
return data, fmt.Errorf("Client.Actions.ListWorkflowRunsByFileName: %w", err)
}

Check warning on line 83 in checks/raw/github/packaging.go

View check run for this annotation

Codecov / codecov/patch

checks/raw/github/packaging.go#L78-L83

Added lines #L78 - L83 were not covered by tests
}

if len(runs) > 0 {
Expand Down
5 changes: 5 additions & 0 deletions checks/raw/sast.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

"github.com/ossf/scorecard/v5/checker"
"github.com/ossf/scorecard/v5/checks/fileparser"
"github.com/ossf/scorecard/v5/clients"
sce "github.com/ossf/scorecard/v5/errors"
"github.com/ossf/scorecard/v5/finding"
)
Expand Down Expand Up @@ -92,6 +93,10 @@
var sastCommits []checker.SASTCommit
commits, err := c.RepoClient.ListCommits()
if err != nil {
// ignoring check for local dir
if errors.Is(err, clients.ErrUnsupportedFeature) {
return sastCommits, nil
}

Check warning on line 99 in checks/raw/sast.go

View check run for this annotation

Codecov / codecov/patch

checks/raw/sast.go#L98-L99

Added lines #L98 - L99 were not covered by tests
return sastCommits,
sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("RepoClient.ListCommits: %v", err))
}
Expand Down
5 changes: 4 additions & 1 deletion checks/sast.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ const CheckSAST = "SAST"

//nolint:gochecknoinits
func init() {
if err := registerCheck(CheckSAST, SAST, nil); err != nil {
supportedRequestTypes := []checker.RequestType{
checker.FileBased,
}
if err := registerCheck(CheckSAST, SAST, supportedRequestTypes); err != nil {
// This should never happen.
panic(err)
}
Expand Down
1 change: 1 addition & 0 deletions checks/security_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const CheckSecurityPolicy = "Security-Policy"
func init() {
supportedRequestTypes := []checker.RequestType{
checker.CommitBased,
checker.FileBased,
}
if err := registerCheck(CheckSecurityPolicy, SecurityPolicy, supportedRequestTypes); err != nil {
// This should never happen.
Expand Down
57 changes: 29 additions & 28 deletions clients/localdir/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
)

var (
_ clients.RepoClient = &localDirClient{}
_ clients.RepoClient = &Client{}
errInputRepoType = errors.New("input repo should be of type repoLocal")
)

//nolint:govet
type localDirClient struct {
type Client struct {
logger *log.Logger
ctx context.Context
path string
Expand All @@ -50,7 +50,7 @@
}

// InitRepo sets up the local repo.
func (client *localDirClient) InitRepo(inputRepo clients.Repo, commitSHA string, commitDepth int) error {
func (client *Client) InitRepo(inputRepo clients.Repo, commitSHA string, commitDepth int) error {
localRepo, ok := inputRepo.(*Repo)
if !ok {
return fmt.Errorf("%w: %v", errInputRepoType, inputRepo)
Expand All @@ -66,12 +66,12 @@
}

// URI implements RepoClient.URI.
func (client *localDirClient) URI() string {
func (client *Client) URI() string {

Check warning on line 69 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L69

Added line #L69 was not covered by tests
return fmt.Sprintf("file://%s", client.path)
}

// IsArchived implements RepoClient.IsArchived.
func (client *localDirClient) IsArchived() (bool, error) {
func (client *Client) IsArchived() (bool, error) {

Check warning on line 74 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L74

Added line #L74 was not covered by tests
return false, fmt.Errorf("IsArchived: %w", clients.ErrUnsupportedFeature)
}

Expand Down Expand Up @@ -148,7 +148,7 @@
}

// LocalPath implements RepoClient.LocalPath.
func (client *localDirClient) LocalPath() (string, error) {
func (client *Client) LocalPath() (string, error) {

Check warning on line 151 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L151

Added line #L151 was not covered by tests
clientPath, err := filepath.Abs(client.path)
if err != nil {
return "", fmt.Errorf("error during filepath.Abs: %w", err)
Expand All @@ -157,7 +157,7 @@
}

// ListFiles implements RepoClient.ListFiles.
func (client *localDirClient) ListFiles(predicate func(string) (bool, error)) ([]string, error) {
func (client *Client) ListFiles(predicate func(string) (bool, error)) ([]string, error) {
client.once.Do(func() {
client.files, client.errFiles = listFiles(client.path)
})
Expand All @@ -175,102 +175,103 @@
}

// GetFileReader implements RepoClient.GetFileReader.
func (client *localDirClient) GetFileReader(filename string) (io.ReadCloser, error) {
func (client *Client) GetFileReader(filename string) (io.ReadCloser, error) {

Check warning on line 178 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L178

Added line #L178 was not covered by tests
return getFile(client.path, filename)
}

// GetBranch implements RepoClient.GetBranch.
func (client *localDirClient) GetBranch(branch string) (*clients.BranchRef, error) {
func (client *Client) GetBranch(branch string) (*clients.BranchRef, error) {

Check warning on line 183 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L183

Added line #L183 was not covered by tests
return nil, fmt.Errorf("ListBranches: %w", clients.ErrUnsupportedFeature)
}

// GetDefaultBranch implements RepoClient.GetDefaultBranch.
func (client *localDirClient) GetDefaultBranch() (*clients.BranchRef, error) {
func (client *Client) GetDefaultBranch() (*clients.BranchRef, error) {

Check warning on line 188 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L188

Added line #L188 was not covered by tests
return nil, fmt.Errorf("GetDefaultBranch: %w", clients.ErrUnsupportedFeature)
}

// GetDefaultBranchName implements RepoClient.GetDefaultBranchName.
func (client *localDirClient) GetDefaultBranchName() (string, error) {
func (client *Client) GetDefaultBranchName() (string, error) {

Check warning on line 193 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L193

Added line #L193 was not covered by tests
return "", fmt.Errorf("GetDefaultBranchName: %w", clients.ErrUnsupportedFeature)
}

// ListCommits implements RepoClient.ListCommits.
func (client *localDirClient) ListCommits() ([]clients.Commit, error) {
func (client *Client) ListCommits() ([]clients.Commit, error) {
return nil, fmt.Errorf("ListCommits: %w", clients.ErrUnsupportedFeature)
}

// ListIssues implements RepoClient.ListIssues.
func (client *localDirClient) ListIssues() ([]clients.Issue, error) {
func (client *Client) ListIssues() ([]clients.Issue, error) {

Check warning on line 203 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L203

Added line #L203 was not covered by tests
return nil, fmt.Errorf("ListIssues: %w", clients.ErrUnsupportedFeature)
}

// ListReleases implements RepoClient.ListReleases.
func (client *localDirClient) ListReleases() ([]clients.Release, error) {
func (client *Client) ListReleases() ([]clients.Release, error) {

Check warning on line 208 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L208

Added line #L208 was not covered by tests
return nil, fmt.Errorf("ListReleases: %w", clients.ErrUnsupportedFeature)
}

// ListContributors implements RepoClient.ListContributors.
func (client *localDirClient) ListContributors() ([]clients.User, error) {
func (client *Client) ListContributors() ([]clients.User, error) {

Check warning on line 213 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L213

Added line #L213 was not covered by tests
return nil, fmt.Errorf("ListContributors: %w", clients.ErrUnsupportedFeature)
}

// ListSuccessfulWorkflowRuns implements RepoClient.WorkflowRunsByFilename.
func (client *localDirClient) ListSuccessfulWorkflowRuns(filename string) ([]clients.WorkflowRun, error) {
func (client *Client) ListSuccessfulWorkflowRuns(filename string) ([]clients.WorkflowRun, error) {

Check warning on line 218 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L218

Added line #L218 was not covered by tests
return nil, fmt.Errorf("ListSuccessfulWorkflowRuns: %w", clients.ErrUnsupportedFeature)
}

// ListCheckRunsForRef implements RepoClient.ListCheckRunsForRef.
func (client *localDirClient) ListCheckRunsForRef(ref string) ([]clients.CheckRun, error) {
func (client *Client) ListCheckRunsForRef(ref string) ([]clients.CheckRun, error) {

Check warning on line 223 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L223

Added line #L223 was not covered by tests
return nil, fmt.Errorf("ListCheckRunsForRef: %w", clients.ErrUnsupportedFeature)
}

// ListStatuses implements RepoClient.ListStatuses.
func (client *localDirClient) ListStatuses(ref string) ([]clients.Status, error) {
func (client *Client) ListStatuses(ref string) ([]clients.Status, error) {

Check warning on line 228 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L228

Added line #L228 was not covered by tests
return nil, fmt.Errorf("ListStatuses: %w", clients.ErrUnsupportedFeature)
}

// ListWebhooks implements RepoClient.ListWebhooks.
func (client *localDirClient) ListWebhooks() ([]clients.Webhook, error) {
func (client *Client) ListWebhooks() ([]clients.Webhook, error) {

Check warning on line 233 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L233

Added line #L233 was not covered by tests
return nil, fmt.Errorf("ListWebhooks: %w", clients.ErrUnsupportedFeature)
}

// Search implements RepoClient.Search.
func (client *localDirClient) Search(request clients.SearchRequest) (clients.SearchResponse, error) {
func (client *Client) Search(request clients.SearchRequest) (clients.SearchResponse, error) {

Check warning on line 238 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L238

Added line #L238 was not covered by tests
return clients.SearchResponse{}, fmt.Errorf("Search: %w", clients.ErrUnsupportedFeature)
}

// SearchCommits implements RepoClient.SearchCommits.
func (client *localDirClient) SearchCommits(request clients.SearchCommitsOptions) ([]clients.Commit, error) {
func (client *Client) SearchCommits(request clients.SearchCommitsOptions) ([]clients.Commit, error) {

Check warning on line 243 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L243

Added line #L243 was not covered by tests
return nil, fmt.Errorf("Search: %w", clients.ErrUnsupportedFeature)
}

func (client *localDirClient) Close() error {
func (client *Client) Close() error {

Check warning on line 247 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L247

Added line #L247 was not covered by tests
return nil
}

// ListProgrammingLanguages implements RepoClient.ListProgrammingLanguages.
// TODO: add ListProgrammingLanguages support for local directories.
func (client *localDirClient) ListProgrammingLanguages() ([]clients.Language, error) {
return nil, fmt.Errorf("ListProgrammingLanguages: %w", clients.ErrUnsupportedFeature)
func (client *Client) ListProgrammingLanguages() ([]clients.Language, error) {
// for now just return all programming languages
return []clients.Language{{Name: clients.All, NumLines: 1}}, nil

Check warning on line 255 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L253-L255

Added lines #L253 - L255 were not covered by tests
}

// ListLicenses implements RepoClient.ListLicenses.
// TODO: add ListLicenses support for local directories.
func (client *localDirClient) ListLicenses() ([]clients.License, error) {
func (client *Client) ListLicenses() ([]clients.License, error) {

Check warning on line 260 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L260

Added line #L260 was not covered by tests
return nil, fmt.Errorf("ListLicenses: %w", clients.ErrUnsupportedFeature)
}

func (client *localDirClient) GetCreatedAt() (time.Time, error) {
func (client *Client) GetCreatedAt() (time.Time, error) {

Check warning on line 264 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L264

Added line #L264 was not covered by tests
return time.Time{}, fmt.Errorf("GetCreatedAt: %w", clients.ErrUnsupportedFeature)
}

func (client *localDirClient) GetOrgRepoClient(ctx context.Context) (clients.RepoClient, error) {
func (client *Client) GetOrgRepoClient(ctx context.Context) (clients.RepoClient, error) {

Check warning on line 268 in clients/localdir/client.go

View check run for this annotation

Codecov / codecov/patch

clients/localdir/client.go#L268

Added line #L268 was not covered by tests
return nil, fmt.Errorf("GetOrgRepoClient: %w", clients.ErrUnsupportedFeature)
}

// CreateLocalDirClient returns a client which implements RepoClient interface.
func CreateLocalDirClient(ctx context.Context, logger *log.Logger) clients.RepoClient {
return &localDirClient{
return &Client{
ctx: ctx,
logger: logger,
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@
}

var requiredRequestTypes []checker.RequestType
// if local option not set add file based

Check warning on line 121 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L121

Added line #L121 was not covered by tests
if o.Local != "" {
requiredRequestTypes = append(requiredRequestTypes, checker.FileBased)
}
// if commit option set to anything other than HEAD add commit based
if !strings.EqualFold(o.Commit, clients.HeadSHA) {
requiredRequestTypes = append(requiredRequestTypes, checker.CommitBased)
}
Expand Down
2 changes: 1 addition & 1 deletion policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func TestGetEnabled(t *testing.T) {
name: "request types limit enabled checks",
argsChecks: []string{},
requiredRequestTypes: []checker.RequestType{checker.FileBased, checker.CommitBased},
expectedEnabledChecks: 5, // All checks which are FileBased and CommitBased
expectedEnabledChecks: 7, // All checks which are FileBased and CommitBased
expectedError: false,
},
{
Expand Down
Loading