-
Notifications
You must be signed in to change notification settings - Fork 119
Add refresh scripts for OWASP resources for issue 471 #877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Bornunique911
wants to merge
10
commits into
OWASP:main
Choose a base branch
from
Bornunique911:review/issue-471-refresh-scripts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
18f1a01
Add OWASP Top 10 and API importer support
Bornunique911 52de3f1
Fix cheat sheet parser test expectations on importer branches
Bornunique911 eb188ab
Use official OWASP cheat sheet URLs in importer branches
Bornunique911 27eb728
Add OWASP AI resource importer support
Bornunique911 42ba35d
Add OWASP Kubernetes importer support
Bornunique911 133f171
Normalize OWASP cheat sheet references
Bornunique911 cd70509
Add refresh scripts for OWASP resources
Bornunique911 e0e8b08
Refactor links definition in TestCheatsheetsParser for clarity
Bornunique911 f2f85f4
Add support for OWASP Top 10 resources and update test cases for cons…
Bornunique911 71a51b1
Fix logger reference in Cheatsheets parser and add database existence…
Bornunique911 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import unittest | ||
|
|
||
| from application import create_app, sqla # type: ignore | ||
| from application.database import db | ||
| from application.defs import cre_defs as defs | ||
| from application.prompt_client import prompt_client | ||
| from application.utils.external_project_parsers.parsers import owasp_aisvs | ||
|
|
||
|
|
||
| class TestOwaspAisvsParser(unittest.TestCase): | ||
| def tearDown(self) -> None: | ||
| sqla.session.remove() | ||
| sqla.drop_all() | ||
| self.app_context.pop() | ||
|
|
||
| def setUp(self) -> None: | ||
| self.app = create_app(mode="test") | ||
| self.app_context = self.app.app_context() | ||
| self.app_context.push() | ||
| sqla.create_all() | ||
| self.collection = db.Node_collection() | ||
|
|
||
| def test_parse(self) -> None: | ||
| for cre_id, name in [ | ||
| ("227-045", "Identify sensitive data and subject it to a policy"), | ||
| ( | ||
| "307-507", | ||
| "Allow only trusted sources both build time and runtime; therefore perform integrity checks on all resources and code", | ||
| ), | ||
| ( | ||
| "162-655", | ||
| "Documentation of all components' business or security function", | ||
| ), | ||
| ]: | ||
| self.collection.add_cre(defs.CRE(id=cre_id, name=name, description="")) | ||
|
|
||
| result = owasp_aisvs.OwaspAisvs().parse( | ||
| self.collection, prompt_client.PromptHandler(database=self.collection) | ||
| ) | ||
|
|
||
| entries = result.results["OWASP AI Security Verification Standard (AISVS)"] | ||
| self.assertEqual(14, len(entries)) | ||
| self.assertEqual("AISVS1", entries[0].sectionID) | ||
| self.assertEqual( | ||
| "Training Data Governance & Bias Management", entries[0].section | ||
| ) | ||
| self.assertEqual( | ||
| "https://github.com/OWASP/AISVS/blob/main/1.0/en/0x10-C01-Training-Data-Integrity-and-Traceability.md", | ||
| entries[0].hyperlink, | ||
| ) | ||
| self.assertEqual( | ||
| ["227-045", "307-507"], | ||
| [link.document.id for link in entries[0].links], | ||
| ) | ||
| self.assertEqual("AISVS14", entries[-1].sectionID) | ||
| self.assertEqual( | ||
| "Human Oversight, Accountability & Governance", entries[-1].section | ||
| ) | ||
| self.assertEqual( | ||
| "https://github.com/OWASP/AISVS/blob/main/1.0/en/0x10-C14-Human-Oversight.md", | ||
| entries[-1].hyperlink, | ||
| ) | ||
| self.assertEqual( | ||
| ["162-655"], | ||
| [link.document.id for link in entries[-1].links], | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import unittest | ||
|
|
||
| from application import create_app, sqla # type: ignore | ||
| from application.database import db | ||
| from application.defs import cre_defs as defs | ||
| from application.prompt_client import prompt_client | ||
| from application.utils.external_project_parsers.parsers import owasp_api_top10_2023 | ||
|
|
||
|
|
||
| class TestOwaspApiTop10_2023Parser(unittest.TestCase): | ||
| def tearDown(self) -> None: | ||
| sqla.session.remove() | ||
| sqla.drop_all() | ||
| self.app_context.pop() | ||
|
|
||
| def setUp(self) -> None: | ||
| self.app = create_app(mode="test") | ||
| self.app_context = self.app.app_context() | ||
| self.app_context.push() | ||
| sqla.create_all() | ||
| self.collection = db.Node_collection() | ||
|
|
||
| def test_parse(self) -> None: | ||
| for cre_id, name in [ | ||
| ("304-667", "Protect API against unauthorized access/modification (IDOR)"), | ||
| ("724-770", "Technical application access control"), | ||
| ("715-223", "Ensure trusted origin of third party resources"), | ||
| ]: | ||
| self.collection.add_cre(defs.CRE(id=cre_id, name=name, description="")) | ||
|
|
||
| result = owasp_api_top10_2023.OwaspApiTop10_2023().parse( | ||
| self.collection, prompt_client.PromptHandler(database=self.collection) | ||
| ) | ||
|
|
||
| entries = result.results["OWASP API Security Top 10 2023"] | ||
| self.assertEqual(10, len(entries)) | ||
| self.assertEqual("API1", entries[0].sectionID) | ||
| self.assertEqual("Broken Object Level Authorization", entries[0].section) | ||
| self.assertEqual( | ||
| ["304-667", "724-770"], | ||
| [link.document.id for link in entries[0].links], | ||
| ) | ||
| self.assertEqual("API10", entries[-1].sectionID) | ||
| self.assertEqual( | ||
| ["715-223"], | ||
| [link.document.id for link in entries[-1].links], | ||
| ) |
56 changes: 56 additions & 0 deletions
56
application/tests/owasp_kubernetes_top10_2022_parser_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import unittest | ||
|
|
||
| from application import create_app, sqla # type: ignore | ||
| from application.database import db | ||
| from application.defs import cre_defs as defs | ||
| from application.prompt_client import prompt_client | ||
| from application.utils.external_project_parsers.parsers import ( | ||
| owasp_kubernetes_top10_2022, | ||
| ) | ||
|
|
||
|
|
||
| class TestOwaspKubernetesTop10_2022Parser(unittest.TestCase): | ||
| def tearDown(self) -> None: | ||
| sqla.session.remove() | ||
| sqla.drop_all() | ||
| self.app_context.pop() | ||
|
|
||
| def setUp(self) -> None: | ||
| self.app = create_app(mode="test") | ||
| self.app_context = self.app.app_context() | ||
| self.app_context.push() | ||
| sqla.create_all() | ||
| self.collection = db.Node_collection() | ||
|
|
||
| def test_parse(self) -> None: | ||
| for cre_id, name in [ | ||
| ("233-748", "Configuration hardening"), | ||
| ("486-813", "Configuration"), | ||
| ("053-751", "Force build pipeline to check outdated/insecure components"), | ||
| ]: | ||
| self.collection.add_cre(defs.CRE(id=cre_id, name=name, description="")) | ||
|
|
||
| result = owasp_kubernetes_top10_2022.OwaspKubernetesTop10_2022().parse( | ||
| self.collection, prompt_client.PromptHandler(database=self.collection) | ||
| ) | ||
|
|
||
| entries = result.results["OWASP Kubernetes Top Ten 2022"] | ||
| self.assertEqual(10, len(entries)) | ||
| self.assertEqual("K01", entries[0].sectionID) | ||
| self.assertEqual("Insecure Workload Configurations", entries[0].section) | ||
| self.assertEqual( | ||
| ["233-748", "486-813"], | ||
| [link.document.id for link in entries[0].links], | ||
| ) | ||
| # K09 intentionally shares the same configuration-focused CRE ids as K01 | ||
| # in this dataset; K10 separately covers outdated/vulnerable components. | ||
| self.assertEqual("K09", entries[8].sectionID) | ||
| self.assertEqual( | ||
| ["233-748", "486-813"], | ||
| [link.document.id for link in entries[8].links], | ||
| ) | ||
| self.assertEqual("K10", entries[-1].sectionID) | ||
| self.assertEqual( | ||
| ["053-751"], | ||
| [link.document.id for link in entries[-1].links], | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.