From e5f5deb64ec5c8d9607d9038613a18c5a23c0352 Mon Sep 17 00:00:00 2001 From: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> Date: Wed, 30 Mar 2022 21:02:17 +0000 Subject: [PATCH] :seedling: e2e tests for local repoclient for permissions - Included e2e tests for local repoclient for permissions. Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- e2e/permissions_test.go | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/e2e/permissions_test.go b/e2e/permissions_test.go index 3b6cf6c083d..4d6a9f937d9 100644 --- a/e2e/permissions_test.go +++ b/e2e/permissions_test.go @@ -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" ) @@ -88,5 +92,47 @@ var _ = Describe("E2E TEST:"+checks.CheckTokenPermissions, func() { Expect(scut.ValidateTestReturn(nil, "token permissions", &expected, &result, &dl)).Should(BeTrue()) Expect(repoClient.Close()).Should(BeNil()) }) + It("Should return token permission for a local repo client", 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/scorecard-check-token-permissions-e2e", + }) + 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.MinResultScore, + NumberOfWarn: 1, + NumberOfInfo: 2, + NumberOfDebug: 5, + } + result := checks.TokenPermissions(&req) + // UPGRADEv2: to remove. + // Old version. + + Expect(result.Error).Should(BeNil()) + Expect(result.Pass).Should(BeFalse()) + // New version. + Expect(scut.ValidateTestReturn(nil, "token permissions", &expected, &result, &dl)).Should(BeTrue()) + Expect(x.Close()).Should(BeNil()) + }) }) })