Example #1
0
    def test_empty_list_api_response(self, mock_list):
        source_id = 'organizations/123/sources/456'

        violations = [{
            'violation_hash': '311',
            'resource_name': 'readme1',
            'resource_data': {u'ipv4Enabled': True,
                              u'authorizedNetworks': [
                                  {
                                      u'expirationTime': u'1970-01-01T00:00:00Z',
                                      u'kind': u'sql#aclEntry',
                                      u'value': u'0.0.0.0/0'}]},
            'resource_id': 'readme1',
            'violation_type': 'CLOUD_SQL_VIOLATION',
            'created_at_datetime': '2018-03-26T04:37:51Z',
            'scanner_index_id': 122,
            'rule_name': 'Cloud SQL rule to search for publicly exposed instances',
            'full_name': 'organization/123/project/cicd-henry/cloudsqlinstance/456/',
            'rule_index': 0,
            'violation_data': {u'instance_name': u'readme1',
                               u'require_ssl': False,
                               u'project_id': u'readme1',
                               u'authorized_networks': [u'0.0.0.0/0'],
                               u'full_name': u'organization/123/project/cicd-henry/cloudsqlinstance/456/'},
            'id': 99185,
            'resource_type': 'cloudsqlinstance'}]

        mock_list.list_findings.return_value = {'readTime': '111'}
        notifier = cscc_notifier.CsccNotifier('abc', self.api_quota)
        notifier._send_findings_to_cscc(violations, source_id)
        self.assertFalse(mock_list.update_finding.called)
                }]
            },
            'resource_id': 'readme1',
            'violation_type': 'CLOUD_SQL_VIOLATION',
            'created_at_datetime': '2018-03-26T04:37:51Z',
            'scanner_index_id': 122,
            'rule_name':
            'Cloud SQL rule to search for publicly exposed instances',
            'full_name':
            'organization/123/project/cicd-henry/cloudsqlinstance/456/',
            'rule_index': 0L,
            'violation_data': {
                u'instance_name':
                u'readme1',
                u'require_ssl':
                False,
                u'project_id':
                u'readme1',
                u'authorized_networks': [u'0.0.0.0/0'],
                u'full_name':
                u'organization/123/project/cicd-henry/cloudsqlinstance/456/'
            },
            'id': 99185L,
            'resource_type': 'cloudsqlinstance'
        }]

        mock_list.list_findings.return_value = {'readTime': '111'}
        notifier = cscc_notifier.CsccNotifier('abc')
        notifier._send_findings_to_cscc(violations, source_id)
        self.assertFalse(mock_list.update_finding.called)