Browse code

fix new pylint warnings

Hanno Böck authored on05/09/2021 09:46:29
Showing1 changed files
... ...
@@ -19,7 +19,7 @@ class TestJsonLint(unittest.TestCase):
19 19
     def test_json_lint(self):
20 20
         valid = True
21 21
         for f in glob.glob("freewvsdb/*.json"):
22
-            fp = open(f)
22
+            fp = open(f, encoding="ascii")
23 23
             orig = fp.read()
24 24
             fp.close()
25 25
             tmp = json.loads(orig)
... ...
@@ -33,7 +33,7 @@ class TestJsonLint(unittest.TestCase):
33 33
     def test_json_values(self):
34 34
         jconfig = []
35 35
         for cfile in glob.glob('freewvsdb/*.json'):
36
-            with open(cfile) as json_file:
36
+            with open(cfile, encoding="ascii") as json_file:
37 37
                 jconfig += json.load(json_file)
38 38
 
39 39
         mkeys = {'name', 'url', 'safe', 'vuln', 'detection'}
Browse code

use curly set syntax and remove unneeded r for open, warnings from pyupgrade

Hanno Böck authored on10/06/2020 20:09:07
Showing1 changed files
... ...
@@ -19,7 +19,7 @@ class TestJsonLint(unittest.TestCase):
19 19
     def test_json_lint(self):
20 20
         valid = True
21 21
         for f in glob.glob("freewvsdb/*.json"):
22
-            fp = open(f, "r")
22
+            fp = open(f)
23 23
             orig = fp.read()
24 24
             fp.close()
25 25
             tmp = json.loads(orig)
... ...
@@ -36,7 +36,7 @@ class TestJsonLint(unittest.TestCase):
36 36
             with open(cfile) as json_file:
37 37
                 jconfig += json.load(json_file)
38 38
 
39
-        mkeys = set(['name', 'url', 'safe', 'vuln', 'detection'])
39
+        mkeys = {'name', 'url', 'safe', 'vuln', 'detection'}
40 40
         for item in jconfig:
41 41
 
42 42
             # check for all mandatory keys
Browse code

test sanity of safe vs latest version

Hanno Böck authored on24/03/2020 17:48:44
Showing1 changed files
... ...
@@ -62,6 +62,13 @@ class TestJsonLint(unittest.TestCase):
62 62
                                     msg="%s: Invalid old_safe ordering %s" %
63 63
                                     (item['name'], item['old_safe']))
64 64
 
65
+            # make sure latest is not outdated
66
+            if 'latest' in item and item['safe'] != "":
67
+                self.assertTrue(not versioncompare(item['safe'],
68
+                                                   item['latest']),
69
+                                msg="%s: Safe version %s newer than latest %s"
70
+                                % (item['name'], item['safe'], item['latest']))
71
+
65 72
             # subdir needs to be integer
66 73
             for det in item['detection']:
