|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from owasp_mcp.collectors.top10 import TOP10_2021 |
| 4 | +from owasp_mcp.collectors.api_top10 import API_TOP10_2023 |
| 5 | +from owasp_mcp.collectors.llm_top10 import LLM_TOP10_2025 |
| 6 | +from owasp_mcp.collectors.proactive_controls import PROACTIVE_CONTROLS_2024 |
| 7 | +from owasp_mcp.collectors.mcp_top10 import MCP_TOP10_2025 |
| 8 | +from owasp_mcp.collectors.masvs import MASVS_DATA |
| 9 | +from owasp_mcp.collectors.cwe_data import CWE_DATABASE |
| 10 | + |
| 11 | + |
| 12 | +class TestTop10Data: |
| 13 | + def test_has_10_items(self): |
| 14 | + assert len(TOP10_2021) == 10 |
| 15 | + |
| 16 | + def test_all_have_required_fields(self): |
| 17 | + for item in TOP10_2021: |
| 18 | + assert "id" in item and "name" in item and "cwes" in item |
| 19 | + |
| 20 | + def test_ids_sequential(self): |
| 21 | + for i, item in enumerate(TOP10_2021, 1): |
| 22 | + assert item["id"] == f"A{str(i).zfill(2)}:2021" |
| 23 | + |
| 24 | + |
| 25 | +class TestApiTop10Data: |
| 26 | + def test_has_10_items(self): |
| 27 | + assert len(API_TOP10_2023) == 10 |
| 28 | + |
| 29 | + def test_all_have_required_fields(self): |
| 30 | + for item in API_TOP10_2023: |
| 31 | + assert all(k in item for k in ["id", "name", "description", "cwes", "url"]) |
| 32 | + |
| 33 | + def test_ids_sequential(self): |
| 34 | + for i, item in enumerate(API_TOP10_2023, 1): |
| 35 | + assert item["id"] == f"API{i}:2023" |
| 36 | + |
| 37 | + |
| 38 | +class TestLlmTop10Data: |
| 39 | + def test_has_10_items(self): |
| 40 | + assert len(LLM_TOP10_2025) == 10 |
| 41 | + |
| 42 | + def test_ids_format(self): |
| 43 | + for i, item in enumerate(LLM_TOP10_2025, 1): |
| 44 | + assert item["id"] == f"LLM{str(i).zfill(2)}:2025" |
| 45 | + |
| 46 | + |
| 47 | +class TestMcpTop10Data: |
| 48 | + def test_has_10_items(self): |
| 49 | + assert len(MCP_TOP10_2025) == 10 |
| 50 | + |
| 51 | + def test_ids_format(self): |
| 52 | + for i, item in enumerate(MCP_TOP10_2025, 1): |
| 53 | + assert item["id"] == f"MCP{str(i).zfill(2)}:2025" |
| 54 | + |
| 55 | + def test_all_have_impact(self): |
| 56 | + for item in MCP_TOP10_2025: |
| 57 | + assert "impact" in item and len(item["impact"]) > 10 |
| 58 | + |
| 59 | + |
| 60 | +class TestProactiveControlsData: |
| 61 | + def test_has_10_items(self): |
| 62 | + assert len(PROACTIVE_CONTROLS_2024) == 10 |
| 63 | + |
| 64 | + def test_ids_format(self): |
| 65 | + for i, item in enumerate(PROACTIVE_CONTROLS_2024, 1): |
| 66 | + assert item["id"] == f"C{i}" |
| 67 | + |
| 68 | + |
| 69 | +class TestMasvsData: |
| 70 | + def test_has_8_categories(self): |
| 71 | + assert len(MASVS_DATA) == 8 |
| 72 | + |
| 73 | + def test_category_ids(self): |
| 74 | + expected = ["MASVS-STORAGE", "MASVS-CRYPTO", "MASVS-AUTH", "MASVS-NETWORK", |
| 75 | + "MASVS-PLATFORM", "MASVS-CODE", "MASVS-RESILIENCE", "MASVS-PRIVACY"] |
| 76 | + actual = [cat_id for cat_id, _, _ in MASVS_DATA] |
| 77 | + assert actual == expected |
| 78 | + |
| 79 | + def test_total_controls(self): |
| 80 | + total = sum(len(controls) for _, _, controls in MASVS_DATA) |
| 81 | + assert total == 23 |
| 82 | + |
| 83 | + |
| 84 | +class TestCweDatabase: |
| 85 | + def test_has_entries(self): |
| 86 | + assert len(CWE_DATABASE) >= 30 |
| 87 | + |
| 88 | + def test_all_tuples(self): |
| 89 | + for entry in CWE_DATABASE: |
| 90 | + assert len(entry) == 3 |
| 91 | + cwe_id, name, desc = entry |
| 92 | + assert cwe_id.startswith("CWE-") |
| 93 | + assert len(name) > 5 |
| 94 | + assert len(desc) > 20 |
| 95 | + |
| 96 | + def test_key_cwes_present(self): |
| 97 | + ids = {e[0] for e in CWE_DATABASE} |
| 98 | + for key in ["CWE-79", "CWE-89", "CWE-918", "CWE-352", "CWE-287"]: |
| 99 | + assert key in ids, f"{key} missing from CWE database" |
0 commit comments