Skip to content

Commit 03f4760

Browse files
authored
Merge pull request #2044 from Devils-Knight/updateSecure
Update SecureWorkflow function to Handle Empty File input
2 parents 4af0234 + ff05a33 commit 03f4760

File tree

4 files changed

+4
-0
lines changed

4 files changed

+4
-0
lines changed

remediation/workflow/permissions/permissions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ func AddWorkflowLevelPermissions(inputYaml string, addProjectComment bool) (stri
101101
line := 0
102102
column := 0
103103
topNode := t.Content
104+
if len(topNode) == 0 {
105+
return inputYaml, fmt.Errorf("Workflow file provided is Empty")
106+
}
104107
for _, n := range topNode[0].Content {
105108
if n.Value == "jobs" && n.Tag == "!!str" {
106109
line = n.Line

remediation/workflow/secureworkflow_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func TestSecureWorkflow(t *testing.T) {
120120
{fileName: "nopin.yml", wantPinnedActions: false, wantAddedHardenRunner: true, wantAddedPermissions: true},
121121
{fileName: "allperms.yml", wantPinnedActions: false, wantAddedHardenRunner: false, wantAddedPermissions: true},
122122
{fileName: "multiplejobperms.yml", wantPinnedActions: false, wantAddedHardenRunner: false, wantAddedPermissions: true},
123+
{fileName: "error.yml", wantPinnedActions: false, wantAddedHardenRunner: false, wantAddedPermissions: false},
123124
}
124125
for _, test := range tests {
125126
input, err := ioutil.ReadFile(path.Join(inputDirectory, test.fileName))

testfiles/secureworkflow/input/error.yml

Whitespace-only changes.

testfiles/secureworkflow/output/error.yml

Whitespace-only changes.

0 commit comments

Comments
 (0)