|
| 1 | +######## Insecure test cases. All of these use insecure packages, and should fail - so they have `continue-on-error` |
| 2 | +######## set on the action step, and a further step to ensure the previous step failed (and actually fail if it _didn't_) |
| 3 | +name: Safety Action Insecure Tests |
| 4 | + |
| 5 | +on: [push] |
| 6 | + |
| 7 | +jobs: |
| 8 | + ##### Auto mode tests |
| 9 | + ### File scanning |
| 10 | + # Scans a requirements.txt in the repo; the simplest case. We contort one into existing for this test |
| 11 | + # case, to avoid confusion |
| 12 | + test-auto-requirements-txt-insecure: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + environment: main |
| 15 | + |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v2 |
| 18 | + |
| 19 | + - run: cp tests/action/requirements.txt-insecure requirements.txt |
| 20 | + |
| 21 | + - uses: ./ |
| 22 | + id: scan-1 |
| 23 | + continue-on-error: true |
| 24 | + with: |
| 25 | + api-key: ${{ secrets.SAFETY_API_KEY }} |
| 26 | + |
| 27 | + - if: steps.scan-1.outcome != 'failure' || steps.scan-1.outputs.exit-code != '64' |
| 28 | + run: exit 1 |
| 29 | + |
| 30 | + # Same as above, but for a poetry lock file |
| 31 | + test-auto-poetry-insecure: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + environment: main |
| 34 | + |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v2 |
| 37 | + |
| 38 | + - run: cp tests/action/poetry.lock-insecure poetry.lock && cp tests/action/pyproject.toml-insecure pyproject.toml |
| 39 | + |
| 40 | + - uses: ./ |
| 41 | + id: scan-2 |
| 42 | + continue-on-error: true |
| 43 | + with: |
| 44 | + api-key: ${{ secrets.SAFETY_API_KEY }} |
| 45 | + |
| 46 | + - if: steps.scan-2.outcome != 'failure' || steps.scan-2.outputs.exit-code != '64' |
| 47 | + run: exit 1 |
| 48 | + |
| 49 | + # Same as above, but for a Pipfile.lock |
| 50 | + test-auto-pipfile-insecure: |
| 51 | + runs-on: ubuntu-latest |
| 52 | + environment: main |
| 53 | + |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v2 |
| 56 | + |
| 57 | + - run: cp tests/action/Pipfile.lock-insecure Pipfile.lock |
| 58 | + |
| 59 | + - uses: ./ |
| 60 | + id: scan-3 |
| 61 | + continue-on-error: true |
| 62 | + with: |
| 63 | + api-key: ${{ secrets.SAFETY_API_KEY }} |
| 64 | + |
| 65 | + - if: steps.scan-3.outcome != 'failure' || steps.scan-3.outputs.exit-code != '64' |
| 66 | + run: exit 1 |
| 67 | + |
| 68 | + ### Env scanning: |
| 69 | + ### Scans the runner environment. Here, the Github action `actions/setup-python@v3` actually |
| 70 | + ### installs things in the root VM that the action runs on; this is what gets scanned. |
| 71 | + test-auto-environment-insecure: |
| 72 | + runs-on: ubuntu-latest |
| 73 | + environment: main |
| 74 | + |
| 75 | + steps: |
| 76 | + - uses: actions/checkout@v2 |
| 77 | + |
| 78 | + - uses: actions/setup-python@v3 |
| 79 | + with: |
| 80 | + python-version: '3.10' |
| 81 | + architecture: 'x64' |
| 82 | + |
| 83 | + - run: python -m pip install -r tests/action/requirements.txt-insecure |
| 84 | + |
| 85 | + - uses: ./ |
| 86 | + id: scan-4 |
| 87 | + continue-on-error: true |
| 88 | + with: |
| 89 | + api-key: ${{ secrets.SAFETY_API_KEY }} |
| 90 | + |
| 91 | + - if: steps.scan-4.outcome != 'failure' || steps.scan-4.outputs.exit-code != '64' |
| 92 | + run: exit 1 |
| 93 | + |
| 94 | + ### Docker scanning: |
| 95 | + ### Scans a recently built Docker container. This uses a few heuristics, defined in entrypoint.sh |
| 96 | + test-auto-docker-insecure: |
| 97 | + runs-on: ubuntu-latest |
| 98 | + environment: main |
| 99 | + |
| 100 | + steps: |
| 101 | + - uses: actions/checkout@v2 |
| 102 | + |
| 103 | + - name: Build image |
| 104 | + run: DOCKER_BUILDKIT=1 docker build -t my-insecure-image tests/action/docker-insecure |
| 105 | + |
| 106 | + - uses: ./ |
| 107 | + id: scan-5 |
| 108 | + continue-on-error: true |
| 109 | + with: |
| 110 | + api-key: ${{ secrets.SAFETY_API_KEY }} |
| 111 | + |
| 112 | + - if: steps.scan-5.outcome != 'failure' || steps.scan-5.outputs.exit-code != '64' |
| 113 | + run: exit 1 |
0 commit comments