-
Notifications
You must be signed in to change notification settings - Fork 118
Fix OpenCRE map analysis 503 on Heroku (#915) #918
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
northdpole
wants to merge
6
commits into
main
Choose a base branch
from
fix/915-map-analysis-opencre-nist503
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
6 commits
Select commit
Hold shift + click to select a range
00cd57e
Update BodyText.tsx (#293)
DRaichev ab63691
Add: Global browse topics button (#304)
john681611 6cf9fa3
fixed typos in image names (#321)
robvanderveer a48b4be
Improved layout of chatbot page text (#364)
robvanderveer 00f1721
Fix OpenCRE map analysis 503 on Heroku (#915)
northdpole 6c3c650
Address CodeRabbit review and fix black formatting
northdpole 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,89 @@ | ||
| import json | ||
| import unittest | ||
| from unittest.mock import Mock, patch | ||
|
|
||
| from application import create_app, sqla # type: ignore | ||
| from application.database import db | ||
| from application.defs import cre_defs as defs | ||
| from application.utils.gap_analysis import ( | ||
| OPENCRE_STANDARD_NAME, | ||
| backfill_opencre_direct_pairs, | ||
| make_resources_key, | ||
| ) | ||
|
|
||
|
|
||
| class TestOpencreGapAnalysis(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_backfill_populates_secure_headers_pair_from_auto_linked_nodes( | ||
| self, | ||
| ) -> None: | ||
| cre = self.collection.add_cre( | ||
| defs.CRE( | ||
| id="636-347", | ||
| name="HTTP security headers", | ||
| description="", | ||
| ) | ||
| ) | ||
| header_node = self.collection.add_node( | ||
| defs.Standard( | ||
| name="Secure Headers", | ||
| section="Prevent information disclosure via HTTP headers", | ||
| hyperlink="https://owasp.org/example", | ||
| ) | ||
| ) | ||
| self.collection.add_link( | ||
| cre=cre, | ||
| node=header_node, | ||
| ltype=defs.LinkTypes.AutomaticallyLinkedTo, | ||
| ) | ||
|
|
||
| written = backfill_opencre_direct_pairs(self.collection, refresh=True) | ||
| cache_key = make_resources_key([OPENCRE_STANDARD_NAME, "Secure Headers"]) | ||
|
|
||
| self.assertGreaterEqual(written, 1) | ||
| self.assertTrue(self.collection.gap_analysis_exists(cache_key)) | ||
| payload = json.loads(self.collection.get_gap_analysis_result(cache_key)) | ||
| self.assertIn("636-347", payload["result"]) | ||
| path = next(iter(payload["result"]["636-347"]["paths"].values())) | ||
| self.assertEqual("AUTOMATICALLY_LINKED_TO", path["path"][0]["relationship"]) | ||
|
|
||
| @patch( | ||
| "application.utils.gap_analysis.build_direct_cre_overlap_map_analysis", | ||
| return_value={"result": {"x": {}}}, | ||
| ) | ||
| def test_backfill_refresh_recomputes_cached_pairs(self, build_mock: Mock) -> None: | ||
| collection = Mock() | ||
| collection.standards.return_value = ["ASVS"] | ||
|
|
||
| backfill_opencre_direct_pairs(collection, refresh=False) | ||
| build_mock.assert_not_called() | ||
|
|
||
| backfill_opencre_direct_pairs(collection, refresh=True) | ||
| self.assertEqual(2, build_mock.call_count) | ||
|
|
||
| @patch( | ||
| "application.utils.gap_analysis.build_direct_cre_overlap_map_analysis", | ||
| return_value={"result": {"x": {}}}, | ||
| ) | ||
| def test_backfill_missing_only_skips_when_cache_exists( | ||
| self, build_mock: Mock | ||
| ) -> None: | ||
| collection = Mock() | ||
| collection.standards.return_value = ["ASVS"] | ||
| collection.gap_analysis_exists.return_value = True | ||
|
|
||
| written = backfill_opencre_direct_pairs(collection, refresh=False) | ||
|
|
||
| self.assertEqual(0, written) | ||
| build_mock.assert_not_called() |
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
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.