Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-martynovich committed Jan 14, 2020
1 parent 6dda2b9 commit a4a6f8d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 50 deletions.
49 changes: 0 additions & 49 deletions backend/device_registry/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,55 +685,6 @@ def test_insecure_services(self):
{'name': 'fingerd', 'version': 'VERSION', 'arch': 'i386',
'os_release_codename': 'jessie'}])

def test_vulnerable_packages_render(self):
self.client.login(username='test', password='123')
url = reverse('device-detail-security', kwargs={'pk': self.device.pk})
# No packages - should render N/A
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertInHTML('''
<th scope="row">
Vulnerable Packages
</th>
<td>
N/A
</td>''', response.rendered_content)

self.device.deb_packages_hash = 'aabbccdd'
self.device.save()
self.device.set_deb_packages([
{'name': 'python2', 'version': 'VERSION', 'source_name': 'python2', 'source_version': 'abcd',
'arch': 'i386'},
{'name': 'python3', 'version': 'VERSION', 'source_name': 'python3', 'source_version': 'abcd',
'arch': 'i386'}
], os_info={'codename': 'stretch'})
# No vulnerable packages - green check mark
self.device.os_release = {'distro': 'debian', 'version': '9', 'codename': 'stretch', 'distro_root': 'debian',
'full_version': '9 (stretch)'}
self.device.save(update_fields=['os_release'])
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertInHTML('''
<th scope="row">
Vulnerable Packages
</th>
<td>
<span class="p-1 text-success">
<i class="fas fa-check" ></i>
</span>
</td>
''', response.rendered_content)

v = Vulnerability.objects.create(name='CVE-123', package='python2', is_binary=False, other_versions=[],
urgency=Vulnerability.Urgency.NONE, fix_available=True)
self.device.deb_packages.get(name='python2').vulnerabilities.add(v)

# Has vulnerable packages - should render them
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'python2')
self.assertContains(response, 'CVE-123')

def test_heartbleed_render(self):
self.device.deb_packages_hash = 'aabbccdd'
self.client.login(username='test', password='123')
Expand Down
3 changes: 2 additions & 1 deletion backend/device_registry/tests/test_recommended_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@ def enable_action(self):
deb_package = DebPackage.objects.create(name='package', version='version1', source_name='package',
source_version='sversion1', arch='amd64', os_release_codename='jessie')
vulnerability = Vulnerability.objects.create(name='name', package='package', is_binary=True, other_versions=[],
urgency='L', fix_available=True, os_release_codename='jessie')
urgency=Vulnerability.Urgency.LOW, fix_available=True,
os_release_codename='jessie')
deb_package.vulnerabilities.add(vulnerability)
self.device.deb_packages.add(deb_package)

Expand Down
2 changes: 2 additions & 0 deletions backend/device_registry/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,8 @@ def get_context_data(self, **kwargs):
table_rows = []
for cve_name, cve_packages in packages_by_cve.items():
plist = sorted([self.AffectedPackage(p.name,
# FIXME: this line may need additional optimisation to avoid calling
# device_set.filter() every time.
[device] if device else list(p.device_set.filter(owner=user)))
for p in cve_packages],
key=lambda p: len(p.devices), reverse=True)
Expand Down

0 comments on commit a4a6f8d

Please sign in to comment.