|
44 | 44 | TEST_DATA = os.path.join(BASE_DIR, 'test_data/') |
45 | 45 |
|
46 | 46 |
|
47 | | -class TestDataDump(TestCase): |
48 | | - def test_debian_data_dump(self): |
49 | | - """ |
50 | | - Scrape data from Debian' main tracker, save it |
51 | | - in the database and verify entries. |
52 | | - """ |
| 47 | +class TestDebianDataDump(TestCase): |
| 48 | + |
| 49 | + @classmethod |
| 50 | + def setUpTestData(self): |
53 | 51 | with open(os.path.join(TEST_DATA, 'debian.json')) as f: |
54 | 52 | test_data = json.load(f) |
55 | 53 |
|
56 | 54 | extract_data = debian.extract_vulnerabilities(test_data) |
57 | 55 | debian_dump(extract_data) |
58 | 56 |
|
| 57 | + def test_Vulnerability(self): |
| 58 | + """ |
| 59 | + Check that all vulnerabilities from the test data are stored in the database |
| 60 | + """ |
59 | 61 | self.assertEqual(3, Vulnerability.objects.count()) |
60 | | - self.assertEqual(3, VulnerabilityReference.objects.count()) |
61 | | - self.assertEqual(3, Package.objects.count()) |
62 | 62 |
|
63 | 63 | self.assertTrue(Vulnerability.objects.get( |
64 | 64 | summary='Multiple stack-based buffer overflows in mimetex.cgi in mimeTeX')) |
65 | 65 |
|
66 | 66 | self.assertTrue(Vulnerability.objects.get( |
67 | 67 | summary='Multiple unspecified vulnerabilities in mimeTeX')) |
68 | 68 |
|
| 69 | + self.assertTrue(Vulnerability.objects.get( |
| 70 | + summary='librsync before 1.0.0 uses a truncated MD4 checksum \ |
| 71 | +to match blocks')) |
| 72 | + |
| 73 | + def test_VulnerabilityReference(self): |
| 74 | + """ |
| 75 | + Check that all vulnerability references from the test data are stored in the database |
| 76 | + """ |
| 77 | + self.assertEqual(3, VulnerabilityReference.objects.count()) |
69 | 78 | self.assertTrue(VulnerabilityReference.objects.get(reference_id='CVE-2009-1382')) |
70 | 79 | self.assertTrue(VulnerabilityReference.objects.get(reference_id='CVE-2009-2459')) |
71 | 80 | self.assertTrue(VulnerabilityReference.objects.get(reference_id='CVE-2014-8242')) |
72 | | - self.assertTrue(Package.objects.get(name='librsync')) |
73 | 81 |
|
74 | | - def test_ubuntu_data_dump(self): |
| 82 | + def test_Package(self): |
75 | 83 | """ |
76 | | - Scrape data from Ubuntu' main tracker, save it |
77 | | - in the database and verify entries. |
| 84 | + Check that all packages from the test data are stored in the database |
78 | 85 | """ |
| 86 | + # There are three rows in Package because currently the models allow duplicates |
| 87 | + # (see issue #28). |
| 88 | + self.assertEqual(3, Package.objects.count()) |
| 89 | + |
| 90 | + self.assertTrue(Package.objects.filter(name='mimetex')) |
| 91 | + self.assertTrue(Package.objects.get(name='librsync')) |
| 92 | + |
| 93 | + |
| 94 | +class TestUbuntuDataDump(TestCase): |
| 95 | + @classmethod |
| 96 | + def setUpTestData(self): |
79 | 97 | with open(os.path.join(TEST_DATA, 'ubuntu_main.html')) as f: |
80 | 98 | test_data = f.read() |
81 | 99 |
|
82 | 100 | data = ubuntu.extract_cves(test_data) |
83 | 101 | ubuntu_dump(data) |
84 | 102 |
|
| 103 | + def test_data_dump(self): |
| 104 | + """ |
| 105 | + Check basic data import |
| 106 | + """ |
85 | 107 | reference = VulnerabilityReference.objects.filter(reference_id='CVE-2002-2439')[0] |
86 | 108 | self.assertEqual(reference.reference_id, 'CVE-2002-2439') |
87 | 109 | self.assertTrue(Package.objects.filter(name='gcc-4.6')[0].name, 'gcc-4.6') |
88 | 110 |
|
89 | | - def test_archlinux_data_dump(self): |
90 | | - """ |
91 | | - Scrape data from Archlinux' main tracker, save it |
92 | | - in the database and verify entries. |
93 | | - """ |
| 111 | + |
| 112 | +class TestArchLinuxDataDump(TestCase): |
| 113 | + |
| 114 | + @classmethod |
| 115 | + def setUpTestData(self): |
94 | 116 | with open(os.path.join(TEST_DATA, 'archlinux.json')) as f: |
95 | | - test_data = json.loads(f.read()) |
| 117 | + test_data = json.load(f) |
96 | 118 |
|
97 | 119 | archlinux_dump(test_data) |
98 | 120 |
|
| 121 | + def test_Vulnerability(self): |
| 122 | + """ |
| 123 | + Check that all vulnerabilities from the test data are stored in the database |
| 124 | + """ |
99 | 125 | self.assertEqual(1, Vulnerability.objects.count()) |
| 126 | + self.assertTrue(Vulnerability.objects.get(summary='multiple issues')) |
| 127 | + |
| 128 | + def test_VulnerabilityReference(self): |
| 129 | + """ |
| 130 | + Check that all vulnerability references from the test data are stored in the database |
| 131 | + """ |
100 | 132 | self.assertEqual(14, VulnerabilityReference.objects.count()) |
| 133 | + self.assertTrue(VulnerabilityReference.objects.get(reference_id='CVE-2018-11360')) |
| 134 | + self.assertTrue(VulnerabilityReference.objects.get(reference_id='ASA-201805-24')) |
| 135 | + self.assertTrue(VulnerabilityReference.objects.get(reference_id='AVG-708')) |
| 136 | + |
| 137 | + def test_Package(self): |
| 138 | + """ |
| 139 | + Check that all packages from the test data are stored in the database |
| 140 | + """ |
101 | 141 | self.assertEqual(8, Package.objects.count()) |
102 | | - self.assertEqual(8, PackageReference.objects.count()) |
103 | | - self.assertEqual(4, ImpactedPackage.objects.count()) |
104 | | - self.assertEqual(4, ResolvedPackage.objects.count()) |
| 142 | + self.assertTrue(Package.objects.filter(name='wireshark-cli')) |
105 | 143 |
|
106 | | - self.assertTrue(Vulnerability.objects.get(summary='multiple issues')) |
| 144 | + def test_PackageReference(self): |
| 145 | + """ |
| 146 | + Check that all package references from the test data are stored in the database |
| 147 | + """ |
| 148 | + self.assertEqual(8, PackageReference.objects.count()) |
107 | 149 |
|
108 | | - self.assertTrue(VulnerabilityReference.objects.get(reference_id='CVE-2018-11360')) |
| 150 | + def test_ImpactedPackage(self): |
| 151 | + """ |
| 152 | + Check that all impacted packages from the test data are stored in the database |
| 153 | + """ |
| 154 | + impacted_pkgs = ImpactedPackage.objects.all() |
| 155 | + impacted_pkg = impacted_pkgs[0] |
109 | 156 |
|
110 | | - self.assertTrue(VulnerabilityReference.objects.get(reference_id='ASA-201805-24')) |
| 157 | + self.assertEqual(4, len(impacted_pkgs)) |
| 158 | + self.assertEqual('2.6.0-1', impacted_pkg.package.version) |
111 | 159 |
|
112 | | - self.assertTrue(VulnerabilityReference.objects.get(reference_id='AVG-708')) |
| 160 | + def test_ResolvedPackage(self): |
| 161 | + """ |
| 162 | + Check that all resolved packages from the test data are stored in the database |
| 163 | + """ |
| 164 | + resolved_pkgs = ResolvedPackage.objects.all() |
| 165 | + resolved_pkg = resolved_pkgs[0] |
113 | 166 |
|
114 | | - self.assertEqual(Package.objects.filter(name='wireshark-cli')[0].name, 'wireshark-cli') |
| 167 | + self.assertEqual(4, len(resolved_pkgs)) |
| 168 | + self.assertEqual('2.6.1-1', resolved_pkg.package.version) |
0 commit comments