File: test_flawfinder_parser.py

package info (click to toggle)
python-firehose 0.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,104 kB
  • sloc: python: 2,587; xml: 1,388; makefile: 152; ansic: 34
file content (71 lines) | stat: -rw-r--r-- 3,078 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
#
#   Copyright 2017 David Carlos  <ddavidcarlos1392@gmail.com>
#   This library is free software; you can redistribute it and/or
#   modify it under the terms of the GNU Lesser General Public
#   License as published by the Free Software Foundation; either
#   version 2.1 of the License, or (at your option) any later version.
#
#   This library is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#   Lesser General Public License for more details.
#
#   You should have received a copy of the GNU Lesser General Public
#   License along with this library; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
#   USA

import os
import unittest

from firehose.parsers.flawfinder import parse_file
from firehose.model import Analysis, Issue, Sut, Trace

class TestParseXml(unittest.TestCase):
    def parse_example(self, filename):
        try:
            path = os.path.join(os.path.dirname(__file__),
                    'example-output',
                    'flawfinder',
                    filename)
            with open(path) as infile:
                return parse_file(infile)
        except IOError:
            print("Example input not found")

    def test_flawfinder_report(self):
        a = self.parse_example('flawfinder-report-1')
        self.assertEqual(a.metadata.generator.name, 'flawfinder')
        self.assertEqual(a.metadata.generator.version, '1.31')
        self.assertEqual(a.metadata.sut, None)
        self.assertEqual(a.metadata.file_, None)
        self.assertEqual(a.metadata.stats, None)
        self.assertEqual(a.metadata.stats, None)

        self.assertEqual(len(a.results), 1804)

        w0 = a.results[0]
        self.assertEqual(w0.cwe, 78)
        expected_message = 'This causes a new program to execute ' \
                           'and is difficult to use safely (CWE-78). ' \
                           'try using a library call that implements ' \
                           'the same functionality if available.'
        self.assertEqual(w0.message.text, expected_message)
        self.assertEqual(w0.testid, 'shell')
        self.assertEqual(w0.location.file.givenpath , "./docs/examples/asiohiper.cpp")
        self.assertEqual(w0.location.point.line, 78)
        self.assertEqual(w0.location.point.column, 0)

        w3 = a.results[4]
        self.assertEqual(w3.location.file.givenpath , "./docs/examples/cookie_interface.c")
        self.assertEqual(w3.testid, 'format')
        some_w = a.results[1801]
        self.assertEqual(some_w.cwe, 126)
        self.assertEqual(some_w.testid, 'buffer')
        other_w = a.results[1802]
        self.assertEqual(other_w.cwe, None)
        self.assertEqual(other_w.location.file.givenpath,
                         "./tests/unit/unit1604.c")
        self.assertEqual(other_w.location.point.line, 49)
        self.assertEqual(other_w.location.point.column, 0)