mirror of
https://github.com/ossf/scorecard.git
synced 2024-09-17 11:57:12 +03:00
🌱 e2e tests for security policy localrepo
- Included e2e tests for security policy for localrepo client https://github.com/ossf/scorecard/issues/1353 Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com>
This commit is contained in:
parent
e5f5deb64e
commit
e8c633a41b
@ -15,7 +15,10 @@ package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
@ -23,6 +26,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/localdir"
|
||||
scut "github.com/ossf/scorecard/v4/utests"
|
||||
)
|
||||
|
||||
@ -148,5 +152,46 @@ 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 for local repoClient at head", func() {
|
||||
dl := scut.TestDetailLogger{}
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", "")
|
||||
Expect(err).Should(BeNil())
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
_, e := git.PlainClone(tmpDir, false, &git.CloneOptions{
|
||||
URL: "http://github.com/ossf-tests/botan",
|
||||
})
|
||||
Expect(e).Should(BeNil())
|
||||
|
||||
repo, err := localdir.MakeLocalDirRepo(tmpDir)
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
x := localdir.CreateLocalDirClient(context.Background(), logger)
|
||||
err = x.InitRepo(repo, clients.HeadSHA)
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
req := checker.CheckRequest{
|
||||
Ctx: context.Background(),
|
||||
RepoClient: x,
|
||||
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(x.Close()).Should(BeNil())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user