Skip to content

Commit 67945b0

Browse files
Merge pull request #15 from oddbit-project/development
Migrate tests to testcontainers and add CI workflows
2 parents 5785479 + 5e3ae68 commit 67945b0

9 files changed

Lines changed: 253 additions & 147 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master, development ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
name: Test (py${{ matrix.python-version }})
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
python-version: [ "3.10", "3.11", "3.12", "3.13", "3.14" ]
20+
steps:
21+
- uses: actions/checkout@v6
22+
- uses: actions/setup-python@v6
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
allow-prereleases: true
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip wheel setuptools
29+
pip install -e . -r requirements-dev.txt
30+
- name: Run tests (PostgreSQL + ClickHouse via testcontainers)
31+
run: python -m pytest --cov=rick_db --cov-report=term-missing
32+
33+
lint:
34+
name: Lint
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v6
38+
- uses: actions/setup-python@v6
39+
with:
40+
python-version: "3.12"
41+
- name: Install lint tools
42+
run: pip install flake8 black
43+
- name: flake8 (real errors)
44+
run: flake8 --select=E9,F63,F7,F82,F811 rick_db
45+
- name: black --check (advisory)
46+
# Advisory only: emit a clean notice on drift instead of a failing step.
47+
run: |
48+
black --check --diff rick_db \
49+
|| echo "::notice title=black::formatting drift detected (advisory; run 'black rick_db')"
50+
51+
build:
52+
name: Build
53+
runs-on: ubuntu-latest
54+
steps:
55+
- uses: actions/checkout@v6
56+
- uses: actions/setup-python@v6
57+
with:
58+
python-version: "3.12"
59+
- name: Build sdist + wheel
60+
run: |
61+
pip install build
62+
python -m build
63+
64+
security:
65+
name: Vulnerability + SAST
66+
runs-on: ubuntu-latest
67+
steps:
68+
- uses: actions/checkout@v6
69+
- uses: actions/setup-python@v6
70+
with:
71+
python-version: "3.12"
72+
- name: Install
73+
run: |
74+
python -m pip install --upgrade pip
75+
pip install -e . pip-audit bandit
76+
- name: pip-audit (dependency CVEs)
77+
# editable self-install is skipped; dependencies are still audited and
78+
# the step fails on any known CVE.
79+
run: pip-audit --skip-editable --desc
80+
- name: bandit (SAST)
81+
run: bandit -r rick_db -ll -x tests
82+
83+
ci-success:
84+
name: CI Success
85+
runs-on: ubuntu-latest
86+
needs: [ test, lint, build, security ]
87+
if: always()
88+
steps:
89+
- name: Verify all jobs passed
90+
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
91+
run: |
92+
echo "One or more required jobs failed."
93+
exit 1
94+
- name: Success
95+
run: echo "All CI jobs passed."

‎.github/workflows/run-tests.yml‎

Lines changed: 0 additions & 33 deletions
This file was deleted.

‎.github/workflows/sbom.yml‎

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,79 @@
1-
name: Generate SBOM
1+
name: Generate SBOMs and Scan
22

33
on:
44
release:
5-
types: [created]
6-
push:
7-
branches: [master]
5+
types: [ published ]
6+
7+
permissions:
8+
contents: write # upload SBOMs to the release
9+
id-token: write # cosign keyless signing
810

911
jobs:
1012
sbom:
1113
runs-on: ubuntu-latest
12-
13-
permissions:
14-
contents: write
14+
timeout-minutes: 15
15+
env:
16+
DTRACK_API_KEY: ${{ secrets.DTRACK_API_KEY }}
1517

