test : add unit tests for NetworkPolicyEngine audit export methods

オープン
#2,447 コメント 2 件 リアクション 0 件 担当者 1 名 GitHub で見る

@Rafiaminhaj がすでに取り組んでいます。

2026年8月15日 から。

評価

この issue はまだ評価されていません。

説明

Summary of What Needs to be Done:
Add unit tests for the export_audit_log and clear_audit_entries methods of NetworkPolicyEngine in backend/secuscan/network_policy.py. These methods are not covered by the existing test_network_policy.py suite which focuses on check_access and policy enforcement logic.

The methods require patching the backend.secuscan.config module (which imports Pydantic) so the engine can be instantiated with test settings. Both methods have substantial logic worth testing: export_audit_log formats audit entries as JSON or CSV, and clear_audit_entries removes all entries from memory.

Changes that Need to be Made:
Create testing/backend/unit/test_network_policy_audit_export.py:

  • Patch sys.modules['backend.secuscan.config'] with a mock config module before importing NetworkPolicyEngine and PolicyAction
  • export_audit_log(format="json"): Test that it returns valid JSON with expected fields (timestamp, plugin_id, task_id, action, dest_ip, dest_port, reason)
  • export_audit_log(format="csv"): Test that it returns valid CSV with header row and data rows
  • export_audit_log(format="csv"): Test that empty audit log produces just the header row
  • clear_audit_entries(): Test that it removes all entries after entries have been added
  • clear_audit_entries(): Test that calling it on an already-empty log is safe (no exception)
  • get_audit_entries() as a companion: verify it returns entries before clear and empty list after
  • Use a temp file path for audit_log_path and max_audit_entries=1000 in the engine constructor
  • Import the real production class directly (not mocked)
  • Run with python3 -m pytest testing/backend/unit/test_network_policy_audit_export.py -v --noconftest

Impact that it would Provide:

  • Tests audit log export functionality that is currently completely untested
  • Prevents regressions in the JSON and CSV export formatting logic
  • Ensures the clear operation is idempotent and safe on empty state
  • Complements the existing TestAuditLogging class which only tests audit entry creation, not export/clear

Note: This task is being handled by tmdeveloper007 — please assign to that account when picking it up.

主要言語
Python
スター
36
フォーク
234
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

utksh1/SecuScan のほかの issue

utksh1/SecuScan の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。