Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: test for security issues with bandit #609

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,30 @@ jobs:
- name: Run tox
run: poetry run tox r -e mypy-${{ matrix.toxenv-factor }} -s false

security-issues:
name: find Security Issues
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
# see https://github.com/actions/checkout
uses: actions/checkout@v4
- name: Setup Python Environment
# see https://github.com/actions/setup-python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION_DEFAULT }}
architecture: 'x64'
- name: Install poetry
# see https://github.com/marketplace/actions/setup-poetry
uses: Gr1N/setup-poetry@v8
with:
poetry-version: ${{ env.POETRY_VERSION }}
- name: Install dependencies
run: poetry install --no-root
- name: Run tox
run: poetry run tox run -e bandit -s false

build-and-test:
name: Test (${{ matrix.os }} py${{ matrix.python-version }} ${{ matrix.toxenv-factor }})
runs-on: ${{ matrix.os }}
Expand Down
9 changes: 9 additions & 0 deletions bandit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# https://bandit.readthedocs.io
# filename must be like this, so codacy can pick it up: https://github.com/codacy/codacy-bandit/blob/master/src/main/scala/codacy/bandit/Bandit.scala#L35C49-L35C59

exclude_dirs:
- docs
- .venv

skips:
- B101
230 changes: 229 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ flake8-isort = "6.0.0"
isort = "5.12.0"
autopep8 = "2.0.4"
mypy = "1.5.1"
bandit = "1.7.5"
tox = "4.11.3"
# `types-toml` need to stay in sync with version of `toml`
types-toml = "^0.10.0"
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_can_call_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) OWASP Foundation. All Rights Reserved.

import subprocess
import subprocess # nosec B404
import sys
from unittest import TestCase

Expand All @@ -31,10 +31,10 @@ def test_callable_as_module(self) -> None:

# Test whether the call passed, is fair enough for now.
# Additional tests may come later, to check output etc.
ran = subprocess.run(
ran = subprocess.run( # nosec B603
args,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=False,
shell=False
)

self.assertEqual(0, ran.returncode, msg='subprocess returned unexpected non-zero\n'
Expand Down
5 changes: 5 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ envlist =
flake8
mypy-{locked,lowest}
py{311,310,39,38}-{locked,lowest}
bandit
skip_missing_interpreters = True
usedevelop = False
download = False
Expand Down Expand Up @@ -37,3 +38,7 @@ commands =
skip_install = True
commands =
poetry run flake8 cyclonedx_py/ tests/

[testenv:bandit]
commands =
poetry run bandit -c bandit.yml -v -r cyclonedx_py tests