Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion pkg/workflow/push_to_pull_request_branch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ safe-outputs:
}

lockContentStr := string(lockContent)
safeOutputsJobSection := extractJobSection(lockContentStr, "safe_outputs")
if safeOutputsJobSection == "" {
t.Fatalf("Could not find safe_outputs job in lock file")
}
pushConfig := extractPushToPullRequestBranchHandlerConfig(t, lockContent)
fallbackAsPullRequest, exists := pushConfig["fallback_as_pull_request"]
if !exists {
Expand All @@ -236,9 +240,12 @@ safe-outputs:
if fallbackAsPullRequestBool {
t.Errorf("Expected fallback_as_pull_request=false, got %#v", fallbackAsPullRequestBool)
}
if strings.Contains(lockContentStr, "pull-requests: write") {
if strings.Contains(safeOutputsJobSection, "pull-requests: write") {
t.Errorf("Generated workflow should NOT have pull-requests: write permission when fallback-as-pull-request is false")
}
if !strings.Contains(safeOutputsJobSection, "pull-requests: read") {
t.Errorf("Generated workflow should have pull-requests: read permission when fallback-as-pull-request is false")
}
}

func TestPushToPullRequestBranchSignedCommitsDisabled(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions pkg/workflow/safe_output_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ var safeOutputHandlers = []safeOutputHandlerDescriptor{
permissions.Merge(NewPermissionsContentsWritePRWrite())
} else {
permissions.Merge(NewPermissionsContentsWrite())
permissions.Set(PermissionPullRequests, PermissionRead)
}
if safeOutputs.PushToPullRequestBranch.AllowWorkflows {
permissions.Set(PermissionWorkflows, PermissionWrite)
Expand Down
3 changes: 2 additions & 1 deletion pkg/workflow/safe_outputs_permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func TestComputePermissionsForSafeOutputs(t *testing.T) {
},
},
{
name: "push-to-pull-request-branch with fallback-as-pull-request false - no pull-requests permission but administration read",
name: "push-to-pull-request-branch with fallback-as-pull-request false - requires pull-requests read and administration read",
safeOutputs: &SafeOutputsConfig{
PushToPullRequestBranch: &PushToPullRequestBranchConfig{
BaseSafeOutputConfig: BaseSafeOutputConfig{},
Expand All @@ -340,6 +340,7 @@ func TestComputePermissionsForSafeOutputs(t *testing.T) {
},
expected: map[PermissionScope]PermissionLevel{
PermissionContents: PermissionWrite,
PermissionPullRequests: PermissionRead,
PermissionAdministration: PermissionRead,
},
},
Expand Down
Loading