Ejemplo n.º 1
0
 def test_nr_of_warnings_and_report_is_requested(self):
     """Test that the number of security warnings is returned."""
     get_response = Mock()
     get_response.json.side_effect = [[dict(name="project", id="id")],
                                      [dict(id=1000)],
                                      dict(status=dict(value="In Process")),
                                      dict(highSeverity=1,
                                           mediumSeverity=2,
                                           lowSeverity=3,
                                           infoSeverity=4),
                                      [dict(name="project", id="id")]]
     post_response = Mock()
     post_response.json.side_effect = [
         dict(access_token="token"),
         dict(access_token="token"),
         dict(reportId=1)
     ]
     with patch("requests.post", return_value=post_response):
         with patch("requests.get", return_value=get_response):
             collector = MetricCollector(self.metric)
             response = collector.get()
     self.assertEqual("10", response["sources"][0]["value"])
     self.assertEqual([], response["sources"][0]["entities"])
     self.assertEqual(1, CxSASTSecurityWarnings.CXSAST_SCAN_REPORTS[1000])
     self.assertEqual(datetime.min, collector.next_collection())
Ejemplo n.º 2
0
    def test_report_finished(self):
        """Test that there are entities when the report is ready."""
        CxSASTSecurityWarnings.CXSAST_SCAN_REPORTS[1000] = 1
        get_response = Mock()
        get_response.json.side_effect = [[dict(name="project", id="id")],
                                         [dict(id=1000)],
                                         dict(status=dict(value="Created")),
                                         dict(highSeverity=1,
                                              mediumSeverity=2,
                                              lowSeverity=3,
                                              infoSeverity=4),
                                         [dict(name="project", id="id")],
                                         [dict(id=1000)],
                                         dict(status=dict(value="Created")),
                                         [dict(name="project", id="id")]]
        get_response.text = """
<CxXMLResults>
    <Query name='Name'>
        <Result NodeId='1' Severity='High' FalsePositive='False' FileName='file' Line='42' Column='2'
                DeepLink='http://deeplink'>
        </Result>
        <Result NodeId='2' Severity='High' FalsePositive='True' FileName='file' Line='44' Column='9'
                DeepLink='http://deeplink'>
        </Result>
    </Query>
</CxXMLResults>"""
        post_response = Mock()
        post_response.json.return_value = dict(access_token="token")
        with patch("requests.post", return_value=post_response):
            with patch("requests.get", return_value=get_response):
                collector = MetricCollector(self.metric)
                response = collector.get()
        self.assertEqual("10", response["sources"][0]["value"])
        self.assertEqual([
            dict(key="1",
                 location="file:42:2",
                 name="Name",
                 severity="High",
                 url="http://deeplink")
        ], response["sources"][0]["entities"])
        self.assertNotEqual(datetime.min, collector.next_collection())