|
7 | 7 | "testing" |
8 | 8 |
|
9 | 9 | "github.com/boostsecurityio/poutine/models" |
| 10 | + "github.com/boostsecurityio/poutine/opa" |
10 | 11 | "github.com/boostsecurityio/poutine/results" |
| 12 | + . "github.com/boostsecurityio/poutine/scanner" |
11 | 13 | "github.com/stretchr/testify/require" |
12 | 14 | ) |
13 | 15 |
|
@@ -142,43 +144,47 @@ func TestIsValidGitURL(t *testing.T) { |
142 | 144 | } |
143 | 145 |
|
144 | 146 | // 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 |
146 | 148 | // the SARIF output would be accepted by GitHub's CodeQL upload action. |
147 | 149 | 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") |
149 | 152 | 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 | + } |
177 | 171 | } |
| 172 | + require.True(t, foundWorkflow, "should have found issue-384.yml workflow") |
178 | 173 |
|
| 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 |
179 | 185 | var buf bytes.Buffer |
180 | 186 | formatter := NewFormat(&buf, "1.0.0") |
181 | | - err := formatter.Format(context.Background(), []*models.PackageInsights{pkg}) |
| 187 | + err = formatter.Format(context.Background(), []*models.PackageInsights{scannedPkg}) |
182 | 188 | require.NoError(t, err) |
183 | 189 |
|
184 | 190 | // Parse the generated SARIF |
|
0 commit comments