Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 refactor: reorder branch protection tests progressively by tier #3881

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 84 additions & 84 deletions checks/evaluation/branch_protection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ func TestBranchProtection(t *testing.T) {
},
},
{
name: "Required status check enabled",
name: "Allow force push enabled",
findings: []finding.Finding{
branchFinding(blocksDeleteOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(blocksForcePushOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(blocksForcePushOnBranches.Probe, "main", finding.OutcomeNegative),
branchFinding(branchesAreProtected.Probe, "main", finding.OutcomePositive),
branchFinding(branchProtectionAppliesToAdmins.Probe, "main", finding.OutcomeNegative),
branchFinding(dismissesStaleReviews.Probe, "main", finding.OutcomeNegative),
Expand All @@ -80,20 +80,20 @@ func TestBranchProtection(t *testing.T) {
),
branchFinding(requiresCodeOwnersReview.Probe, "main", finding.OutcomeNegative),
branchFinding(requiresLastPushApproval.Probe, "main", finding.OutcomeNegative),
branchFinding(requiresUpToDateBranches.Probe, "main", finding.OutcomePositive),
branchFinding(requiresUpToDateBranches.Probe, "main", finding.OutcomeNegative),
branchFinding(runsStatusChecksBeforeMerging.Probe, "main", finding.OutcomePositive),
branchFinding(requiresPRsToChangeCode.Probe, "main", finding.OutcomePositive),
},
result: scut.TestReturn{
Score: 4,
NumberOfInfo: 5,
NumberOfWarn: 5,
Score: 1,
NumberOfWarn: 7,
NumberOfInfo: 3,
},
},
{
name: "Required status check enabled without checking for status string",
name: "Allow deletions enabled",
findings: []finding.Finding{
branchFinding(blocksDeleteOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(blocksDeleteOnBranches.Probe, "main", finding.OutcomeNegative),
branchFinding(blocksForcePushOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(branchesAreProtected.Probe, "main", finding.OutcomePositive),
branchFinding(branchProtectionAppliesToAdmins.Probe, "main", finding.OutcomeNegative),
Expand All @@ -104,14 +104,14 @@ func TestBranchProtection(t *testing.T) {
),
branchFinding(requiresCodeOwnersReview.Probe, "main", finding.OutcomeNegative),
branchFinding(requiresLastPushApproval.Probe, "main", finding.OutcomeNegative),
branchFinding(requiresUpToDateBranches.Probe, "main", finding.OutcomePositive),
branchFinding(runsStatusChecksBeforeMerging.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(requiresUpToDateBranches.Probe, "main", finding.OutcomeNegative),
branchFinding(runsStatusChecksBeforeMerging.Probe, "main", finding.OutcomePositive),
branchFinding(requiresPRsToChangeCode.Probe, "main", finding.OutcomePositive),
},
result: scut.TestReturn{
Score: 4,
NumberOfInfo: 4,
NumberOfWarn: 6,
Score: 1,
NumberOfWarn: 7,
NumberOfInfo: 3,
},
},
{
Expand Down Expand Up @@ -139,6 +139,56 @@ func TestBranchProtection(t *testing.T) {
NumberOfDebug: 1,
},
},
{
name: "Non-admin run on project that require zero reviewer (or don't require PRs at all, we can't differentiate it)",
findings: []finding.Finding{
branchFinding(blocksDeleteOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(blocksForcePushOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(branchesAreProtected.Probe, "main", finding.OutcomePositive),
branchFinding(branchProtectionAppliesToAdmins.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(dismissesStaleReviews.Probe, "main", finding.OutcomeNotAvailable),
withValue(
branchFinding(requiresApproversForPullRequests.Probe, "main", finding.OutcomeNotAvailable),
requiresApproversForPullRequests.RequiredReviewersKey, "0",
),
branchFinding(requiresCodeOwnersReview.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(requiresLastPushApproval.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(requiresUpToDateBranches.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(runsStatusChecksBeforeMerging.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(requiresPRsToChangeCode.Probe, "main", finding.OutcomeNotAvailable),
},
result: scut.TestReturn{
Score: 3,
NumberOfWarn: 2,
NumberOfInfo: 2,
NumberOfDebug: 5,
},
},
{
name: "Non-admin run on project that require 1 reviewer",
findings: []finding.Finding{
branchFinding(blocksDeleteOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(blocksForcePushOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(branchesAreProtected.Probe, "main", finding.OutcomePositive),
branchFinding(branchProtectionAppliesToAdmins.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(dismissesStaleReviews.Probe, "main", finding.OutcomeNotAvailable),
withValue(
branchFinding(requiresApproversForPullRequests.Probe, "main", finding.OutcomePositive),
requiresApproversForPullRequests.RequiredReviewersKey, "1",
),
branchFinding(requiresCodeOwnersReview.Probe, "main", finding.OutcomeNegative),
branchFinding(requiresLastPushApproval.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(requiresUpToDateBranches.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(runsStatusChecksBeforeMerging.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(requiresPRsToChangeCode.Probe, "main", finding.OutcomePositive),
},
result: scut.TestReturn{
Score: 6,
NumberOfWarn: 3,
NumberOfInfo: 3,
NumberOfDebug: 4,
},
},
{
name: "Admin run with all tier 2 requirements except require PRs and reviewers",
findings: []finding.Finding{
Expand Down Expand Up @@ -213,81 +263,31 @@ func TestBranchProtection(t *testing.T) {
},
},
{
name: "Non-admin run on project that require zero reviewer (or don't require PRs at all, we can't differentiate it)",
findings: []finding.Finding{
branchFinding(blocksDeleteOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(blocksForcePushOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(branchesAreProtected.Probe, "main", finding.OutcomePositive),
branchFinding(branchProtectionAppliesToAdmins.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(dismissesStaleReviews.Probe, "main", finding.OutcomeNotAvailable),
withValue(
branchFinding(requiresApproversForPullRequests.Probe, "main", finding.OutcomeNotAvailable),
requiresApproversForPullRequests.RequiredReviewersKey, "0",
),
branchFinding(requiresCodeOwnersReview.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(requiresLastPushApproval.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(requiresUpToDateBranches.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(runsStatusChecksBeforeMerging.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(requiresPRsToChangeCode.Probe, "main", finding.OutcomeNotAvailable),
},
result: scut.TestReturn{
Score: 3,
NumberOfWarn: 2,
NumberOfInfo: 2,
NumberOfDebug: 5,
},
},
{
name: "Non-admin run on project that require 1 reviewer",
findings: []finding.Finding{
branchFinding(blocksDeleteOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(blocksForcePushOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(branchesAreProtected.Probe, "main", finding.OutcomePositive),
branchFinding(branchProtectionAppliesToAdmins.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(dismissesStaleReviews.Probe, "main", finding.OutcomeNotAvailable),
withValue(
branchFinding(requiresApproversForPullRequests.Probe, "main", finding.OutcomePositive),
requiresApproversForPullRequests.RequiredReviewersKey, "1",
),
branchFinding(requiresCodeOwnersReview.Probe, "main", finding.OutcomeNegative),
branchFinding(requiresLastPushApproval.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(requiresUpToDateBranches.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(runsStatusChecksBeforeMerging.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(requiresPRsToChangeCode.Probe, "main", finding.OutcomePositive),
},
result: scut.TestReturn{
Score: 6,
NumberOfWarn: 3,
NumberOfInfo: 3,
NumberOfDebug: 4,
},
},
{
name: "Required admin enforcement enabled",
name: "Required status check enabled",
findings: []finding.Finding{
branchFinding(blocksDeleteOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(blocksForcePushOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(branchesAreProtected.Probe, "main", finding.OutcomePositive),
branchFinding(branchProtectionAppliesToAdmins.Probe, "main", finding.OutcomePositive),
branchFinding(branchProtectionAppliesToAdmins.Probe, "main", finding.OutcomeNegative),
branchFinding(dismissesStaleReviews.Probe, "main", finding.OutcomeNegative),
withValue(
branchFinding(requiresApproversForPullRequests.Probe, "main", finding.OutcomeNegative),
requiresApproversForPullRequests.RequiredReviewersKey, "0",
),
branchFinding(requiresCodeOwnersReview.Probe, "main", finding.OutcomeNegative),
branchFinding(requiresLastPushApproval.Probe, "main", finding.OutcomeNegative),
branchFinding(requiresUpToDateBranches.Probe, "main", finding.OutcomeNegative),
branchFinding(requiresUpToDateBranches.Probe, "main", finding.OutcomePositive),
branchFinding(runsStatusChecksBeforeMerging.Probe, "main", finding.OutcomePositive),
branchFinding(requiresPRsToChangeCode.Probe, "main", finding.OutcomePositive),
},
result: scut.TestReturn{
Score: 3,
NumberOfWarn: 5,
Score: 4,
NumberOfInfo: 5,
NumberOfWarn: 5,
},
},
{
name: "Required linear history enabled",
name: "Required status check enabled without checking for status string",
findings: []finding.Finding{
branchFinding(blocksDeleteOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(blocksForcePushOnBranches.Probe, "main", finding.OutcomePositive),
Expand All @@ -300,23 +300,23 @@ func TestBranchProtection(t *testing.T) {
),
branchFinding(requiresCodeOwnersReview.Probe, "main", finding.OutcomeNegative),
branchFinding(requiresLastPushApproval.Probe, "main", finding.OutcomeNegative),
branchFinding(requiresUpToDateBranches.Probe, "main", finding.OutcomeNegative),
branchFinding(runsStatusChecksBeforeMerging.Probe, "main", finding.OutcomePositive),
branchFinding(requiresUpToDateBranches.Probe, "main", finding.OutcomePositive),
branchFinding(runsStatusChecksBeforeMerging.Probe, "main", finding.OutcomeNotAvailable),
branchFinding(requiresPRsToChangeCode.Probe, "main", finding.OutcomePositive),
},
result: scut.TestReturn{
Score: 3,
NumberOfWarn: 6,
Score: 4,
NumberOfInfo: 4,
NumberOfWarn: 6,
},
},
{
name: "Allow force push enabled",
name: "Required admin enforcement enabled",
findings: []finding.Finding{
branchFinding(blocksDeleteOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(blocksForcePushOnBranches.Probe, "main", finding.OutcomeNegative),
branchFinding(blocksForcePushOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(branchesAreProtected.Probe, "main", finding.OutcomePositive),
branchFinding(branchProtectionAppliesToAdmins.Probe, "main", finding.OutcomeNegative),
branchFinding(branchProtectionAppliesToAdmins.Probe, "main", finding.OutcomePositive),
branchFinding(dismissesStaleReviews.Probe, "main", finding.OutcomeNegative),
withValue(
branchFinding(requiresApproversForPullRequests.Probe, "main", finding.OutcomeNegative),
Expand All @@ -329,15 +329,15 @@ func TestBranchProtection(t *testing.T) {
branchFinding(requiresPRsToChangeCode.Probe, "main", finding.OutcomePositive),
},
result: scut.TestReturn{
Score: 1,
NumberOfWarn: 7,
NumberOfInfo: 3,
Score: 3,
NumberOfWarn: 5,
NumberOfInfo: 5,
},
},
{
name: "Allow deletions enabled",
name: "Required linear history enabled",
findings: []finding.Finding{
branchFinding(blocksDeleteOnBranches.Probe, "main", finding.OutcomeNegative),
branchFinding(blocksDeleteOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(blocksForcePushOnBranches.Probe, "main", finding.OutcomePositive),
branchFinding(branchesAreProtected.Probe, "main", finding.OutcomePositive),
branchFinding(branchProtectionAppliesToAdmins.Probe, "main", finding.OutcomeNegative),
Expand All @@ -353,9 +353,9 @@ func TestBranchProtection(t *testing.T) {
branchFinding(requiresPRsToChangeCode.Probe, "main", finding.OutcomePositive),
},
result: scut.TestReturn{
Score: 1,
NumberOfWarn: 7,
NumberOfInfo: 3,
Score: 3,
NumberOfWarn: 6,
NumberOfInfo: 4,
},
},
{
Expand Down
Loading