Skip to content

Commit e8c633a

Browse files
🌱 e2e tests for security policy localrepo
- Included e2e tests for security policy for localrepo client #1353 Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com>
1 parent e5f5deb commit e8c633a

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

e2e/security_policy_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@ package e2e
1515

1616
import (
1717
"context"
18+
"io/ioutil"
19+
"os"
1820

21+
"github.com/go-git/go-git/v5"
1922
. "github.com/onsi/ginkgo/v2"
2023
. "github.com/onsi/gomega"
2124

2225
"github.com/ossf/scorecard/v4/checker"
2326
"github.com/ossf/scorecard/v4/checks"
2427
"github.com/ossf/scorecard/v4/clients"
2528
"github.com/ossf/scorecard/v4/clients/githubrepo"
29+
"github.com/ossf/scorecard/v4/clients/localdir"
2630
scut "github.com/ossf/scorecard/v4/utests"
2731
)
2832

@@ -148,5 +152,46 @@ var _ = Describe("E2E TEST:"+checks.CheckSecurityPolicy, func() {
148152
Expect(scut.ValidateTestReturn(nil, "policy found", &expected, &result, &dl)).Should(BeTrue())
149153
Expect(repoClient.Close()).Should(BeNil())
150154
})
155+
It("Should return valid security policy for local repoClient at head", func() {
156+
dl := scut.TestDetailLogger{}
157+
158+
tmpDir, err := ioutil.TempDir("", "")
159+
Expect(err).Should(BeNil())
160+
defer os.RemoveAll(tmpDir)
161+
162+
_, e := git.PlainClone(tmpDir, false, &git.CloneOptions{
163+
URL: "http://github.com/ossf-tests/botan",
164+
})
165+
Expect(e).Should(BeNil())
166+
167+
repo, err := localdir.MakeLocalDirRepo(tmpDir)
168+
Expect(err).Should(BeNil())
169+
170+
x := localdir.CreateLocalDirClient(context.Background(), logger)
171+
err = x.InitRepo(repo, clients.HeadSHA)
172+
Expect(err).Should(BeNil())
173+
174+
req := checker.CheckRequest{
175+
Ctx: context.Background(),
176+
RepoClient: x,
177+
Repo: repo,
178+
Dlogger: &dl,
179+
}
180+
expected := scut.TestReturn{
181+
Error: nil,
182+
Score: checker.MaxResultScore,
183+
NumberOfWarn: 0,
184+
NumberOfInfo: 1,
185+
NumberOfDebug: 0,
186+
}
187+
result := checks.SecurityPolicy(&req)
188+
// UPGRADEv2: to remove.
189+
// Old version.
190+
Expect(result.Error).Should(BeNil())
191+
Expect(result.Pass).Should(BeTrue())
192+
// New version.
193+
Expect(scut.ValidateTestReturn(nil, "policy found", &expected, &result, &dl)).Should(BeTrue())
194+
Expect(x.Close()).Should(BeNil())
195+
})
151196
})
152197
})

0 commit comments

Comments
 (0)