-
Notifications
You must be signed in to change notification settings - Fork 13
158 lines (134 loc) · 5.06 KB
/
Copy pathtest-action.yml
File metadata and controls
158 lines (134 loc) · 5.06 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
name: Test Composite Action
on:
push:
paths:
- 'action.yml'
- '.github/workflows/test-action.yml'
- '.github/fixtures/**'
pull_request:
paths:
- 'action.yml'
- '.github/workflows/test-action.yml'
- '.github/fixtures/**'
workflow_dispatch:
jobs:
test-action-detects-secrets:
name: "Action: detect secrets in fixture"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Stage the fixture in a neutral temp dir OUTSIDE the fixtures/tests
# tree. The action runs `rafter secrets` from the workspace root, where
# this repo's own .rafter.yml declassifies **/fixtures/** (triaged FPs
# for the dogfooding gate) — scanning the in-repo path would suppress the
# finding. This job verifies the ENGINE detects the secret, so we scan a
# copy at a path the policy's globs don't match.
- name: Stage fixture in a clean temp dir
run: |
mkdir -p /tmp/rafter-detect
cp .github/fixtures/fake-secret.txt /tmp/rafter-detect/fake-secret.txt
- name: Run Rafter action on fixture with known secret
id: scan
uses: ./ # test the local action.yml
with:
scan-path: '/tmp/rafter-detect'
format: json
continue-on-error: true
- name: Verify findings detected
shell: bash
run: |
echo "Exit code: ${{ steps.scan.outputs.exit-code }}"
echo "Findings: ${{ steps.scan.outputs.finding-count }}"
if [ "${{ steps.scan.outputs.exit-code }}" != "1" ]; then
echo "FAIL: expected exit code 1 (findings), got ${{ steps.scan.outputs.exit-code }}"
exit 1
fi
COUNT="${{ steps.scan.outputs.finding-count }}"
if [ "$COUNT" = "0" ] || [ -z "$COUNT" ]; then
echo "FAIL: expected findings > 0, got ${COUNT}"
exit 1
fi
echo "PASS: action correctly detected ${COUNT} secret(s)"
test-action-clean-scan:
name: "Action: clean scan on safe directory"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create a clean directory
run: |
mkdir -p /tmp/clean-test
echo "just some safe code" > /tmp/clean-test/safe.txt
- name: Run Rafter action on clean directory
id: scan
uses: ./
with:
scan-path: '/tmp/clean-test'
format: json
- name: Verify no findings
shell: bash
run: |
echo "Exit code: ${{ steps.scan.outputs.exit-code }}"
echo "Findings: ${{ steps.scan.outputs.finding-count }}"
if [ "${{ steps.scan.outputs.exit-code }}" != "0" ]; then
echo "FAIL: expected exit code 0 (clean), got ${{ steps.scan.outputs.exit-code }}"
exit 1
fi
echo "PASS: action correctly reported clean scan"
test-action-pip-install:
name: "Action: pip install method"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
# Scan a copy outside the fixtures tree so the repo's .rafter.yml does
# not suppress the finding (see "detect secrets" job for rationale).
- name: Stage fixture in a clean temp dir
run: |
mkdir -p /tmp/rafter-detect
cp .github/fixtures/fake-secret.txt /tmp/rafter-detect/fake-secret.txt
- name: Run Rafter action via pip
id: scan
uses: ./
with:
scan-path: '/tmp/rafter-detect'
install-method: pip
format: json
continue-on-error: true
- name: Verify pip install works
shell: bash
run: |
if [ "${{ steps.scan.outputs.exit-code }}" != "1" ]; then
echo "FAIL: expected exit code 1, got ${{ steps.scan.outputs.exit-code }}"
exit 1
fi
echo "PASS: pip install method works, detected secrets"
test-action-published-v1:
name: "Action: published @v1 tag"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Scan a copy outside the fixtures tree so the repo's .rafter.yml does
# not suppress the finding (see "detect secrets" job for rationale).
- name: Stage fixture in a clean temp dir
run: |
mkdir -p /tmp/rafter-detect
cp .github/fixtures/fake-secret.txt /tmp/rafter-detect/fake-secret.txt
- name: Run published Rafter action @v1
id: scan
uses: raftersecurity/rafter-cli@v1
with:
scan-path: '/tmp/rafter-detect'
format: json
continue-on-error: true
- name: Verify @v1 works
shell: bash
run: |
echo "Exit code: ${{ steps.scan.outputs.exit-code }}"
echo "Findings: ${{ steps.scan.outputs.finding-count }}"
if [ "${{ steps.scan.outputs.exit-code }}" != "1" ]; then
echo "FAIL: expected exit code 1, got ${{ steps.scan.outputs.exit-code }}"
exit 1
fi
echo "PASS: published raftersecurity/rafter-cli@v1 works"