示例#1
0
def _get_issue_instance(severity=panther.MEDIUM, confidence=panther.MEDIUM):
    new_issue = issue.Issue(severity, confidence, 'Test issue')
    new_issue.fname = 'code.py'
    new_issue.test = 'panther_plugin'
    new_issue.test_id = 'B999'
    new_issue.lineno = 1
    return new_issue
示例#2
0
    def test_get_code(self, getline):
        getline.return_value = b'\x08\x30'
        new_issue = issue.Issue(panther.MEDIUM, lineno=1)

        try:
            new_issue.get_code()
        except UnicodeDecodeError:
            self.fail('Bytes not properly decoded in issue.get_code()')
示例#3
0
    def test_results_count(self):
        levels = [constants.LOW, constants.MEDIUM, constants.HIGH]
        self.manager.results = ([
            issue.Issue(severity=l, confidence=l) for l in levels
        ])

        r = [
            self.manager.results_count(sev_filter=l, conf_filter=l)
            for l in levels
        ]

        self.assertEqual([3, 2, 1], r)
示例#4
0
    def setUp(self):
        super(JsonFormatterTests, self).setUp()
        conf = config.PantherConfig()
        self.manager = manager.PantherManager(conf, 'file')
        (tmp_fd, self.tmp_fname) = tempfile.mkstemp()
        self.context = {
            'filename': self.tmp_fname,
            'lineno': 4,
            'linerange': [4]
        }
        self.check_name = 'hardcoded_bind_all_interfaces'
        self.issue = issue.Issue(panther.MEDIUM, panther.MEDIUM,
                                 'Possible binding to all interfaces.')

        self.candidates = [
            issue.Issue(panther.LOW, panther.LOW, 'Candidate A', lineno=1),
            issue.Issue(panther.HIGH, panther.HIGH, 'Candiate B', lineno=2)
        ]

        self.manager.out_file = self.tmp_fname

        self.issue.fname = self.context['filename']
        self.issue.lineno = self.context['lineno']
        self.issue.linerange = self.context['linerange']
        self.issue.test = self.check_name

        self.manager.results.append(self.issue)
        self.manager.metrics = metrics.Metrics()

        # mock up the metrics
        for key in ['_totals', 'binding.js']:
            self.manager.metrics.data[key] = {'loc': 4, 'nosec': 2}
            for (criteria, default) in constants.CRITERIA:
                for rank in constants.RANKING:
                    self.manager.metrics.data[key]['{0}.{1}'.format(
                        criteria, rank)] = 0
示例#5
0
 def update_issues(self):
     '''Updates the issues with dependencies vulnerabilities'''
     if self.run_check():
         self._fetch_cves()
         for vuln in self.nsp_report:
             i = issue.Issue(None)
             i.from_dict({
                 'filename': 'package.json',
                 'test_id': constants.NSP_TEST_ID,
                 'line_number': '',
                 'line_range': [0, 1],
                 'test_name': NspManager._format_issue_name(vuln),
                 'issue_text': ' > '.join(vuln['path']),
                 'code': self._format_issue_desc(vuln),
                 'issue_confidence': panther.HIGH,
                 'issue_severity': NspManager._get_severity_level(vuln)
             })
             self.results.append(i)
示例#6
0
    def setUp(self):
        super(CsvFormatterTests, self).setUp()
        conf = config.PantherConfig()
        self.manager = manager.PantherManager(conf, 'file')
        (tmp_fd, self.tmp_fname) = tempfile.mkstemp()
        self.context = {
            'filename': self.tmp_fname,
            'lineno': 4,
            'linerange': [4]
        }
        self.check_name = 'hardcoded_bind_all_interfaces'
        self.issue = issue.Issue(panther.MEDIUM, panther.MEDIUM,
                                 'Possible binding to all interfaces.')
        self.manager.out_file = self.tmp_fname

        self.issue.fname = self.context['filename']
        self.issue.lineno = self.context['lineno']
        self.issue.linerange = self.context['linerange']
        self.issue.test = self.check_name

        self.manager.results.append(self.issue)
示例#7
0
 def _get_issue_instance(self, sev=constants.MEDIUM, conf=constants.MEDIUM):
     new_issue = issue.Issue(sev, conf, 'Test issue')
     new_issue.fname = 'code.py'
     new_issue.test = 'panther_plugin'
     new_issue.lineno = 1
     return new_issue