Skip to content

Commit c342b5d

Browse files
committed
[PLUTO-1411] Add trivy test
1 parent 90d3e58 commit c342b5d

File tree

5 files changed

+103
-0
lines changed

5 files changed

+103
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Trivy Plugin Test
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
push:
8+
paths:
9+
- 'plugins/tools/trivy/**'
10+
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version: '1.21'
23+
cache: true
24+
25+
- name: Build CLI
26+
run: |
27+
go build -o cli-v2 ./cli-v2.go
28+
chmod +x cli-v2
29+
30+
- name: Run Trivy plugin tests
31+
run: |
32+
# Store the path to the CLI
33+
CLI_PATH="$(pwd)/cli-v2"
34+
# Change to test directory
35+
cd plugins/tools/trivy/test
36+
# Install the plugin
37+
"$CLI_PATH" install
38+
# Run analysis
39+
"$CLI_PATH" analyze --tool trivy --format sarif --output actual.sarif
40+
# Convert absolute paths to relative paths in the output
41+
sed -i 's|file:///home/runner/work/codacy-cli-v2/codacy-cli-v2/|file:///|g' actual.sarif
42+
# Compare with expected output
43+
diff expected.sarif actual.sarif
44+
# Clean up
45+
rm actual.sarif
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
runtimes:
2+
tools:
3+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"version": "2.1.0",
3+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
4+
"runs": [
5+
{
6+
"tool": {
7+
"driver": {
8+
"fullName": "Trivy Vulnerability Scanner",
9+
"informationUri": "https://github.com/aquasecurity/trivy",
10+
"name": "Trivy",
11+
"rules": [],
12+
"version": "0.59.1"
13+
}
14+
},
15+
"results": [],
16+
"columnKind": "utf16CodeUnits",
17+
"originalUriBaseIds": {
18+
"ROOTPATH": {
19+
"uri": "file:///plugins/tools/trivy/test/"
20+
}
21+
}
22+
}
23+
]
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM node:12.0.0
2+
3+
# Using an old version of npm that has known vulnerabilities
4+
RUN npm install -g [email protected]
5+
6+
# Copy application files
7+
WORKDIR /app
8+
COPY package*.json ./
9+
10+
# Install dependencies with known vulnerabilities
11+
RUN npm install [email protected]
12+
13+
# Copy source code
14+
COPY . .
15+
16+
# Expose port
17+
EXPOSE 3000
18+
19+
# Start the application
20+
CMD ["node", "app.js"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "trivy-test-app",
3+
"version": "1.0.0",
4+
"description": "Test application for Trivy vulnerability scanning",
5+
"main": "app.js",
6+
"dependencies": {
7+
"express": "4.16.4",
8+
"lodash": "4.17.15",
9+
"moment": "2.24.0"
10+
}
11+
}

0 commit comments

Comments
 (0)