feat: configure hypothesis fuzzing and bandit security scanning#72
feat: configure hypothesis fuzzing and bandit security scanning#72
Conversation
- Add hypothesis to testing requirements in setup.cfg - Add property-based fuzz tests for DeviceStatus model in tests/test_mqtt_hypothesis.py - Add bandit environment to tox.ini for security linting - Add security job to GitHub Actions workflow to run bandit
- Fix import sorting and remove duplicate imports - Fix line length violations (>80 characters) - Remove trailing whitespace and blank line whitespace - Ensure proper code formatting for CI compliance
- Fix line length violations in comments (>80 characters) - Ensure all ruff linting checks pass - All tests continue to pass locally
- Add .bandit configuration file to skip B101 (assert_used) warnings - Update tox.ini bandit environment to use configuration file - Security check now passes while maintaining security scanning for actual vulnerabilities - Assert statements in CLI rich output are low-severity and acceptable for this use case
There was a problem hiding this comment.
Pull request overview
This PR adds property-based fuzz testing with Hypothesis and introduces Bandit security scanning via tox and GitHub Actions to improve test robustness and CI security checks.
Changes:
- Added Hypothesis as a testing dependency and introduced a new property-based fuzz test suite for
DeviceStatus. - Added a
bandittox environment and a dedicated CI job to run security scanning. - Added a
.banditconfiguration file to control Bandit rule behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
tox.ini |
Adds a bandit tox env and includes it in the envlist for security scanning. |
tests/test_mqtt_hypothesis.py |
Adds Hypothesis-based fuzz tests validating DeviceStatus parsing and unit conversions. |
setup.cfg |
Adds hypothesis under testing extras. |
.github/workflows/ci.yml |
Adds a separate CI job to run tox -e bandit. |
.bandit |
Configures Bandit skips (currently B101). |
- Fix flow rate test to use lenient tolerance (abs=0.01) instead of manual rounding This avoids brittle assumptions about the converter's rounding behavior and instead relies on pytest.approx() to account for the model's 2-decimal rounding - Improve bandit security scanning configuration Replaced global B101 skip with file-specific skip for src/nwp500/cli/rich_output.py This maintains security scanning rigor while acknowledging that assert statements are acceptable for type-narrowing checks in CLI optional feature code - Note: 'heLowerOnTDiffempSetting' field name retains the API's existing typo as documented in the model's alias - this is the correct key expected by the DeviceStatus model validation All 403 tests passing, security and linting checks passing
eman
left a comment
There was a problem hiding this comment.
Addressing review comments:
-
Line 96 - heLowerOnTDiffempSetting: This is the correct field name; it reflects an actual typo in the Navien cloud API payload. The model correctly handles this with an alias mapping
"heLowerOnTDiffempSetting"tohe_lower_on_diff_temp_setting. The test payload intentionally uses the API's typo to validate the model's alias handling. -
Lines 48 & 69 - recircOperationBusy: These are NOT duplicates. Line 48 defines
operationBusy(on line 48, different key), and line 69 definesrecircOperationBusy. The reviewer may have misread the line numbers. Both keys are needed in the test payload. -
Rounding in flow rate test: Updated to use
pytest.approx(gpm_val, abs=0.01)with 0.01 tolerance instead of manual rounding. This is now tolerance-based and resilient to model rounding changes. -
.bandit Configuration: Updated from global
B101skip to file-specific skip targeting onlysrc/nwp500/cli/rich_output.pywhere asserts are used for type-narrowing when rich library is available. This maintains security rigor for the rest of the codebase.
|
Re: Line 96 - heLowerOnTDiffempSetting This is the correct field name reflecting an actual typo in the Navien API payload. The model correctly handles this with an alias mapping |
|
Re: Lines 48 & 69 - recircOperationBusy These are NOT duplicates. Line 48 defines |
|
Re: Flow rate test rounding Updated to use |
|
Re: .bandit B101 global skip Updated from global |
Summary
This PR adds comprehensive security and fuzzing capabilities to the nwp500-python project:
Changes Made
Testing Infrastructure
hypothesisto testing requirements insetup.cfgtests/test_mqtt_hypothesis.pywith property-based fuzz tests for:Security Enhancements
banditenvironment totox.inifor security lintingCode Quality
Testing
Breaking Changes
None. This is a purely additive feature that enhances security and test coverage.