Browse Source

add test to make sure that when a bogus hash entry is entered, it gets caught

main
John-Mark Gurney 5 years ago
parent
commit
337800a408
1 changed files with 20 additions and 0 deletions
  1. +20
    -0
      casimport/__init__.py

+ 20
- 0
casimport/__init__.py View File

@@ -669,3 +669,23 @@ class Test(unittest.TestCase):
# a local ipfs gateway makes more sense than hitting a # a local ipfs gateway makes more sense than hitting a
# public gateway # public gateway
pass 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'))

Loading…
Cancel
Save