test_digestverifyingreader.py 1.1 KB

1234567891011121314151617181920212223242526
  1. import pytest
  2. from warcio.digestverifyingreader import _compare_digest_rfc_3548
  3. from warcio.utils import Digester
  4. empty_sha1_b32 = '3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ'
  5. empty_sha1_b64 = '2jmj7l5rSw0yVb/vlWAYkK/YBwk='
  6. empty_sha1_b64_alt = '2jmj7l5rSw0yVb_vlWAYkK_YBwk='
  7. empty_sha1_b16 = 'DA39A3EE5E6B4B0D3255BFEF95601890AFD80709'
  8. def test_compare_digest_rfc_3548():
  9. assert _compare_digest_rfc_3548(None, None) is None
  10. sha1d = Digester('sha1')
  11. assert _compare_digest_rfc_3548(sha1d, 'sha1:'+empty_sha1_b32) is True
  12. assert _compare_digest_rfc_3548(sha1d, 'sha1:'+empty_sha1_b32.replace('3I', 'xx')) is False
  13. assert _compare_digest_rfc_3548(sha1d, 'sha1:'+empty_sha1_b64) is True
  14. assert _compare_digest_rfc_3548(sha1d, 'sha1:'+empty_sha1_b64_alt) is True
  15. assert _compare_digest_rfc_3548(sha1d, 'sha1:'+empty_sha1_b16) is True
  16. assert _compare_digest_rfc_3548(sha1d, 'sha1:'+empty_sha1_b16.lower()) is True
  17. with pytest.raises(ValueError):
  18. assert _compare_digest_rfc_3548(sha1d, 'foo') is False
  19. assert _compare_digest_rfc_3548(sha1d, 'foo:bar') is False