diff --git a/casimport/__init__.py b/casimport/__init__.py index 9e7f4b4..3ee5dd3 100644 --- a/casimport/__init__.py +++ b/casimport/__init__.py @@ -669,3 +669,23 @@ class Test(unittest.TestCase): # a local ipfs gateway makes more sense than hitting a # public gateway pass + + def test_filecorruption(self): + cachedir = self.tempdir / 'cachedir' + cachedir.mkdir() + + # that an existing file + shutil.copy(self.fixtures / 'hello.py', cachedir) + + # is in the cache + fdcas = FileDirCAS(cachedir) + + # that when refresh is surpressed + fdcas.refresh_dir = lambda: None + + # and has a bogus hash + fdcas._hashes['0000'] = cachedir / 'hello.py' + + # that when read raises an exception + with self.assertRaises(ValueError): + fdcas.fetch_data(urllib.parse.urlparse('hash://sha256/0000'))