67 74
                 self.assertTrue(isinstance(det['subdir'], int),
Browse code

check old_safe for consistency, fix pylint

Hanno Böck authored on22/12/2019 12:11:48
Showing1 changed files
... ...
@@ -6,6 +6,12 @@ import difflib
6 6
 import re
7 7
 
8 8
 
9
+def versioncompare(safe_version, find_version):
10
+    safe_version_tup = [int(x) for x in safe_version.split(".")]
11
+    find_version_tup = [int(x) for x in find_version.split(".")]
12
+    return find_version_tup < safe_version_tup
13
+
14
+
9 15
 class TestJsonLint(unittest.TestCase):
10 16
 
11 17
     @unittest.skipIf(sys.version_info < (3, 6, 0),
... ...
@@ -46,8 +52,19 @@ class TestJsonLint(unittest.TestCase):
46 52
                             or item['vuln'].startswith("https://"),
47 53
                             msg="%s: Invalid vuln %s" %
48 54
                             (item['name'], item['vuln']))
55
+
56
+            # make sure old_safe is properly sorted
57
+            if 'old_safe' in item:
58
+                old_safe = item['old_safe'].split(',')
59
+                for i in range(1, len(old_safe)):
60
+                    self.assertTrue(versioncompare(old_safe[i - 1],
61
+                                                   old_safe[i]),
62
+                                    msg="%s: Invalid old_safe ordering %s" %
63
+                                    (item['name'], item['old_safe']))
64
+
65
+            # subdir needs to be integer
49 66
             for det in item['detection']:
50
-                self.assertTrue(type(det['subdir']) == int,
67
+                self.assertTrue(isinstance(det['subdir'], int),
51 68
                                 msg="%s: subdir not int" % item['name'])
52 69
 
53 70
 
Browse code

check subdir is int

Hanno Böck authored on19/12/2019 16:39:07
Showing1 changed files
... ...
@@ -46,6 +46,9 @@ class TestJsonLint(unittest.TestCase):
46 46
                             or item['vuln'].startswith("https://"),
47 47
                             msg="%s: Invalid vuln %s" %
48 48
                             (item['name'], item['vuln']))
49
+            for det in item['detection']:
50
+                self.assertTrue(type(det['subdir']) == int,
51
+                                msg="%s: subdir not int" % item['name'])
49 52
 
50 53
 
51 54
 if __name__ == '__main__':
Browse code

add sanity checks for json data

Hanno Böck authored on16/12/2019 20:45:03
Showing1 changed files
... ...
@@ -3,6 +3,7 @@ import glob
3 3
 import json
4 4
 import sys
5 5
 import difflib
6
+import re
6 7
 
7 8
 
8 9
 class TestJsonLint(unittest.TestCase):
... ...
@@ -23,6 +24,29 @@ class TestJsonLint(unittest.TestCase):
23 24
                 valid = False
24 25
         self.assertTrue(valid)
25 26
 
27
+    def test_json_values(self):
28
+        jconfig = []
29
+        for cfile in glob.glob('freewvsdb/*.json'):
30
+            with open(cfile) as json_file:
31
+                jconfig += json.load(json_file)
32
+
33
+        mkeys = set(['name', 'url', 'safe', 'vuln', 'detection'])
34
+        for item in jconfig:
35
+
36
+            # check for all mandatory keys
37
+            self.assertEqual(mkeys.intersection(item.keys()), mkeys,
38
+                             msg="Missing key in %s" % item['name'])
39
+
40
+            # check we have at least one detection
41
+            self.assertTrue(len(item['detection']) >= 1,
42
+                            msg="No detection in %s" % item['name'])
43
+
44
+            # vuln needs to be CVE or HTTPS URL
45
+            self.assertTrue(re.match("^CVE-[0-9]*-[0-9]*$", item['vuln'])
46
+                            or item['vuln'].startswith("https://"),
47
+                            msg="%s: Invalid vuln %s" %
48
+                            (item['name'], item['vuln']))
49
+
26 50
 
27 51
 if __name__ == '__main__':
28 52
     unittest.main()
Browse code

avoid some pylint warnings

Hanno Böck authored on14/12/2019 09:46:03
Showing1 changed files
... ...
@@ -17,12 +17,11 @@ class TestJsonLint(unittest.TestCase):
17 17
             fp.close()
18 18
             tmp = json.loads(orig)
19 19
             new = json.dumps(tmp, indent=2)
20
-            if (orig != new):
20
+            if orig != new:
21 21
                 print("json %s not valid" % f)
22 22
                 sys.stdout.writelines(difflib.unified_diff(orig, new))
23 23
                 valid = False
24
-        if not valid:
25
-            raise Exception("Unlinted json files found")
24
+        self.assertTrue(valid)
26 25
 
27 26
 
28 27
 if __name__ == '__main__':
Browse code

disable jsonlint test on python 3.5 due to different behavior of json.dumps()

Hanno Böck authored on12/12/2019 19:10:28
Showing1 changed files
... ...
@@ -6,6 +6,9 @@ import difflib
6 6
 
7 7
 
8 8
 class TestJsonLint(unittest.TestCase):
9
+
10
+    @unittest.skipIf(sys.version_info < (3, 6, 0),
11
+                     "json.dumps force-sorts on python 3.5")
9 12
     def test_json_lint(self):
10 13
         valid = True
11 14
         for f in glob.glob("freewvsdb/*.json"):
Browse code

add codingstyle and json linting tests

Hanno Böck authored on12/12/2019 18:29:13
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+import unittest
2
+import glob
3
+import json
4
+import sys
5
+import difflib
6
+
7
+
8
+class TestJsonLint(unittest.TestCase):
9
+    def test_json_lint(self):
10
+        valid = True
11
+        for f in glob.glob("freewvsdb/*.json"):
12
+            fp = open(f, "r")
13
+            orig = fp.read()
14
+            fp.close()
15
+            tmp = json.loads(orig)
16
+            new = json.dumps(tmp, indent=2)
17
+            if (orig != new):
18
+                print("json %s not valid" % f)
19
+                sys.stdout.writelines(difflib.unified_diff(orig, new))
20
+                valid = False
21
+        if not valid:
22
+            raise Exception("Unlinted json files found")
23
+
24
+
25
+if __name__ == '__main__':
26
+    unittest.main()