-
Notifications
You must be signed in to change notification settings - Fork 0
307 lines (251 loc) · 10.2 KB
/
Copy pathtest.yml
File metadata and controls
307 lines (251 loc) · 10.2 KB
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
name: Test
on:
push:
branches: [main, claude/*]
pull_request:
branches: [main]
# Pin opengrep version for consistent SARIF output
# IMPORTANT: When updating this version, also update:
# - internal/version/version.go
# - docker/Dockerfile
env:
OPENGREP_VERSION: "1.15.1"
jobs:
test:
runs-on: ubuntu-latest
# Skip redundant runs: run on push, or on pull_request only if from a fork
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install opengrep (pinned version)
run: |
wget -O /usr/local/bin/opengrep "https://github.com/opengrep/opengrep/releases/download/v${OPENGREP_VERSION}/opengrep_manylinux_x86"
chmod +x /usr/local/bin/opengrep
opengrep --version
- name: Build
run: go build -v ./...
- name: Run unit tests with coverage
run: |
go test -v -race -coverprofile=coverage.out -short ./...
go tool cover -func=coverage.out
- name: Run integration tests (with scanner)
run: |
go test -v -timeout 5m ./test/...
- name: Upload coverage
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.out
scanner-test:
runs-on: ubuntu-latest
# Skip redundant runs: run on push, or on pull_request only if from a fork
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install opengrep (pinned version)
run: |
wget -O /usr/local/bin/opengrep "https://github.com/opengrep/opengrep/releases/download/v${OPENGREP_VERSION}/opengrep_manylinux_x86"
chmod +x /usr/local/bin/opengrep
opengrep --version
- name: Clone test repo and scan for fake secrets
run: |
# Clone this repo (contains test/fixtures/fake_secrets.go)
git clone --depth 1 https://github.com/baocin/gitscan.git /tmp/test-repo
# Run scanner with SARIF output to file (--sarif-output writes directly to file)
# Use --quiet to suppress progress bar which can interfere with output
echo "Running opengrep scanner..."
opengrep scan --quiet --config auto --sarif-output=/tmp/scan-results.json /tmp/test-repo || true
# Show scanner progress (from stderr)
echo "=== Scanner Progress ==="
cat /tmp/scan-stderr.log | head -50
# Show JSON results
echo "=== Scan Results (JSON) ==="
cat /tmp/scan-results.json | head -200
# Verify we got JSON output
if [ ! -s /tmp/scan-results.json ]; then
echo "ERROR: No scan output generated"
echo "=== Stderr log ==="
cat /tmp/scan-stderr.log
exit 1
fi
# Check for valid JSON structure
if ! python3 -c "import json; json.load(open('/tmp/scan-results.json'))"; then
echo "ERROR: Invalid JSON output"
echo "=== Full output ==="
cat /tmp/scan-results.json
echo "=== Stderr log ==="
cat /tmp/scan-stderr.log
exit 1
fi
echo "Scanner produced valid JSON output"
- name: Verify SARIF parsing compatibility
run: |
# Test that our Go code can parse the scanner output
go test -v -run TestParseSARIF ./internal/scanner/...
benchmark-test:
runs-on: ubuntu-latest
# Skip redundant runs: run on push, or on pull_request only if from a fork
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install opengrep (pinned version)
run: |
wget -O /usr/local/bin/opengrep "https://github.com/opengrep/opengrep/releases/download/v${OPENGREP_VERSION}/opengrep_manylinux_x86"
chmod +x /usr/local/bin/opengrep
opengrep --version
- name: Run OWASP NodeGoat clone test
run: |
go test -v -run TestCloneOWASPNodeGoatPinned ./test/... -timeout 5m
- name: Run clone speed tests
run: |
go test -v -run TestCloneSpeed ./test/... -timeout 5m
- name: Run OWASP NodeGoat scan test
run: |
go test -v -run TestScanOWASPNodeGoat ./test/... -timeout 10m
- name: Run benchmarks (1 iteration for CI)
run: |
go test -bench=. -benchtime=1x -run=^$ ./test/... -timeout 10m || true
integration-test:
runs-on: ubuntu-latest
needs: test
# Skip redundant runs: run on push, or on pull_request only if from a fork
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install opengrep (pinned version)
run: |
wget -O /usr/local/bin/opengrep "https://github.com/opengrep/opengrep/releases/download/v${OPENGREP_VERSION}/opengrep_manylinux_x86"
chmod +x /usr/local/bin/opengrep
opengrep --version
- name: Build server
run: go build -o gitscan-server ./cmd/gitscan-server
- name: Start server
run: |
./gitscan-server -listen :6633 -cache-dir /tmp/gitscan-cache &
sleep 3
curl -sf http://localhost:6633/health || exit 1
- name: Test health endpoint
run: |
curl -sf http://localhost:6633/health
- name: Test version endpoint
run: |
curl -sf http://localhost:6633/version | jq .
- name: Test homepage
run: |
curl -sf http://localhost:6633/ | grep -q "git.vet"
- name: Test git clone (info/refs)
run: |
# Test that info/refs endpoint responds with git protocol
curl -sf "http://localhost:6633/github.com/OWASP/NodeGoat/info/refs?service=git-upload-pack" | head -c 100
docker-test:
runs-on: ubuntu-latest
needs: test # Run after unit tests pass
# Skip redundant runs: run on push, or on pull_request only if from a fork
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- uses: actions/checkout@v4
- name: Build Docker image
run: |
echo "Building Docker image..."
docker build -f docker/Dockerfile -t gitscan:test .
echo "Image built successfully"
- name: Verify binary in image
run: |
echo "=== Checking binary exists and is executable ==="
docker run --rm gitscan:test ls -la /usr/local/bin/gitscan
docker run --rm gitscan:test file /usr/local/bin/gitscan
echo "=== Checking shared library dependencies ==="
docker run --rm gitscan:test ldd /usr/local/bin/gitscan 2>&1 || echo "Static binary or musl-linked"
- name: Start container
run: |
docker run -d --name gitscan-test -p 6633:6633 gitscan:test
echo "Container started, waiting for server..."
# Wait for server to be ready (up to 30 seconds)
for i in $(seq 1 15); do
if curl -sf http://localhost:6633/health > /dev/null 2>&1; then
echo "Server ready after $((i*2)) seconds"
break
fi
echo "Waiting... ($i/15)"
sleep 2
done
- name: Test health endpoint
run: |
response=$(curl -sf http://localhost:6633/health)
echo "Health: $response"
[ "$response" = "ok" ] || [ "$response" = "OK" ] || exit 1
- name: Test version endpoint
run: |
curl -sf http://localhost:6633/version | jq .
- name: Test homepage
run: |
curl -sf http://localhost:6633/ | grep -q "git.vet"
echo "Homepage OK - contains git.vet"
- name: Test pricing page
run: |
curl -sf http://localhost:6633/pricing | grep -q "Pricing"
echo "Pricing page OK"
# Test redirect from /pricing/ to /pricing
status=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:6633/pricing/)
echo "Redirect status: $status"
[ "$status" = "301" ] || [ "$status" = "200" ] || exit 1
- name: Test static assets
run: |
# Test favicon
curl -sf http://localhost:6633/static/favicon.svg > /dev/null
echo "Favicon OK"
- name: Test git protocol - info/refs
run: |
response=$(curl -sf "http://localhost:6633/github.com/OWASP/NodeGoat/info/refs?service=git-upload-pack")
echo "$response" | head -c 200
echo ""
# Verify git protocol response
echo "$response" | grep -q "git-upload-pack" || { echo "Missing git-upload-pack in response"; exit 1; }
echo "Git info/refs OK"
- name: Test report page (404 for non-existent)
run: |
# Should return HTML even for non-existent reports
curl -sf http://localhost:6633/r/nonexistent123 | grep -q "Report Not Found"
echo "Report 404 page OK"
- name: Show container logs
if: always()
run: |
echo "=== Container logs ==="
docker logs gitscan-test 2>&1 | tail -100
- name: Cleanup
if: always()
run: |
docker stop gitscan-test 2>/dev/null || true
docker rm gitscan-test 2>/dev/null || true