1618
steps:
17-
- uses: actions/checkout@v4
18-
19-
- name: Set up Python
20-
uses: actions/setup-python@v5
21-
with:
22-
python-version: '3.12'
23-
24-
- name: Install dependencies
25-
run: |
26-
python -m pip install --upgrade pip
27-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
28-
29-
- name: Generate SBOM
30-
uses: anchore/sbom-action@v0
31-
with:
32-
artifact-name: rick_db-sbom.spdx.json
33-
output-file: rick_db-sbom.spdx.json
34-
upload-release-assets: ${{ github.event_name == 'release' }}
19+
- name: Checkout repository
20+
uses: actions/checkout@v6
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v6
24+
with:
25+
python-version: "3.12"
26+
27+
- name: Install package + cyclonedx-py
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install . cyclonedx-bom
31+
32+
- name: Generate CycloneDX SBOM
33+
run: cyclonedx-py environment -o sbom-cyclonedx.json --output-format JSON
34+
35+
- name: Upload SBOM to Dependency-Track
36+
if: ${{ env.DTRACK_API_KEY != '' }}
37+
env:
38+
PROJECT_NAME: ${{ github.event.repository.name }}
39+
PROJECT_VERSION: ${{ github.ref_name }}
40+
run: |
41+
curl -sSf -X POST "https://dtrack.blackshield.dev/api/v1/bom" \
42+
-H "X-Api-Key: ${DTRACK_API_KEY}" \
43+
-F "autoCreate=true" \
44+
-F "projectName=${PROJECT_NAME}" \
45+
-F "projectVersion=${PROJECT_VERSION}" \
46+
-F "bom=@sbom-cyclonedx.json"
47+
48+
- name: Install Syft
49+
run: curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
50+
51+
- name: Install Grype
52+
run: curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
53+
54+
- name: Install Cosign
55+
uses: sigstore/cosign-installer@v3
56+
57+
- name: Generate SPDX SBOM
58+
run: syft . -o spdx-json > sbom-spdx.json
59+
60+
- name: Scan CycloneDX SBOM
61+
run: grype sbom:sbom-cyclonedx.json --fail-on high --output table
62+
63+
- name: Scan SPDX SBOM
64+
run: grype sbom:sbom-spdx.json --fail-on high --output table
65+
66+
- name: Sign CycloneDX SBOM
67+
run: cosign sign-blob --yes sbom-cyclonedx.json --output-signature sbom-cyclonedx.json.sig
68+
69+
- name: Sign SPDX SBOM
70+
run: cosign sign-blob --yes sbom-spdx.json --output-signature sbom-spdx.json.sig
71+
72+
- name: Upload SBOMs to release
73+
uses: softprops/action-gh-release@v3
74+
with:
75+
files: |
76+
sbom-cyclonedx.json
77+
sbom-cyclonedx.json.sig
78+
sbom-spdx.json
79+
sbom-spdx.json.sig

‎CHANGELOG.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Changelog
22

