Skip to content

Commit

Permalink
Merge branch 'main' into feat/renovdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
naveensrinivasan authored Jan 31, 2022
2 parents 27d125a + 3995d31 commit b3a64b8
Show file tree
Hide file tree
Showing 9 changed files with 550 additions and 288 deletions.
5 changes: 3 additions & 2 deletions checks/binary_artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestBinaryArtifacts(t *testing.T) {
}{
{
name: "Jar file",
inputFolder: "file://testdata/binaryartifacts/jars",
inputFolder: "testdata/binaryartifacts/jars",
err: nil,
expected: checker.CheckResult{
Score: 9,
Expand All @@ -46,7 +46,7 @@ func TestBinaryArtifacts(t *testing.T) {
},
{
name: "non binary file",
inputFolder: "file://testdata/licensedir/withlicense",
inputFolder: "testdata/licensedir/withlicense",
err: nil,
expected: checker.CheckResult{
Score: 10,
Expand All @@ -61,6 +61,7 @@ func TestBinaryArtifacts(t *testing.T) {

logger := log.NewLogger(log.DebugLevel)

// TODO: Use gMock instead of Localdir here.
ctrl := gomock.NewController(t)
repo, err := localdir.MakeLocalDirRepo(tt.inputFolder)

Expand Down
207 changes: 207 additions & 0 deletions checks/fileparser/github_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,210 @@ func TestIsGitHubOwnedAction(t *testing.T) {
})
}
}

// TestGetJobName tests the GetJobName function.
func TestGetJobName(t *testing.T) {
t.Parallel()
type args struct {
job *actionlint.Job
}
var name actionlint.String
name.Value = "foo"
tests := []struct {
name string
args args
want string
}{
{
name: "job name",
args: args{
job: &actionlint.Job{
Name: &name,
},
},
want: "foo",
},
{
name: "job name is empty",
args: args{
job: &actionlint.Job{},
},
want: "",
},
{
name: "job is nil",
args: args{},
want: "",
},
}
for _, tt := range tests {
tt := tt // Re-initializing variable so it is not changed while executing the closure below
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := GetJobName(tt.args.job); got != tt.want {
t.Errorf("GetJobName() = %v, want %v", got, tt.want)
}
})
}
}

func TestGetStepName(t *testing.T) {
t.Parallel()
type args struct {
step *actionlint.Step
}
var name actionlint.String
name.Value = "foo"
tests := []struct {
name string
args args
want string
}{
{
name: "step name",
args: args{
step: &actionlint.Step{
Name: &name,
},
},
want: "foo",
},
{
name: "step name is empty",
args: args{
step: &actionlint.Step{},
},
want: "",
},
{
name: "step is nil",
args: args{},
want: "",
},
}
for _, tt := range tests {
tt := tt // Re-initializing variable so it is not changed while executing the closure below
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := GetStepName(tt.args.step); got != tt.want {
t.Errorf("GetStepName() = %v, want %v", got, tt.want)
}
})
}
}

func TestIsStepExecKind(t *testing.T) {
t.Parallel()
type args struct {
step *actionlint.Step
kind actionlint.ExecKind
}
tests := []struct {
name string
args args
want bool
}{
{
name: "step is nil",
args: args{},
want: false,
},
}

for _, tt := range tests {
tt := tt // Re-initializing variable so it is not changed while executing the closure below
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := IsStepExecKind(tt.args.step, tt.args.kind); got != tt.want {
t.Errorf("IsStepExecKind() = %v, want %v", got, tt.want)
}
})
}
}

func TestGetLineNumber(t *testing.T) {
t.Parallel()
type args struct {
pos *actionlint.Pos
}
//nolint
tests := []struct {
name string
args args
want uint
}{
{
name: "line number",
args: args{
pos: &actionlint.Pos{
Line: 1,
},
},
want: 1,
},
{
name: "line number is empty",
args: args{
pos: &actionlint.Pos{
Line: 1,
},
},
want: 1,
},
{
name: "pos is nil",
args: args{},
want: 1,
},
}

for _, tt := range tests {
tt := tt // Re-initializing variable so it is not changed while executing the closure below
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := GetLineNumber(tt.args.pos); got != tt.want {
t.Errorf("GetLineNumber() = %v, want %v for %v", got, tt.want, tt.name)
}
})
}
}

