about summary refs log tree commit diff
path: root/tst/test_listen.py
diff options
context:
space:
mode:
authorNguyễn Gia Phong <cnx@loang.net>2025-06-07 17:46:45 +0900
committerNguyễn Gia Phong <cnx@loang.net>2025-06-07 17:46:45 +0900
commit637e73f023107c142c1eecc187c18a5581c10794 (patch)
treecb290f10d14d9abd42832823a129367725bcdaf8 /tst/test_listen.py
parent15ba0b0cc93ffe8a2047399b95fe064e23ba1013 (diff)
downloadscadere-637e73f023107c142c1eecc187c18a5581c10794.tar.gz
Ensure ID uniqueness for certificates
Diffstat (limited to 'tst/test_listen.py')
-rw-r--r--tst/test_listen.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/tst/test_listen.py b/tst/test_listen.py
index 662c576..49b9dd8 100644
--- a/tst/test_listen.py
+++ b/tst/test_listen.py
@@ -33,12 +33,12 @@ from xml.etree.ElementTree import (XML, XMLParser, indent,
 from hypothesis import HealthCheck, given, settings
 from hypothesis.strategies import (booleans, composite, data,
                                    datetimes, from_type, integers,
-                                   lists, sampled_from, text)
+                                   sampled_from, sets, text, uuids)
 from hypothesis.provisional import domains, urls
 from pytest import raises
 
 from scadere.check import base64_from_str, printable
-from scadere.listen import (handle, is_subdomain, path,
+from scadere.listen import (handle, is_subdomain, path, parse_summary,
                             str_from_base64, with_trailing_slash, xml)
 
 ATOM_NAMESPACES = {'': 'http://www.w3.org/2005/Atom'}
@@ -69,7 +69,7 @@ def test_path(hostname, port, number, string):
     assert str_from_base64(r[2]) == string
 
 
-@given(domains(), lists(domains()))
+@given(domains(), sets(domains()))
 def test_is_subdomain(subject, objects):
     if not objects:
         assert is_subdomain(subject, objects)
@@ -101,7 +101,7 @@ def certificates(draw):
     not_after = draw(datetimes()).isoformat()
     hostname = draw(domains())
     port = draw(ports())
-    number = draw(serials())
+    number = draw(serials()) if valid else draw(uuids(version=4)).int
     string = draw(base64s())
     return f'{not_before} {not_after} {hostname} {port} {number} {string}'
 
@@ -214,9 +214,15 @@ async def check_server(handler, func, *args):
         rmtree(d)
 
 
+def unique_netlocs(summaries):
+    """Return summaries for unique network locations."""
+    return {parse_summary(summary)[2:4]: summary
+            for summary in summaries}.values()
+
+
 @given(urls().filter(is_base_url).filter(has_usual_path),
-       lists(certificates(), min_size=1))
-@settings(deadline=None)
+       sets(certificates(), min_size=1).map(unique_netlocs))
+@settings(suppress_health_check=[HealthCheck.too_slow])
 async def test_content(base_url, certs):
     base_path = urlsplit(base_url).path
     with tmp_cert_file(certs) as cert_file: