Skip to content

Commit 8adf7c6

Browse files
authored
Fix tests, add lint and test workflows (#20)
* Added urlopen version of safe_requests get * Added test workflow and some linting * Added pre-commit hooks + overall linting * Added test instructions for readme * Removed nonexistent exclusions in pre-commit config
1 parent 780b236 commit 8adf7c6

File tree

16 files changed

+740
-340
lines changed

16 files changed

+740
-340
lines changed

.github/workflows/lint.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
merge_group:
11+
12+
concurrency:
13+
group: (${{ github.workflow }}-${{ github.event.inputs.branch || github.event.pull_request.head.ref }})
14+
cancel-in-progress: true
15+
16+
jobs:
17+
pre-commit:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
- uses: actions/setup-python@v5
22+
- uses: pre-commit/[email protected]

.github/workflows/test.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
merge-group:
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
build:
18+
name: Build Package
19+
runs-on: ubuntu-22.04
20+
timeout-minutes: 5
21+
steps:
22+
- name: Check out code
23+
uses: actions/checkout@v4
24+
- name: Set Up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: '3.12'
28+
cache: 'pip'
29+
- name: Install build dependencies
30+
run: pip install build twine
31+
- name: Build package
32+
run: python -m build .
33+
- name: Twine Check
34+
run: twine check dist/*
35+
test:
36+
name: Run pytest
37+
runs-on: ubuntu-22.04
38+
timeout-minutes: 25
39+
strategy:
40+
matrix:
41+
python-version: ['3.10', '3.11', '3.12']
42+
steps:
43+
- name: install netcat
44+
run: apt update && apt install -y netcat
45+
- name: make bash default shell
46+
run: ln -sf /bin/bash /bin/sh
47+
- name: Check out code
48+
uses: actions/checkout@v4
49+
- name: Set Up Python
50+
uses: actions/setup-python@v5
51+
with:
52+
python-version: ${{ matrix.python-version }}
53+
cache: 'pip'
54+
- name: Install Codemodder Package
55+
run: pip install .
56+
- name: Install Dependencies
57+
run: pip install -r dev_requirements.txt
58+
- name: Run unit tests
59+
run: pytest

.pre-commit-config.yaml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v2.3.0
3+
rev: v4.6.0
44
hooks:
55
- id: check-yaml
66
- id: check-json
77
- id: end-of-file-fixer
88
- id: trailing-whitespace
99
- id: check-added-large-files
1010
- repo: https://github.com/psf/black
11-
rev: 23.3.0
11+
rev: 24.4.0
1212
hooks:
1313
- id: black
14+
- repo: https://github.com/pre-commit/mirrors-mypy
15+
rev: v1.9.0
16+
hooks:
17+
- id: mypy
18+
args: [--disable-error-code=has-type,--disable-error-code=import-not-found]
19+
additional_dependencies:
20+
[
21+
"types-jsonschema~=4.21.0",
22+
"types-mock==5.0.*",
23+
"types-PyYAML==6.0",
24+
"types-toml~=0.10",
25+
"types-requests~=2.13",
26+
]
27+
- repo: https://github.com/astral-sh/ruff-pre-commit
28+
rev: v0.3.7
29+
hooks:
30+
- id: ruff
31+
# todo: replace black with this?
32+
# Run the formatter.
33+
# - id: ruff-format
34+
- repo: https://github.com/pycqa/isort
35+
rev: 5.13.2
36+
hooks:
37+
- id: isort
38+
args: ["--profile", "black"]

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include README.md LICENSE.txt
1+
include README.md LICENSE.txt

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ Many of the APIs provided are meant to be drop-in replacements that either offer
1010
To install this package from PyPI, use the following command:
1111

1212
`pip install security`
13+
14+
## Running tests
15+
16+
DO NOT RUN TESTS LOCALLY WITHOUT A VM/CONTAINER.
17+
18+
Tests will try to run "dangerous" commands (i.e. curl, netcat, etc.) and try to access sensitive files (i.e. sudoers, passwd, etc.). We do so to test the our abilities to detect and filter these types of attacks.
19+
20+
While all these commands are devised as innocuous, it is still not a good idea to risk exposure. They also require a specific environment to pass. We recommend using something like [act](https://github.com/nektos/act) to run the github workflow locally within a container for local development.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
from .api import call, run
2+
3+
__all__ = ["call", "run"]

0 commit comments

Comments
 (0)