# Tests for the HTTP server # Copyright (C) 2025 Nguyễn Gia Phong # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . from base64 import urlsafe_b64decode as from_base64 from hypothesis import given from hypothesis.strategies import integers, datetimes, text from hypothesis.provisional import domains from scadere.listen import body, path @given(domains(), integers(1, 65535), text(), integers(0, 256**20)) def test_path(hostname, port, issuer, serial): r = path(hostname, port, issuer, hex(serial).removeprefix('0x')).split('/') assert(r[0] == hostname) assert(int(r[1]) == port) assert(from_base64(r[2]).decode() == issuer) assert(int(r[3], 16) == serial) @given(domains(), integers(1, 65535), text(), integers(0, 256**20), datetimes(), datetimes()) def test_body(hostname, port, issuer, serial, not_before, not_after): r = body(not_before, not_after, hostname, port, hex(serial).removeprefix('0x'), issuer) assert(r[-1][0] == 'dl') d = dict(zip((v for k, v in r[-1][1:] if k == 'dt'), (v for k, v in r[-1][1:] if k == 'dd'))) assert(d['Domain'] == hostname) assert(d['Port'] == port) assert(d['Issuer'] == issuer) assert(int(d['Serial number'], 16) == serial) assert(d['Valid from'] == not_before) assert(d['Valid until'] == not_after)