Skip to content

Commit

Permalink
Fixes - Incorrect result for branch protection
Browse files Browse the repository at this point in the history
  • Loading branch information
naveensrinivasan committed Jan 26, 2021
1 parent 2a1463b commit 93373f7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion checks/branch_protected.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ func BranchProtection(c checker.Checker) checker.CheckResult {
return checker.RetryResult(err)
}

protection, _, err := c.Client.Repositories.
protection, resp, err := c.Client.Repositories.
GetBranchProtection(c.Ctx, c.Owner, c.Repo, *repo.DefaultBranch)
if resp.StatusCode == 404 {
return checker.RetryResult(err)
}

if err != nil {
c.Logf("!! branch protection not enabled")
Expand Down
30 changes: 30 additions & 0 deletions e2e/branchprotection_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package e2e

import (
"context"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/ossf/scorecard/checker"
"github.com/ossf/scorecard/checks"
)

var _ = Describe("E2E TEST:Branch Protection", func() {
Context("E2E TEST:Validating branch protection", func() {
It("Should fail to return branch protection on other respositories", func() {
l := log{}
checker := checker.Checker{
Ctx: context.Background(),
Client: ghClient,
HttpClient: client,
Owner: "apache",
Repo: "airflow",
GraphClient: graphClient,
Logf: l.Logf,
}
result := checks.BranchProtection(checker)
Expect(result.Error).ShouldNot(BeNil())
Expect(result.Pass).Should(BeFalse())
})
})
})

0 comments on commit 93373f7

Please sign in to comment.