Skip to content

Commit dec11c4

Browse files
committed
Normalize OWASP cheat sheet references
1 parent 7ea289c commit dec11c4

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

application/tests/cheatsheets_parser_test.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,37 @@ class Repo:
7272
self.maxDiff = None
7373
for name, nodes in entries.results.items():
7474
self.assertEqual(name, parser.name)
75-
self.assertEqual(len(nodes), 1)
76-
self.assertEqual(expected.todict(), nodes[0].todict())
75+
sections = {node.section for node in nodes}
76+
self.assertIn("Secrets Management Cheat Sheet", sections)
77+
secret_entry = [
78+
node
79+
for node in nodes
80+
if node.section == "Secrets Management Cheat Sheet"
81+
][0]
82+
self.assertEqual(expected.todict(), secret_entry.todict())
83+
84+
def test_register_supplemental_cheatsheets(self) -> None:
85+
for cre_id, name in [
86+
("118-110", "API/web services"),
87+
("724-770", "Technical application access control"),
88+
("623-550", "Denial Of Service protection"),
89+
]:
90+
self.collection.add_cre(defs.CRE(name=name, id=cre_id))
91+
92+
entries = cheatsheets_parser.Cheatsheets().register_supplemental_cheatsheets(
93+
cache=self.collection
94+
)
95+
rest = [
96+
entry for entry in entries if entry.section == "REST Security Cheat Sheet"
97+
][0]
98+
self.assertEqual(
99+
"https://cheatsheetseries.owasp.org/cheatsheets/REST_Security_Cheat_Sheet.html",
100+
rest.hyperlink,
101+
)
102+
self.assertEqual(
103+
["118-110", "724-770", "623-550"],
104+
[link.document.id for link in rest.links],
105+
)
77106

78107
cheatsheets_md = """ # Secrets Management Cheat Sheet
79108

application/utils/external_project_parsers/parsers/cheatsheets_parser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
class Cheatsheets(ParserInterface):
2020
name = "OWASP Cheat Sheets"
2121
cheatsheetseries_base_url = "https://cheatsheetseries.owasp.org/cheatsheets"
22+
supplement_data_file = (
23+
Path(__file__).resolve().parent.parent
24+
/ "data"
25+
/ "owasp_cheatsheets_supplement.json"
26+
)
27+
logger = logging.getLogger(__name__)
2228

2329
def cheatsheet(
2430
self, section: str, hyperlink: str, tags: List[str]

0 commit comments

Comments
 (0)