Skip to content

Commit

Permalink
Merge pull request #222 from tarnfeld/empty-ssl-consistency
Browse files Browse the repository at this point in the history
SSL consistency renderer cannot call max() with no arguments
  • Loading branch information
chrisamin committed Sep 1, 2020
2 parents 3ddfcce + 12e93f2 commit e0606e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ripe/atlas/tools/renderers/ssl_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def get_nprobes_ofpopular_cert(self):
Gets the number of probes that have seen the most popular
(in terms of probes) cert.
"""
if not self.uniqcerts:
return 0
return max(
[self.uniqcerts[cert_id]["cnt"] for cert_id in self.uniqcerts]
)
Expand Down
12 changes: 12 additions & 0 deletions tests/renderers/ssl_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ def test_get_nprobes_ofpopular_cert(self):
renderer.gather_unique_certs(sagans)
self.assertEquals(renderer.get_nprobes_ofpopular_cert(), 11)

def test_get_nprobes_ofpopular_cert_empty(self):
"""Tests that getting the number of probes for popular certs does not
throw an error when there are no valid certificates."""

path = 'ripe.atlas.tools.helpers.rendering.Probe.get_many'
with mock.patch(path) as mock_get_many:
mock_get_many.return_value = self.probes.values()
sagans = SaganSet([])
renderer = Renderer()
renderer.gather_unique_certs(sagans)
self.assertEquals(renderer.get_nprobes_ofpopular_cert(), 0)

def test_render_certificate(self):
"""Tests rendering of single certificate."""
expected_output = (
Expand Down

0 comments on commit e0606e2

Please sign in to comment.