Skip to content

Add security tests for emu plugin#56

Merged
deacon-mp merged 1 commit intomasterfrom
fix/add-security-tests
Mar 18, 2026
Merged

Add security tests for emu plugin#56
deacon-mp merged 1 commit intomasterfrom
fix/add-security-tests

Conversation

@deacon-mp
Copy link
Copy Markdown
Contributor

Summary

  • Add tests/test_emu_security.py with security-focused tests for the emu plugin
  • Tests verify requirements.txt includes a CVE warning comment for the pyminizip dependency
  • Tests validate hook.py is parseable, defines async def enable(), and sets a plugin name
  • Tests confirm YAML files in conf/ are valid; data/ YAML checked when present (skipped otherwise)

Test plan

  • Run pytest plugins/emu/tests/test_emu_security.py -v from caldera root
  • Failing pyminizip test indicates a CVE warning comment should be added to requirements.txt

Add test_emu_security.py covering:
- requirements.txt: CVE warning comment for pyminizip dependency
- hook.py: parseable by ast.parse, defines enable() and name variable
- YAML validation: conf/ files are parseable, data/ files checked
  if present (skipped when data is not yet populated)
@sonarqubecloud
Copy link
Copy Markdown

@deacon-mp deacon-mp merged commit 4b1a8a1 into master Mar 18, 2026
3 of 6 checks passed
@deacon-mp deacon-mp deleted the fix/add-security-tests branch March 18, 2026 03:03
@deacon-mp deacon-mp requested a review from Copilot March 18, 2026 03:10
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new security-focused pytest module for the emu plugin to prevent common packaging/configuration regressions (dependency risk documentation, plugin entrypoint sanity, and YAML validity).

Changes:

  • Add tests to enforce a CVE/vulnerability warning comment near the pyminizip requirement.
  • Add tests to ensure hook.py is parseable and declares expected plugin entrypoint fields (async def enable, name).
  • Add tests to validate YAML files under conf/ and (optionally) data/.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +70 to +98
def test_hook_defines_enable_function(self):
"""hook.py must define an async 'enable' function."""
with open(HOOK_PATH, 'r') as f:
source = f.read()
tree = ast.parse(source)
enable_funcs = [
node for node in ast.walk(tree)
if isinstance(node, ast.AsyncFunctionDef) and node.name == 'enable'
]
assert len(enable_funcs) > 0, (
"hook.py must define an 'async def enable(...)' function"
)

def test_hook_defines_plugin_name(self):
"""hook.py should define a 'name' variable."""
with open(HOOK_PATH, 'r') as f:
source = f.read()
tree = ast.parse(source)
name_assignments = [
node for node in ast.walk(tree)
if isinstance(node, ast.Assign)
and any(
isinstance(target, ast.Name) and target.id == 'name'
for target in node.targets
)
]
assert len(name_assignments) > 0, (
"hook.py should define a 'name' variable for the plugin"
)
Comment on lines +24 to +48
with open(REQUIREMENTS_PATH, 'r') as f:
content = f.read()

# Verify pyminizip is listed
assert 'pyminizip' in content, (
"pyminizip not found in requirements.txt"
)

# Check for a CVE-related comment near the pyminizip line
lines = content.splitlines()
found_cve_comment = False
for i, line in enumerate(lines):
if 'pyminizip' in line.lower():
# Check this line and surrounding lines for CVE warning
context_start = max(0, i - 2)
context_end = min(len(lines), i + 3)
context = '\n'.join(lines[context_start:context_end])
if 'cve' in context.lower() or 'vulnerab' in context.lower():
found_cve_comment = True
break
assert found_cve_comment, (
"requirements.txt should have a comment warning about known "
"CVEs for pyminizip (e.g., '# WARNING: pyminizip has known "
"CVE vulnerabilities')"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants