diff options
author | Nguyễn Gia Phong <cnx@loang.net> | 2025-05-25 19:05:44 +0900 |
---|---|---|
committer | Nguyễn Gia Phong <cnx@loang.net> | 2025-05-25 19:05:44 +0900 |
commit | 7c888edbb9512e8cc75c302d487b5c2e4eace62c (patch) | |
tree | 07deb8a957be8aa26d2b45a489e43086ed071f78 /tst/test_listen.py | |
parent | 552c60f5fd0395acabfd8320a5372c54df23a5ea (diff) | |
download | scadere-7c888edbb9512e8cc75c302d487b5c2e4eace62c.tar.gz |
Add some basic tests
Diffstat (limited to 'tst/test_listen.py')
-rw-r--r-- | tst/test_listen.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tst/test_listen.py b/tst/test_listen.py new file mode 100644 index 0000000..d3a8052 --- /dev/null +++ b/tst/test_listen.py @@ -0,0 +1,48 @@ +# 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 <https://www.gnu.org/licenses/>. + +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) |