mcp-context-forge icon indicating copy to clipboard operation
mcp-context-forge copied to clipboard

[TASK][PLUGINS]: Add unit tests for secrets detection plugins

Open lucarlig opened this issue 9 months ago โ€ข 5 comments

โœ… Test Summary

Add unit tests for plugins/secrets_detection module covering pattern detection, container scanning.


๐Ÿงช Test Type

Choose one or more applicable categories:

  • [x] Unit tests (Python)
  • [ ] Integration / end-to-end tests
  • [ ] Manual UI testing (admin panel)
  • [ ] Transport coverage (HTTP, WebSocket, SSE, stdio)
  • [ ] Federation / multi-gateway testing
  • [ ] Configuration / environment-specific behavior
  • [ ] Other (explain below)

๐Ÿงฌ Scope & Affected Components

Select what this test covers or validates:

  • [ ] mcpgateway core (API logic, handlers)
  • [ ] Admin UI (HTMX / Alpine / Tailwind)
  • [ ] Tool/Resource/Prompt logic
  • [ ] Federation sync/discovery
  • [ ] Server interactions or SSE
  • [ ] Auth / JWT / security flows
  • [ ] Observability (logging, metrics)
  • [ ] Makefile, shell scripts or CLI
  • [ ] Containerized setup (Docker/Podman)
  • [x] Other: Plugin framework - secrets detection

๐Ÿ“‹ Acceptance Criteria

What should pass or be verified?

  • [x] All relevant assertions are covered
  • [ ] No side-effects or regressions observed
  • [ ] Confirmed in multiple environments (if needed)
  • [ ] Edge cases and error handling tested
  • [ ] Logs and output are clean and expected

๐Ÿ““ Additional Context & Steps

Include commands, expected behaviors, or test strategy.

# Run unit tests
pytest tests/unit/plugins/test_secrets_detection.py -v

lucarlig avatar Feb 12 '26 09:02 lucarlig

I'd like to work on this, I'll review the plugins/secrets_detection module and propose test coverage!

omorros avatar Feb 12 '26 10:02 omorros

Thanks for filing this. The plugins/secrets_detection module has 8 detection patterns (AWS keys, Google API keys, Slack tokens, private keys, JWTs, hex secrets, base64) but existing tests (tests/unit/plugins/test_secrets_detection.py) only cover the AWS secret pattern.

Key areas to test:

  • All 8 regex patterns with valid/invalid/boundary inputs
  • _scan_container() recursive scanning logic
  • Configuration options (redact, block_on_detection, min_findings_to_block)
  • The three hook methods (prompt_pre_fetch, tool_post_invoke, resource_post_fetch)

See tests/unit/plugins/test_unified_pdp_plugin.py for the mocking pattern and plugins/AGENTS.md for test guidelines.

crivetimihai avatar Feb 12 '26 19:02 crivetimihai

Hi @crivetimihai, I've already submitted a PR covering all of these areas: #2877

  • All 8 regex patterns with valid/invalid/boundary tests
  • _scan_container() recursive scanning and redaction
  • Configuration options (redact, block_on_detection, min_findings_to_block)
  • All three hooks (prompt_pre_fetch, tool_post_invoke, resource_post_fetch)
  • Edge cases (empty inputs, deep nesting, examples cap)
  • Also found and fixed a bug: payload.name โ†’ payload.prompt_id in the redaction path

97 tests total, all passing. Would appreciate a review when you get a chance! ;)

omorros avatar Feb 12 '26 19:02 omorros

Triage: Validated. Unit tests for secrets detection. Good first issue. Needs an assignee.

crivetimihai avatar Mar 07 '26 15:03 crivetimihai

this has been done in the new repository

lucarlig avatar Apr 29 '26 08:04 lucarlig