Skip to content

Commit 8fe5538

Browse files
Update test to actually scan and use the issue-384 workflow fixture
- Modified TestSarifFormatIssue384 to use InventoryScanner to scan the testdata directory - Test now parses the actual workflow file and runs OPA analysis to generate findings - Added imports for scanner and opa packages - Test validates that issue-384.yml workflow is found and scanned - SARIF output is generated from real scan results instead of mock data Co-authored-by: fproulx-boostsecurity <[email protected]>
1 parent 3d7c208 commit 8fe5538

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

formatters/sarif/sarif_test.go

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77
"testing"
88

99
"github.com/boostsecurityio/poutine/models"
10+
"github.com/boostsecurityio/poutine/opa"
1011
"github.com/boostsecurityio/poutine/results"
12+
. "github.com/boostsecurityio/poutine/scanner"
1113
"github.com/stretchr/testify/require"
1214
)
1315

@@ -142,43 +144,47 @@ func TestIsValidGitURL(t *testing.T) {
142144
}
143145

144146
// TestSarifFormatIssue384 validates that the fix for issue #384 works correctly.
145-
// This test uses the exact workflow YAML from the issue report to ensure
147+
// This test scans the actual workflow YAML from the issue report to ensure
146148
// the SARIF output would be accepted by GitHub's CodeQL upload action.
147149
func TestSarifFormatIssue384(t *testing.T) {
148-
// Create a test package with a finding in the workflow from issue #384
150+
// Scan the testdata directory containing the workflow from issue #384
151+
scanner := NewInventoryScanner("testdata")
149152
pkg := &models.PackageInsights{
150-
Purl: "pkg:github/coveo/[email protected]",
151-
SourceGitRepo: "coveo/test-repo",
152-
SourceGitCommitSha: "fcd6c2d5b2c2d8366e13b7415780831017e0ecae",
153-
SourceGitRef: "refs/pull/482/merge",
154-
SourceScmType: "github",
155-
FindingsResults: results.FindingsResult{
156-
Findings: []results.Finding{
157-
{
158-
RuleId: "unsafe_checkout",
159-
Purl: "pkg:github/coveo/[email protected]",
160-
Meta: results.FindingMeta{
161-
Path: "testdata/.github/workflows/issue-384.yml",
162-
Line: 29,
163-
Job: "poutine",
164-
Step: "3",
165-
},
166-
},
167-
},
168-
Rules: map[string]results.Rule{
169-
"unsafe_checkout": {
170-
Id: "unsafe_checkout",
171-
Title: "Unsafe Checkout",
172-
Description: "Potential code injection via untrusted checkout",
173-
Level: "warning",
174-
},
175-
},
176-
},
153+
Purl: "pkg:github/coveo/test-repo",
154+
SourceGitRepo: "coveo/test-repo",
155+
SourceGitRef: "refs/pull/482/merge",
156+
SourceScmType: "github",
157+
}
158+
err := scanner.Run(pkg)
159+
require.NoError(t, err)
160+
161+
// Verify the workflow was found
162+
require.NotEmpty(t, pkg.GithubActionsWorkflows, "should have found the issue-384 workflow")
163+
164+
// Find the issue-384 workflow
165+
var foundWorkflow bool
166+
for _, wf := range pkg.GithubActionsWorkflows {
167+
if wf.Path == ".github/workflows/issue-384.yml" {
168+
foundWorkflow = true
169+
break
170+
}
177171
}
172+
require.True(t, foundWorkflow, "should have found issue-384.yml workflow")
178173

174+
// Analyze with OPA to generate findings (using a basic config)
175+
opaInstance, err := opa.NewOpa(context.Background(), &models.Config{
176+
Include: []models.ConfigInclude{},
177+
})
178+
require.NoError(t, err)
179+
180+
inventory := NewInventory(opaInstance, nil, "", "")
181+
scannedPkg, err := inventory.ScanPackage(context.Background(), *pkg, "testdata")
182+
require.NoError(t, err)
183+
184+
// Generate SARIF output
179185
var buf bytes.Buffer
180186
formatter := NewFormat(&buf, "1.0.0")
181-
err := formatter.Format(context.Background(), []*models.PackageInsights{pkg})
187+
err = formatter.Format(context.Background(), []*models.PackageInsights{scannedPkg})
182188
require.NoError(t, err)
183189

184190
// Parse the generated SARIF

0 commit comments

Comments
 (0)