From: Philipp Gesang Date: Tue, 28 Feb 2017 15:34:34 +0000 (+0100) Subject: unit test bogus header data X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=0dae78de7cc30f982a8b8b35920d0be56e0db82b;p=python-delta-tar unit test bogus header data --- diff --git a/testing/test_crypto.py b/testing/test_crypto.py index 559c06b..e0c02a0 100644 --- a/testing/test_crypto.py +++ b/testing/test_crypto.py @@ -44,7 +44,12 @@ def fill_mod (n): def faux_payload (): return "abcd" * 42 + class CryptoLayerTest (unittest.TestCase): + pass + + +class AESGCMTest (CryptoLayerTest): def test_crypto_aes_gcm_enc_simple (self): NaCl = os.urandom (CRYPTO_NACL_SIZE) @@ -251,6 +256,8 @@ class CryptoLayerTest (unittest.TestCase): ok, _, _ = dec.done () +class HeaderTest (CryptoLayerTest): + def test_crypto_fmt_hdr_make (self): meta = faux_hdr() ok, hdr = crypto.hdr_make (meta) @@ -258,6 +265,12 @@ class CryptoLayerTest (unittest.TestCase): assert len (hdr) == crypto.I2N_HDR_SIZE + def test_crypto_fmt_hdr_make_useless (self): + ok, ret = crypto.hdr_make ({ 42: "x" }) + assert ok is False + assert ret.startswith ("error writing header:") + + def test_crypto_fmt_hdr_read (self): meta = faux_hdr() ok, hdr = crypto.hdr_make (meta) @@ -270,3 +283,29 @@ class CryptoLayerTest (unittest.TestCase): % (meta [k], mmeta [k]) + def test_crypto_fmt_hdr_read_trailing_garbage (self): + meta = faux_hdr() + ok, hdr = crypto.hdr_make (meta) + hdr += b"-junk" + ok, msg = crypto.hdr_read (hdr) + assert ok is False + assert msg.startswith ("error reading header from") + + + def test_crypto_fmt_hdr_read_leading_garbage (self): + meta = faux_hdr() + ok, hdr = crypto.hdr_make (meta) + hdr = b"junk-" + hdr + ok, msg = crypto.hdr_read (hdr) + assert ok is False + assert msg.startswith ("error reading header from") + + + def test_crypto_fmt_hdr_inner_garbage (self): + meta = faux_hdr() + ok, hdr = crypto.hdr_make (meta) + hdr = hdr[:len(hdr)//2] + b"junk-" + hdr[len(hdr)//2:] + ok, msg = crypto.hdr_read (hdr) + assert ok is False + assert msg.startswith ("error reading header from") +