From ba0b06637bcec3a01d8e6a11884fbad1a0f5d612 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Mon, 19 Mar 2018 11:58:49 +0200 Subject: Add support for HMAC signatures, fixes #4 --- tests/test_viewstate.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests') diff --git a/tests/test_viewstate.py b/tests/test_viewstate.py index ca20167..9cc9285 100644 --- a/tests/test_viewstate.py +++ b/tests/test_viewstate.py @@ -26,3 +26,23 @@ class TestViewState(object): with pytest.raises(ViewStateException): vs = ViewState(raw=b'\x01\x02') vs.decode() + + def test_no_signature(self): + vs = ViewState(raw=b'\xff\x01e') + vs.decode() + assert vs.mac is None + assert vs.signature is None + + def test_macs(self): + MAC_LENGTHS = { + 'hmac_sha1': 20, + 'hmac_sha256': 32, + 'unknown': 5 # could be any other value + } + + for mac, n in MAC_LENGTHS.items(): + sig = b'\x55' * n # not a real signature, just testing length + vs = ViewState(raw=b'\xff\x01d' + sig) + vs.decode() + assert vs.mac == mac + assert vs.signature == sig -- cgit v1.3.1