Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
poutine/scanner/inventory_scanner_test.go at main · boostsecurityio/poutine · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
boostsecurityio
poutine
Repository navigation
Code
Issues
6
(6)
Pull requests
15
(15)
Actions
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
poutine
/
scanner
/
inventory_scanner_test.go
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
230 lines (198 loc) · 7.25 KB
main
Breadcrumbs
poutine
/
scanner
/
inventory_scanner_test.go
Copy path
Top
File metadata and controls
Code
Blame
230 lines (198 loc) · 7.25 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
package
scanner
import
(
"context"
"testing"
"github.com/boostsecurityio/poutine/models"
"github.com/boostsecurityio/poutine/opa"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func
TestGithubWorkflows
(
t
*
testing.
T
) {
s
:=
NewInventoryScanner
(
"testdata"
)
pkgInsights
:=
&
models.
PackageInsights
{}
err
:=
s
.
Run
(
pkgInsights
)
workflows
:=
pkgInsights
.
GithubActionsWorkflows
assert
.
Nil
(
t
,
err
)
paths
:=
[]
string
{}
for
_
,
workflow
:=
range
workflows
{
paths
=
append
(
paths
,
workflow
.
Path
)
}
assert
.
ElementsMatch
(
t
,
paths
, []
string
{
".github/workflows/debug_enabled_valid.yml"
,
".github/workflows/valid.yml"
,
".github/workflows/matrix.yml"
,
".github/workflows/reusable.yml"
,
".github/workflows/secrets.yaml"
,
".github/workflows/workflow_run_valid.yml"
,
".github/workflows/workflow_run_reusable.yml"
,
".github/workflows/allowed_pr_runner.yml"
,
".github/workflows/anchors_env.yml"
,
".github/workflows/anchors_job.yml"
,
".github/workflows/anchors_multiple.yml"
,
".github/workflows/anchors_with_vulnerability.yml"
,
".github/workflows/test_new_fields.yml"
,
})
}
func
TestGithubWorkflowsNotFound
(
t
*
testing.
T
) {
s
:=
NewInventoryScanner
(
"testdata/.github"
)
pkgInsights
:=
&
models.
PackageInsights
{}
err
:=
s
.
Run
(
pkgInsights
)
workflows
:=
pkgInsights
.
GithubActionsWorkflows
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
0
,
len
(
workflows
))
}
// TestGithubWorkflowMalformedNotDropped verifies that a workflow containing a
// locally-malformed sub-node is still retained by the parser instead of being
// silently dropped from the scan.
func
TestGithubWorkflowMalformedNotDropped
(
t
*
testing.
T
) {
data
:=
[]
byte
(
`
name: CI
on:
push:
branches: {}
permissions: not-a-real-value
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: make build
`
)
p
:=
NewGithubActionWorkflowParser
()
pkgInsights
:=
&
models.
PackageInsights
{}
err
:=
p
.
ParseFromMemory
(
data
,
".github/workflows/ci.yml"
,
pkgInsights
)
require
.
NoError
(
t
,
err
)
require
.
Len
(
t
,
pkgInsights
.
GithubActionsWorkflows
,
1
)
wf
:=
pkgInsights
.
GithubActionsWorkflows
[
0
]
assert
.
Equal
(
t
,
".github/workflows/ci.yml"
,
wf
.
Path
)
require
.
Len
(
t
,
wf
.
Jobs
,
1
)
assert
.
Equal
(
t
,
"build"
,
wf
.
Jobs
[
0
].
ID
)
require
.
Len
(
t
,
wf
.
Jobs
[
0
].
Steps
,
2
)
}
func
TestGithubActionsMetadata
(
t
*
testing.
T
) {
s
:=
NewInventoryScanner
(
"testdata"
)
pkgInsights
:=
&
models.
PackageInsights
{}
err
:=
s
.
Run
(
pkgInsights
)
metadata
:=
pkgInsights
.
GithubActionsMetadata
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
2
,
len
(
metadata
))
assert
.
Equal
(
t
,
"action.yml"
,
metadata
[
0
].
Path
)
assert
.
Equal
(
t
,
"docker"
,
metadata
[
0
].
Runs
.
Using
)
assert
.
Equal
(
t
,
"docker://alpine:latest"
,
metadata
[
0
].
Runs
.
Image
)
}
func
TestRun
(
t
*
testing.
T
) {
workdir
:=
"testdata"
o
,
_
:=
opa
.
NewOpa
(
context
.
TODO
(),
&
models.
Config
{
Include
: []models.
ConfigInclude
{},
})
pkgInsights
:=
&
models.
PackageInsights
{}
pkgInsights
.
Purl
=
"pkg:github/org/owner"
i
:=
NewInventory
(
o
,
nil
,
"github"
,
""
)
scannedPackage
,
err
:=
i
.
ScanPackage
(
context
.
TODO
(),
*
pkgInsights
,
workdir
)
assert
.
NoError
(
t
,
err
)
assert
.
Contains
(
t
,
scannedPackage
.
BuildDependencies
,
"pkg:githubactions/actions/checkout@v4"
)
assert
.
Contains
(
t
,
scannedPackage
.
PackageDependencies
,
"pkg:githubactions/actions/github-script@main"
)
assert
.
Contains
(
t
,
scannedPackage
.
PackageDependencies
,
"pkg:docker/alpine@latest"
)
assert
.
Equal
(
t
,
3
,
len
(
scannedPackage
.
GitlabciConfigs
))
}
func
TestGithubWorkflowsWithAnchors
(
t
*
testing.
T
) {
s
:=
NewInventoryScanner
(
"testdata"
)
pkgInsights
:=
&
models.
PackageInsights
{}
err
:=
s
.
Run
(
pkgInsights
)
require
.
NoError
(
t
,
err
)
workflows
:=
pkgInsights
.
GithubActionsWorkflows
// Find and validate the anchor workflows
var
envWorkflow
,
jobWorkflow
,
multipleWorkflow
*
models.
GithubActionsWorkflow
for
i
:=
range
workflows
{
switch
workflows
[
i
].
Path
{
case
".github/workflows/anchors_env.yml"
:
envWorkflow
=
&
workflows
[
i
]
case
".github/workflows/anchors_job.yml"
:
jobWorkflow
=
&
workflows
[
i
]
case
".github/workflows/anchors_multiple.yml"
:
multipleWorkflow
=
&
workflows
[
i
]
}
}
// Verify anchors_env.yml parsed correctly
assert
.
NotNil
(
t
,
envWorkflow
,
"anchors_env.yml should be found"
)
assert
.
Equal
(
t
,
"Anchors - Environment Variables"
,
envWorkflow
.
Name
)
assert
.
Len
(
t
,
envWorkflow
.
Jobs
,
2
)
// Both jobs should have the same environment variables (anchor was reused)
job1
:=
envWorkflow
.
Jobs
[
0
]
job2
:=
envWorkflow
.
Jobs
[
1
]
assert
.
Len
(
t
,
job1
.
Env
,
2
)
assert
.
Len
(
t
,
job2
.
Env
,
2
)
assert
.
Contains
(
t
,
job1
.
Env
, models.
GithubActionsEnv
{
Name
:
"NODE_ENV"
,
Value
:
"production"
})
assert
.
Contains
(
t
,
job2
.
Env
, models.
GithubActionsEnv
{
Name
:
"NODE_ENV"
,
Value
:
"production"
})
// Verify anchors_job.yml parsed correctly
assert
.
NotNil
(
t
,
jobWorkflow
,
"anchors_job.yml should be found"
)
assert
.
Equal
(
t
,
"Anchors - Complete Job"
,
jobWorkflow
.
Name
)
assert
.
Len
(
t
,
jobWorkflow
.
Jobs
,
2
)
// Both jobs should be identical (complete job anchor reused)
testJob
:=
jobWorkflow
.
Jobs
[
0
]
altTestJob
:=
jobWorkflow
.
Jobs
[
1
]
assert
.
Equal
(
t
,
"test"
,
testJob
.
ID
)
assert
.
Equal
(
t
,
"alt-test"
,
altTestJob
.
ID
)
assert
.
Equal
(
t
,
testJob
.
RunsOn
,
altTestJob
.
RunsOn
)
assert
.
Equal
(
t
,
testJob
.
Env
,
altTestJob
.
Env
)
assert
.
Len
(
t
,
testJob
.
Steps
,
3
)
assert
.
Len
(
t
,
altTestJob
.
Steps
,
3
)
assert
.
Equal
(
t
,
"actions/checkout@v5"
,
testJob
.
Steps
[
0
].
Uses
)
assert
.
Equal
(
t
,
"actions/checkout@v5"
,
altTestJob
.
Steps
[
0
].
Uses
)
// Verify anchors_multiple.yml parsed correctly
assert
.
NotNil
(
t
,
multipleWorkflow
,
"anchors_multiple.yml should be found"
)
assert
.
Equal
(
t
,
"Anchors - Multiple References"
,
multipleWorkflow
.
Name
)
assert
.
Len
(
t
,
multipleWorkflow
.
Jobs
,
3
)
// All three jobs should use the same runner and container (multiple anchors reused)
for
i
:=
0
;
i
<
3
;
i
++
{
assert
.
Equal
(
t
, models.
GithubActionsJobRunsOn
{
"ubuntu-latest"
},
multipleWorkflow
.
Jobs
[
i
].
RunsOn
)
assert
.
Equal
(
t
,
"node:18"
,
multipleWorkflow
.
Jobs
[
i
].
Container
.
Image
)
}
}
func
TestPipelineAsCodeTekton
(
t
*
testing.
T
) {
s
:=
NewInventoryScanner
(
"testdata"
)
pkgInsights
:=
&
models.
PackageInsights
{}
err
:=
s
.
Run
(
pkgInsights
)
assert
.
NoError
(
t
,
err
)
pipelines
:=
pkgInsights
.
PipelineAsCodeTekton
assert
.
Len
(
t
,
pipelines
,
1
)
expectedAnnotations
:=
map
[
string
]
string
{
"pipelinesascode.tekton.dev/on-event"
:
"[push, pull_request]"
,
"pipelinesascode.tekton.dev/on-target-branch"
:
"[*]"
,
"pipelinesascode.tekton.dev/task"
:
"[git-clone]"
,
}
expectedPipeline
:=
models.
PipelineAsCodeTekton
{
ApiVersion
:
"tekton.dev/v1beta1"
,
Kind
:
"PipelineRun"
,
Metadata
:
struct
{
Name
string
`json:"name"`
Annotations
map
[
string
]
string
`json:"annotations"`
}{
Name
:
"linters"
,
Annotations
:
expectedAnnotations
,
},
Spec
: models.
PipelineRunSpec
{
PipelineSpec
:
&
models.
PipelineSpec
{
Tasks
: []models.
PipelineTask
{
{
Name
:
"fetchit"
,
},
{
Name
:
"vale"
,
TaskSpec
:
&
models.
TaskSpec
{
Steps
: []models.
Step
{
{
Name
:
"vale-lint"
,
Script
:
"vale docs/content --minAlertLevel=error --output=line
\n
"
,
Lines
:
map
[
string
]
int
{
"script"
:
43
,
"start"
:
40
},
},
},
},
},
},
},
},
}
assert
.
Equal
(
t
,
expectedPipeline
.
Metadata
,
pipelines
[
0
].
Metadata
)
assert
.
Equal
(
t
,
expectedPipeline
.
Spec
.
PipelineSpec
.
Tasks
[
1
].
TaskSpec
.
Steps
[
0
],
pipelines
[
0
].
Spec
.
PipelineSpec
.
Tasks
[
1
].
TaskSpec
.
Steps
[
0
])
}
You can’t perform that action at this time.