func TestFormatActionlintError(t *testing.T) {
t.Parallel()
type args struct {
errs []*actionlint.Error
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "no errors",
args: args{
errs: []*actionlint.Error{},
},
wantErr: false,
},
{
name: "one error",
args: args{
errs: []*actionlint.Error{
{
Message: "foo",
},
},
},
wantErr: true,
},
}
for _, tt := range tests {
tt := tt // Re-initializing variable so it is not changed while executing the closure below
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if err := FormatActionlintError(tt.args.errs); (err != nil) != tt.wantErr {
t.Errorf("FormatActionlintError() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
5 changes: 3 additions & 2 deletions checks/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestLicenseFileSubdirectory(t *testing.T) {
}{
{
name: "With LICENSE",
inputFolder: "file://testdata/licensedir/withlicense",
inputFolder: "testdata/licensedir/withlicense",
expected: scut.TestReturn{
Error: nil,
Score: checker.MaxResultScore,
Expand All @@ -128,7 +128,7 @@ func TestLicenseFileSubdirectory(t *testing.T) {
},
{
name: "Without LICENSE",
inputFolder: "file://testdata/licensedir/withoutlicense",
inputFolder: "testdata/licensedir/withoutlicense",
expected: scut.TestReturn{
Error: nil,
Score: checker.MinResultScore,
Expand All @@ -143,6 +143,7 @@ func TestLicenseFileSubdirectory(t *testing.T) {

logger := log.NewLogger(log.DebugLevel)

// TODO: Use gMock instead of Localdir here.
ctrl := gomock.NewController(t)
repo, err := localdir.MakeLocalDirRepo(tt.inputFolder)

Expand Down
6 changes: 3 additions & 3 deletions clients/localdir/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ func TestClient_CreationAndCaching(t *testing.T) {
{
name: "invalid fullpath",
outputFiles: []string{},
inputFolder: "file:///invalid/fullpath",
inputFolder: "invalid/fullpath",
err: os.ErrNotExist,
},
{
name: "invalid relative path",
outputFiles: []string{},
inputFolder: "file://invalid/relative/path",
inputFolder: "invalid/relative/path",
err: os.ErrNotExist,
},
{
name: "repo 0",
outputFiles: []string{
"file0", "dir1/file1", "dir1/dir2/file2",
},
inputFolder: "file://testdata/repo0",
inputFolder: "testdata/repo0",
err: nil,
},
}
Expand Down
13 changes: 2 additions & 11 deletions clients/localdir/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,11 @@ import (
"fmt"
"os"
"path"
"strings"

clients "github.com/ossf/scorecard/v4/clients"
)

var (
errNotDirectory = errors.New("not a directory")
errInvalidURI = errors.New("invalid URI")
)

var filePrefix = "file://"
var errNotDirectory = errors.New("not a directory")

type repoLocal struct {
path string
Expand Down Expand Up @@ -78,10 +72,7 @@ func (r *repoLocal) AppendMetadata(m ...string) {

// MakeLocalDirRepo returns an implementation of clients.Repo interface.
func MakeLocalDirRepo(pathfn string) (clients.Repo, error) {
if !strings.HasPrefix(pathfn, filePrefix) {
return nil, fmt.Errorf("%w", errInvalidURI)
}
p := path.Clean(pathfn[len(filePrefix):])
p := path.Clean(pathfn)
repo := &repoLocal{
path: p,
}
Expand Down
30 changes: 30 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2020 Security Scorecard Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package cmd implements Scorecard commandline.
package cmd

var (
flagRepo string
flagLocal string
flagChecksToRun []string
flagMetadata []string
flagLogLevel string
flagFormat string
flagNPM string
flagPyPI string
flagRubyGems string
flagShowDetails bool
flagPolicyFile string
)
Loading

0 comments on commit b3a64b8

Please sign in to comment.