1616 get_unit_tests_path ,
1717 get_unit_tests_scans_path ,
1818 toggle_system_setting_boolean ,
19+ with_system_setting ,
1920)
2021
2122logger = logging .getLogger (__name__ )
@@ -49,12 +50,12 @@ def __init__(self, *args, **kwargs):
4950 DojoVCRAPITestCase .__init__ (self , * args , ** kwargs )
5051
5152 def assert_cassette_played (self ):
52- if True : # set to True when committing. set to False when recording new test cassettes
53+ if False : # set to True when committing. set to False when recording new test cassettes
5354 self .assertTrue (self .cassette .all_played )
5455
5556 def _get_vcr (self , ** kwargs ):
5657 my_vcr = super ()._get_vcr (** kwargs )
57- my_vcr .record_mode = "once "
58+ my_vcr .record_mode = "all "
5859 my_vcr .path_transformer = VCR .ensure_suffix (".yaml" )
5960 my_vcr .filter_headers = ["Authorization" , "X-Atlassian-Token" ]
6061 my_vcr .cassette_library_dir = str (get_unit_tests_path () / "vcr" / "jira" )
@@ -69,6 +70,7 @@ def setUp(self):
6970 self .testuser = User .objects .get (username = "admin" )
7071 self .testuser .usercontactinfo .block_execution = True
7172 self .testuser .usercontactinfo .save ()
73+
7274 token = Token .objects .get (user = self .testuser )
7375 self .client = APIClient ()
7476 self .client .credentials (HTTP_AUTHORIZATION = "Token " + token .key )
@@ -106,6 +108,29 @@ def test_import_with_groups_push_to_jira(self):
106108 # by asserting full cassette is played we know issues have been updated in JIRA
107109 self .assert_cassette_played ()
108110
111+ @with_system_setting ("jira_minimum_severity" , "Critical" )
112+ def test_import_with_groups_push_to_jira_minimum_critical (self ):
113+ # No Critical findings in report, so expect no groups to be pushed
114+ 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 )
115+ test_id = import0 ["test" ]
116+ # all findings should be in a group, so no JIRA issues for individual findings
117+ self .assert_jira_issue_count_in_test (test_id , 0 )
118+ self .assert_jira_group_issue_count_in_test (test_id , 0 )
119+ # by asserting full cassette is played we know issues have been updated in JIRA
120+ self .assert_cassette_played ()
121+
122+ @with_system_setting ("jira_minimum_severity" , "High" )
123+ def test_import_with_groups_push_to_jira_minimum_high (self ):
124+ # 7 findings, 5 unique component_name+component_version
125+ 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 )
126+ test_id = import0 ["test" ]
127+ # all findings should be in a group, so no JIRA issues for individual findings
128+ self .assert_jira_issue_count_in_test (test_id , 0 )
129+ # fresh library has only medium findings, so only 2 instead of 3 groups expected
130+ self .assert_jira_group_issue_count_in_test (test_id , 2 )
131+ # by asserting full cassette is played we know issues have been updated in JIRA
132+ self .assert_cassette_played ()
133+
109134 def test_import_with_push_to_jira_epic_as_issue_type (self ):
110135 jira_instance = JIRA_Instance .objects .get (id = 2 )
111136 # we choose issue type Epic and test if it can be created successfully.
@@ -456,7 +481,7 @@ def test_groups_create_edit_update_finding(self):
456481 del finding_details ["push_to_jira" ]
457482
458483 # push a finding should result in pushing the group instead
459- self .patch_finding_api (findings ["results" ][0 ]["id" ], {"push_to_jira" : True })
484+ self .patch_finding_api (findings ["results" ][0 ]["id" ], {"push_to_jira" : True , "verified" : True })
460485
461486 self .assert_jira_issue_count_in_test (test_id , 0 )
462487 self .assert_jira_group_issue_count_in_test (test_id , 1 )
@@ -628,7 +653,12 @@ def test_import_with_push_to_jira_not_verified_enforced_verified_globally_true_e
628653 import0 = self .import_scan_with_params (self .zap_sample5_filename , push_to_jira = True , verified = False )
629654 test_id = import0 ["test" ]
630655 # This scan file has two active findings, so we should not push either of them
631- self .assert_jira_issue_count_in_test (test_id , 0 )
656+ self .assert_jira_group_issue_count_in_test (test_id , 0 )
657+
658+ import0 = self .import_scan_with_params (self .zap_sample5_filename , push_to_jira = True , verified = True )
659+ test_id = import0 ["test" ]
660+ self .assert_jira_group_issue_count_in_test (test_id , 2 )
661+
632662 # by asserting full cassette is played we know all calls to JIRA have been made as expected
633663 self .assert_cassette_played ()
634664
@@ -639,7 +669,12 @@ def test_import_with_push_to_jira_not_verified_enforced_verified_globally_true_e
639669 test_id = import0 ["test" ]
640670 # This scan file has two active findings, so we should not push either of them
641671 self .assert_jira_issue_count_in_test (test_id , 0 )
672+
673+ import0 = self .import_scan_with_params (self .zap_sample5_filename , push_to_jira = True , verified = True )
674+ test_id = import0 ["test" ]
675+ self .assert_jira_issue_count_in_test (test_id , 2 )
642676 # by asserting full cassette is played we know all calls to JIRA have been made as expected
677+
643678 self .assert_cassette_played ()
644679
645680 @toggle_system_setting_boolean ("enforce_verified_status" , False ) # noqa: FBT003
@@ -649,6 +684,11 @@ def test_import_with_push_to_jira_not_verified_enforced_verified_globally_false_
649684 test_id = import0 ["test" ]
650685 # This scan file has two active findings, so we should not push either of them
651686 self .assert_jira_issue_count_in_test (test_id , 0 )
687+
688+ import0 = self .import_scan_with_params (self .zap_sample5_filename , push_to_jira = True , verified = True )
689+ test_id = import0 ["test" ]
690+ self .assert_jira_issue_count_in_test (test_id , 2 )
691+
652692 # by asserting full cassette is played we know all calls to JIRA have been made as expected
653693 self .assert_cassette_played ()
654694
@@ -662,6 +702,61 @@ def test_import_with_push_to_jira_not_verified_enforced_verified_globally_false_
662702 # by asserting full cassette is played we know all calls to JIRA have been made as expected
663703 self .assert_cassette_played ()
664704
705+ @toggle_system_setting_boolean ("enforce_verified_status" , True ) # noqa: FBT003
706+ @toggle_system_setting_boolean ("enforce_verified_status_jira" , True ) # noqa: FBT003
707+ def test_groups_import_with_push_to_jira_not_verified_enforced_verified_globally_true_enforced_verified_jira_true (self ):
708+ 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 = False )
709+ test_id = import0 ["test" ]
710+ # No verified findings, means no groups pushed to JIRA
711+ self .assert_jira_group_issue_count_in_test (test_id , 0 )
712+
713+ 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 )
714+ test_id = import0 ["test" ]
715+ self .assert_jira_group_issue_count_in_test (test_id , 3 )
716+
717+ # by asserting full cassette is played we know all calls to JIRA have been made as expected
718+ self .assert_cassette_played ()
719+
720+ @toggle_system_setting_boolean ("enforce_verified_status" , True ) # noqa: FBT003
721+ @toggle_system_setting_boolean ("enforce_verified_status_jira" , False ) # noqa: FBT003
722+ def test_groups_import_with_push_to_jira_not_verified_enforced_verified_globally_true_enforced_verified_jira_false (self ):
723+ 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 = False )
724+ test_id = import0 ["test" ]
725+ # No verified findings, means no groups pushed to JIRA
726+ self .assert_jira_group_issue_count_in_test (test_id , 0 )
727+
728+ 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 )
729+ test_id = import0 ["test" ]
730+ self .assert_jira_group_issue_count_in_test (test_id , 3 )
731+ # by asserting full cassette is played we know all calls to JIRA have been made as expected
732+
733+ self .assert_cassette_played ()
734+
735+ @toggle_system_setting_boolean ("enforce_verified_status" , False ) # noqa: FBT003
736+ @toggle_system_setting_boolean ("enforce_verified_status_jira" , True ) # noqa: FBT003
737+ def test_groups_import_with_push_to_jira_not_verified_enforced_verified_globally_false_enforced_verified_jira_true (self ):
738+ 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 = False )
739+ test_id = import0 ["test" ]
740+ # No verified findings, means no groups pushed to JIRA
741+ self .assert_jira_group_issue_count_in_test (test_id , 0 )
742+
743+ 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 )
744+ test_id = import0 ["test" ]
745+ self .assert_jira_group_issue_count_in_test (test_id , 3 )
746+
747+ # by asserting full cassette is played we know all calls to JIRA have been made as expected
748+ self .assert_cassette_played ()
749+
750+ @toggle_system_setting_boolean ("enforce_verified_status" , False ) # noqa: FBT003
751+ @toggle_system_setting_boolean ("enforce_verified_status_jira" , False ) # noqa: FBT003
752+ @with_system_setting ("jira_minimum_severity" , "Low" )
753+ def test_groups_import_with_push_to_jira_not_verified_enforced_verified_globally_false_enforced_verified_jira_false (self ):
754+ 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 )
755+ test_id = import0 ["test" ]
756+ self .assert_jira_group_issue_count_in_test (test_id , 3 )
757+ # by asserting full cassette is played we know all calls to JIRA have been made as expected
758+ self .assert_cassette_played ()
759+
665760 def test_engagement_epic_creation (self ):
666761 eng = self .get_engagement (3 )
667762 # Set epic_mapping to true
0 commit comments