3+
## [2.2.3]
4+
5+
### Security
6+
7+
#### Medium
8+
- **sql/dialect.py, sql/common.py**: Fixed SQL injection in JSON path handling. The `path` argument of `json_extract()`, `json_extract_text()`, `json_contains_path()`, `json_path_query()` and the corresponding `JsonField`/`PgJsonField` helpers was interpolated into the generated SQL wrapped in single quotes without escaping embedded quotes. A JSON path sourced from untrusted input could break out of the string literal and inject arbitrary SQL. Embedded single quotes are now escaped (doubled) via a new `SqlDialect._quote_str()` helper across all dialects (PostgreSQL, MySQL, ClickHouse, SQLite, default). Note: JSON paths are still interpolated, not parameterized — callers should continue to treat them as code, not data.
9+
10+
#### Low
11+
- **sql/common.py**: `PgJsonField.__getitem__` (square-bracket key access) now emits a single-quoted, quote-escaped JSON key (`data->'name'`) instead of a double-quoted one (`data->"name"`). The previous form was parsed by PostgreSQL as an identifier reference rather than a JSON key (a correctness bug) and did not escape the key.
12+
- **cli/commands/dto.py**: The `dto` code generator interpolated database-derived table, schema, and column names into single-quoted Python string literals without escaping. A maliciously named database object could inject code into the generated DTO module. Identifier string values are now emitted via `repr()`, and attribute names are validated as Python identifiers (raising an error otherwise) before being written.
13+
14+
### Changed
15+
- Dependencies bumped to latest releases: `psycopg2`/`psycopg2-binary` 2.9.12, `toml` 0.10.2, `setuptools` 82.0.1, `clickhouse-connect` >=1.1.1, and dev tooling (`pytest` 9.0.3, `pytest-cov` 7.1.0, `coverage` 7.14.1, `tox` 4.55.0, `mkdocs-material` 9.7.6, `mdx-include` 1.4.2).
16+
- **Testing**: Replaced the `tox-docker` setup with [testcontainers](https://testcontainers.com/). The PostgreSQL and ClickHouse containers used by the integration tests are now started and stopped from `tests/conftest.py` (session-scoped fixtures), so the suite can be run with a plain `pytest` invocation and no longer depends on `tox` or environment-variable wiring. Removed the `[docker:*]` sections from `tox.ini` and swapped `tox-docker` for `testcontainers[postgres]` in `requirements-dev.txt`.
17+
18+
### CI
19+
- Added a `CI` GitHub Actions workflow (test matrix on Python 3.10–3.14, flake8/black lint, build, `pip-audit` + `bandit` security scan, gated by a `ci-success` job).
20+
- Reworked the SBOM workflow to generate CycloneDX + SPDX SBOMs, scan them with Grype, sign them with Cosign, and upload them to the release (with optional Dependency-Track submission).
21+
322
## [2.2.2]
423

524
### Added

‎CLAUDE.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,10 @@ for event in conn.profiler.get_events():
650650
tests/backend/sqlite/ tests/repository/test_sqlite_repository.py \
651651
tests/dbgrid/test_sqlite_dbgrid.py tests/cursor/test_cursor_sqlite3.py -x -q
652652

653-
# Full suite with PostgreSQL (requires docker)
653+
# Full suite (PostgreSQL + ClickHouse via testcontainers, requires a docker daemon)
654+
# Containers are started/stopped automatically from tests/conftest.py — no env vars needed
655+
pytest
656+
# or across all supported Python versions
654657
tox -e py311
655658

656659
# Linting

‎README.md‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,15 @@ if __name__ == '__main__':
151151

152152
## Running tests
153153

154-
To run the tests, you should have both tox and tox-docker, as well as a local docker daemon. Make sure the current user has
155-
access to the docker daemon. The test suite uses PostgreSQL and ClickHouse docker containers.
156-
```python
154+
To run the tests, you need a local docker daemon and the current user must have access to it. The PostgreSQL and ClickHouse
155+
containers are started and stopped automatically by [testcontainers](https://testcontainers.com/) — no manual setup or
156+
environment variables are required.
157+
```shell
157158
$ pip3 install -r requirements-dev.txt
159+
160+
# run the whole suite directly
161+
$ pytest
162+
163+
# or across all supported Python versions
158164
$ tox
159165
```

‎requirements-dev.txt‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
pytest==9.0.2
2-
pytest-cov==7.0.0
1+
pytest==9.0.3
2+
pytest-cov==7.1.0
33
pytest-testdox==3.1.0
44
flake8==7.3.0
55
flake8_black==0.4.0
6-
coverage==7.13.4
7-
tox==4.49.1
8-
tox-docker==5.0.0
9-
psycopg2-binary==2.9.11
10-
clickhouse-connect>=0.7.0
11-
setuptools>=75.6.0
6+
coverage==7.14.1
7+
tox==4.55.0
8+
testcontainers[postgres]==4.14.2
9+
psycopg2-binary==2.9.12
10+
clickhouse-connect>=1.1.1
11+
setuptools>=82.0.1
1212
mkdocs
1313
mkdocs-material-extensions
14-
mkdocs-material==9.7.4
15-
mdx-include>=1.4.1
14+
mkdocs-material==9.7.6
15+
mdx-include>=1.4.2
1616
pymdown-extensions
1717
black

0 commit comments

Comments
 (0)