Skip to content

Commit 148de75

Browse files
authored
Target app mayhem security (#128)
* Use MAYHEM_URL secret rather than hard-coded beta instance in workflow * Set owner * Add fail on defects test * Wait if fail-on-defects set * Restructure __tests__ * Allow overriding package path
1 parent 476532d commit 148de75

8 files changed

Lines changed: 83 additions & 24 deletions

File tree

.github/workflows/main.yml

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
name: 'build-test'
1+
name: "build-test"
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
88
workflow_dispatch:
99

1010
jobs:
11-
build: # make sure build/ci work properly
11+
build:
12+
# make sure build/ci work properly
1213
runs-on: ubuntu-latest
1314
env:
1415
MAYHEM_TOKEN: ${{ secrets.MAYHEM_TOKEN }}
@@ -23,7 +24,8 @@ jobs:
2324
- run: |
2425
npm run all
2526
26-
test-some-outputs: # make sure the action works on a clean machine without building
27+
test-some-outputs:
28+
# make sure the action works on a clean machine without building
2729
runs-on: ubuntu-latest
2830
steps:
2931
- uses: actions/checkout@v3
@@ -34,12 +36,13 @@ jobs:
3436
- uses: ./
3537
id: mcode-action
3638
with:
37-
mayhem-url: https://beta.forallsecure.com
39+
mayhem-url: ${{ secrets.MAYHEM_URL }}
3840
mayhem-token: ${{ secrets.MAYHEM_TOKEN }}
3941
github-token: ${{ secrets.GITHUB_TOKEN }}
4042
sarif-output: out/sarif/
41-
args: --image forallsecure/lighttpd:vulnerable --file __tests__/Mayhemfile --duration 60
42-
43+
package: __tests__/lighttpd
44+
args: --image forallsecure/lighttpd:vulnerable --duration 60
45+
4346
- name: Upload SARIF file(s)
4447
uses: github/codeql-action/upload-sarif@v2
4548
with:
@@ -50,7 +53,8 @@ jobs:
5053
[ -z "${{ steps.mcode-action.outputs.runId }}" ] && echo "runId was blank!" && exit 1;
5154
echo "The run id was: ${{ steps.mcode-action.outputs.runId }}"
5255
53-
test-all-outputs: # make sure the action works on a clean machine without building
56+
test-all-outputs:
57+
# make sure the action works on a clean machine without building
5458
runs-on: ubuntu-latest
5559
steps:
5660
- uses: actions/checkout@v3
@@ -61,13 +65,14 @@ jobs:
6165
- uses: ./
6266
id: mcode-action
6367
with:
64-
mayhem-url: https://beta.forallsecure.com
68+
mayhem-url: ${{ secrets.MAYHEM_URL }}
6569
mayhem-token: ${{ secrets.MAYHEM_TOKEN }}
6670
github-token: ${{ secrets.GITHUB_TOKEN }}
6771
junit-output: out/junit/
6872
sarif-output: out/sarif/
6973
coverage-output: out/coverage/
70-
args: --image forallsecure/lighttpd:vulnerable --file __tests__/Mayhemfile --duration 60
74+
package: __tests__/lighttpd
75+
args: --image forallsecure/lighttpd:vulnerable --duration 60
7176

7277
- name: Archive Coverage report
7378
uses: actions/upload-artifact@v3
@@ -82,7 +87,7 @@ jobs:
8287
name: mcode-junit
8388
path: out/junit/
8489
if-no-files-found: error
85-
90+
8691
- name: Upload SARIF file(s)
8792
uses: github/codeql-action/upload-sarif@v2
8893
with:
@@ -93,7 +98,8 @@ jobs:
9398
[ -z "${{ steps.mcode-action.outputs.runId }}" ] && echo "runId was blank!" && exit 1;
9499
echo "The run id was: ${{ steps.mcode-action.outputs.runId }}"
95100
96-
test-no-outputs: # make sure the action works on a clean machine without building
101+
test-no-outputs:
102+
# make sure the action works on a clean machine without building
97103
runs-on: ubuntu-latest
98104
steps:
99105
- uses: actions/checkout@v3
@@ -104,10 +110,11 @@ jobs:
104110
- uses: ./
105111
id: mcode-action
106112
with:
107-
mayhem-url: https://beta.forallsecure.com
113+
mayhem-url: ${{ secrets.MAYHEM_URL }}
108114
mayhem-token: ${{ secrets.MAYHEM_TOKEN }}
109115
github-token: ${{ secrets.GITHUB_TOKEN }}
110-
args: --image forallsecure/lighttpd:vulnerable --file __tests__/Mayhemfile --duration 60
116+
package: __tests__/lighttpd
117+
args: --image forallsecure/lighttpd:vulnerable --duration 60
111118

112119
- name: Print runId (${{ steps.mcode-action.outputs.runId }}) and test it's non-empty
113120
run: |
@@ -126,13 +133,14 @@ jobs:
126133
- uses: ./
127134
id: mcode-action
128135
with:
129-
mayhem-url: https://beta.forallsecure.com
136+
mayhem-url: ${{ secrets.MAYHEM_URL }}
130137
mayhem-token: ${{ secrets.MAYHEM_TOKEN }}
131138
github-token: ${{ secrets.GITHUB_TOKEN }}
132-
args: --image forallsecure/lighttpd:vulnerable --file __tests__/Mayhemfile --duration 60
139+
package: __tests__/lighttpd
140+
args: --image forallsecure/lighttpd:vulnerable --duration 60
133141
# override the default owner which is forallsecure
134-
# the secrets.MAYHEM_TOKEN is this case is owned by vlussenburg, which is why we choose that owner here
135-
owner: vlussenburg
142+
# the secrets.MAYHEM_TOKEN is this case is owned by mcode-action, which is why we choose that owner here
143+
owner: mcode-action
136144
# override default verbosity which is info (contrary to what the `action.yml` says: https://github.com/ForAllSecure/mcode-action/blob/806778bb4a79d793f678087d0f9f3ff18f9a2d93/src/main.ts#L36)
137145
verbosity: debug
138146
# already covered and skipped in this test: mayhem-token, mayhem-url, github-token, sarif|junit|coverage-output, args
@@ -141,3 +149,32 @@ jobs:
141149
run: |
142150
[ -z "${{ steps.mcode-action.outputs.runId }}" ] && echo "runId was blank!" && exit 1;
143151
echo "The run id was: ${{ steps.mcode-action.outputs.runId }}"
152+
153+
test-fail-on-defects:
154+
# make sure the action works on a clean machine without building
155+
runs-on: ubuntu-latest
156+
steps:
157+
- uses: actions/checkout@v3
158+
with:
159+
# fetch entire history to compute diffs between jobs
160+
fetch-depth: 0
161+
162+
- uses: ./
163+
id: mcode-action
164+
continue-on-error: true
165+
with:
166+
mayhem-url: ${{ secrets.MAYHEM_URL }}
167+
mayhem-token: ${{ secrets.MAYHEM_TOKEN }}
168+
github-token: ${{ secrets.GITHUB_TOKEN }}
169+
package: __tests__/mayhemit
170+
args: --image forallsecure/c-base-executable:latest --duration 60
171+
fail-on-defects: true
172+
173+
# Previous step should fail
174+
- name: Invert success and failure
175+
run: if [[ ${{ steps.mcode-action.outcome }} == "failure" ]]; then exit 0; else exit 1; fi
176+
177+
- name: Print runId (${{ steps.mcode-action.outputs.runId }}) and test it's non-empty
178+
run: |
179+
[ -z "${{ steps.mcode-action.outputs.runId }}" ] && echo "runId was blank!" && exit 1;
180+
echo "The run id was: ${{ steps.mcode-action.outputs.runId }}"

__tests__/mayhemit/Mayhemfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
image: forallsecure/c-base-executable # fields are unnecessary
2+
duration: 60 # since they will
3+
project: forallsecure/mayhemit # be filled at
4+
target: mayhemit # run creation time
5+
tasks:
6+
# just do one quick task
7+
- name: regression_testing
8+
cmds:
9+
- cmd: /mayhemit @@

__tests__/mayhemit/testsuite/crash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bug

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ inputs:
3232
verbosity:
3333
description: verbosity level for starting runs
3434
required: false
35+
package:
36+
description: Path to the Mayhem package relative to the repository root
37+
required: false
38+
default: "."
3539
args:
3640
description: command line arguments to override CLI behavior
3741
required: false

dist/index.js

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ async function run(): Promise<void> {
3030
required: true,
3131
});
3232
const mayhemToken: string = core.getInput("mayhem-token") || githubToken;
33+
const packagePath: string = core.getInput("package") || ".";
3334
const sarifOutput: string = core.getInput("sarif-output") || "";
3435
const junitOutput: string = core.getInput("junit-output") || "";
3536
const coverageOutput: string = core.getInput("coverage-output") || "";
@@ -117,7 +118,7 @@ async function run(): Promise<void> {
117118
fi
118119
119120
# Run mayhem
120-
run=$(${cli} --verbosity ${verbosity} run . \
121+
run=$(${cli} --verbosity ${verbosity} run ${packagePath} \
121122
--project ${repo.toLowerCase()} \
122123
--owner ${owner} ${argsString});
123124
@@ -132,7 +133,10 @@ async function run(): Promise<void> {
132133
fi
133134
134135
# if the user didn't specify requiring any output, don't wait for the result.
135-
if [ -z "${coverageOutput}" ] && [ -z "${junitOutput}" ] && [ -z "${sarifOutput}" ]; then
136+
if [ -z "${coverageOutput}" ] && \
137+
[ -z "${junitOutput}" ] && \
138+
[ -z "${sarifOutput}" ] && \
139+
[ "${failOnDefects.toString().toLowerCase()}" != "true" ]; then
136140
echo "No coverage, junit or sarif output requested, not waiting for job result.";
137141
exit 0;
138142
fi

0 commit comments

Comments
 (0)