|
1 | 1 | # from unittest import skip
|
2 | 2 | import logging
|
| 3 | +from unittest.mock import patch |
3 | 4 |
|
4 | 5 | from crum import impersonate
|
5 | 6 | from django.urls import reverse
|
@@ -70,7 +71,6 @@ def setUp(self):
|
70 | 71 | self.testuser = User.objects.get(username="admin")
|
71 | 72 | self.testuser.usercontactinfo.block_execution = True
|
72 | 73 | self.testuser.usercontactinfo.save()
|
73 |
| - |
74 | 74 | token = Token.objects.get(user=self.testuser)
|
75 | 75 | self.client = APIClient()
|
76 | 76 | self.client.credentials(HTTP_AUTHORIZATION="Token " + token.key)
|
@@ -321,7 +321,7 @@ def add_risk_acceptance(self, eid, data_risk_accceptance, fid=None):
|
321 | 321 | self.assertEqual(302, response.status_code, response.content[:1000])
|
322 | 322 | return response
|
323 | 323 |
|
324 |
| - def test_import_grouped_reopen_expired_sla(self): |
| 324 | + def test_import_grouped_reopen_expired_risk_acceptance(self): |
325 | 325 | # steps
|
326 | 326 | # import scan, make sure they are in grouped JIRA
|
327 | 327 | # risk acceptance all the grouped findings, make sure they are closed in JIRA
|
@@ -374,6 +374,59 @@ def test_import_grouped_reopen_expired_sla(self):
|
374 | 374 | # by asserting full cassette is played we know all calls to JIRA have been made as expected
|
375 | 375 | self.assert_cassette_played()
|
376 | 376 |
|
| 377 | + @patch("dojo.decorators.we_want_async", return_value=False) |
| 378 | + def test_import_grouped_reopen_expired_risk_acceptance_with_finding_sync(self, mock): |
| 379 | + # steps |
| 380 | + # import scan, make sure they are in grouped JIRA |
| 381 | + # risk acceptance all the grouped findings, make sure they are closed in JIRA |
| 382 | + # expire risk acceptance on all grouped findings, make sure they are open in JIRA |
| 383 | + JIRA_Instance.objects.update(finding_jira_sync=True) |
| 384 | + |
| 385 | + import0 = self.import_scan_with_params(self.npm_groups_sample_filename, scan_type="NPM Audit Scan", group_by="component_name+component_version", push_to_jira=True, verified=True) |
| 386 | + test_id = import0["test"] |
| 387 | + self.assert_jira_issue_count_in_test(test_id, 0) |
| 388 | + self.assert_jira_group_issue_count_in_test(test_id, 3) |
| 389 | + findings = self.get_test_findings_api(test_id) |
| 390 | + finding_id = findings["results"][0]["id"] |
| 391 | + |
| 392 | + ra_data = { |
| 393 | + "name": "Accept: Unit test", |
| 394 | + "accepted_findings": [], |
| 395 | + "recommendation": "A", |
| 396 | + "recommendation_details": "recommendation 1", |
| 397 | + "decision": "A", |
| 398 | + "decision_details": "it has been decided!", |
| 399 | + "accepted_by": "pointy haired boss", |
| 400 | + "owner": 1, |
| 401 | + "expiration_date": "2024-12-31", |
| 402 | + "reactivate_expired": True, |
| 403 | + } |
| 404 | + |
| 405 | + for finding in findings["results"]: |
| 406 | + ra_data["accepted_findings"].append(finding["id"]) |
| 407 | + |
| 408 | + pre_jira_status = self.get_jira_issue_status(finding_id) |
| 409 | + |
| 410 | + response = self.add_risk_acceptance(1, data_risk_accceptance=ra_data) |
| 411 | + self.assertEqual("/engagement/1", response.url) |
| 412 | + |
| 413 | + # we don't do any explicit push to JIRA here as it should happen automatically |
| 414 | + |
| 415 | + post_jira_status = self.get_jira_issue_status(finding_id) |
| 416 | + self.assertNotEqual(pre_jira_status, post_jira_status) |
| 417 | + |
| 418 | + pre_jira_status = post_jira_status |
| 419 | + ra = Risk_Acceptance.objects.last() |
| 420 | + ra_helper.expire_now(ra) |
| 421 | + |
| 422 | + # we don't do any explicit push to JIRA here as it should happen automatically |
| 423 | + |
| 424 | + post_jira_status = self.get_jira_issue_status(finding_id) |
| 425 | + self.assertNotEqual(pre_jira_status, post_jira_status) |
| 426 | + |
| 427 | + # by asserting full cassette is played we know all calls to JIRA have been made as expected |
| 428 | + self.assert_cassette_played() |
| 429 | + |
377 | 430 | def test_import_with_groups_twice_push_to_jira(self):
|
378 | 431 | import0 = self.import_scan_with_params(self.npm_groups_sample_filename, scan_type="NPM Audit Scan", group_by="component_name+component_version", push_to_jira=True, verified=True)
|
379 | 432 | test_id = import0["test"]
|
|
0 commit comments