-
Notifications
You must be signed in to change notification settings - Fork 0
🧪 QA: Add SOC2 compliance monitor tests #327
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
base: staging
Are you sure you want to change the base?
Changes from all commits
3bfe5c9
c7a1aa2
e3f8cc5
a78e452
8880f7f
282a0a7
52a4763
caebe6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import pytest | ||
| import sys | ||
| import os | ||
| import importlib.util | ||
|
|
||
| spec = importlib.util.spec_from_file_location("compliance_monitor", "security/compliance-monitor.py") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The module import uses a cwd-relative path; running pytest from a non-root working directory will fail to locate Prompt for AI agents |
||
| compliance_monitor = importlib.util.module_from_spec(spec) | ||
| spec.loader.exec_module(compliance_monitor) | ||
|
Comment on lines
+6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The module path is resolved relative to the current working directory ( SuggestionResolve the module path relative to the test file and validate from pathlib import Path
import importlib.util
MODULE_PATH = Path(__file__).resolve().parents[1] / "security" / "compliance-monitor.py"
spec = importlib.util.spec_from_file_location("compliance_monitor", MODULE_PATH)
assert spec and spec.loader
compliance_monitor = importlib.util.module_from_spec(spec)
spec.loader.exec_module(compliance_monitor)Reply with "@CharlieHelps yes please" if you’d like me to add a commit with this change. |
||
|
|
||
| def test_monitor_soc2_compliance_all_pass(): | ||
| monitor = compliance_monitor.ComplianceMonitor() | ||
| result = monitor.monitor_soc2_compliance() | ||
|
|
||
| assert result["framework"] == "SOC2" | ||
| assert result["compliance_score"] == 100.0 | ||
| assert result["status"] == "compliant" | ||
|
|
||
| checks = result["checks"] | ||
| assert checks["access_controls"] is True | ||
| assert checks["system_monitoring"] is True | ||
| assert checks["data_encryption"] is True | ||
| assert checks["backup_procedures"] is True | ||
| assert checks["incident_response"] is True | ||
|
|
||
| def test_monitor_soc2_compliance_partial_fail(): | ||
| monitor = compliance_monitor.ComplianceMonitor() | ||
|
|
||
| monitor.check_access_controls = lambda: False | ||
| monitor.check_data_encryption = lambda: False | ||
|
|
||
| result = monitor.monitor_soc2_compliance() | ||
|
|
||
| assert result["framework"] == "SOC2" | ||
| assert result["compliance_score"] == 60.0 | ||
| assert result["status"] == "non_compliant" | ||
|
|
||
| checks = result["checks"] | ||
| assert checks["access_controls"] is False | ||
| assert checks["system_monitoring"] is True | ||
| assert checks["data_encryption"] is False | ||
| assert checks["backup_procedures"] is True | ||
| assert checks["incident_response"] is True | ||
|
|
||
|
Comment on lines
+10
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests partially rely on the real implementations of other SuggestionMake the tests deterministic by monkeypatching all def test_monitor_soc2_compliance_all_pass(monkeypatch):
monitor = compliance_monitor.ComplianceMonitor()
monkeypatch.setattr(monitor, "check_access_controls", lambda: True)
monkeypatch.setattr(monitor, "check_system_monitoring", lambda: True)
monkeypatch.setattr(monitor, "check_data_encryption", lambda: True)
monkeypatch.setattr(monitor, "check_backup_procedures", lambda: True)
monkeypatch.setattr(monitor, "check_incident_response", lambda: True)
...Reply with "@CharlieHelps yes please" if you’d like me to add a commit applying this pattern to all scenarios. |
||
| def test_monitor_soc2_compliance_edge_cases(): | ||
| monitor = compliance_monitor.ComplianceMonitor() | ||
|
|
||
| monitor.check_access_controls = lambda: False | ||
| monitor.check_system_monitoring = lambda: False | ||
| monitor.check_data_encryption = lambda: False | ||
| monitor.check_backup_procedures = lambda: False | ||
| monitor.check_incident_response = lambda: False | ||
|
|
||
| result = monitor.monitor_soc2_compliance() | ||
|
|
||
| assert result["compliance_score"] == 0.0 | ||
| assert result["status"] == "non_compliant" | ||
|
|
||
| def test_monitor_soc2_compliance_just_below_threshold(): | ||
| monitor = compliance_monitor.ComplianceMonitor() | ||
|
|
||
| monitor.check_access_controls = lambda: False | ||
|
|
||
| result = monitor.monitor_soc2_compliance() | ||
|
|
||
| assert result["compliance_score"] == 80.0 | ||
| assert result["status"] == "non_compliant" | ||
|
Comment on lines
+15
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The assertions compare floating-point values with exact equality. If the score is computed via division (even with “nice” decimals), minor representation differences can cause brittle failures across Python versions/implementations. SuggestionUse assert result["compliance_score"] == pytest.approx(60.0)Reply with "@CharlieHelps yes please" if you’d like me to add a commit with this change. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These imports are unused in this test module, which adds noise and can trip Python linting if it’s enabled in your CI/tooling.
Suggestion
Remove unused imports (
sys,os) and keep only what’s needed.Reply with "@CharlieHelps yes please" if you’d like me to add a commit with this cleanup.