diff --git a/src/python/jw/pkg/lib/ec/secret_store/KvFile.py b/src/python/jw/pkg/lib/ec/secret_store/KvFile.py index fb7d954c..498ecb92 100644 --- a/src/python/jw/pkg/lib/ec/secret_store/KvFile.py +++ b/src/python/jw/pkg/lib/ec/secret_store/KvFile.py @@ -215,6 +215,8 @@ class KvFile(Base): secret_path = f'/{config_path}{BLOB_SUFFIX}' if await self.__ctx.file_exists(secret_path): return await self.__ctx.get(secret_path) + if await self.__ctx.is_dir(f'/{config_path}'): + raise IsADirectoryError(errno.EISDIR, f'get: {path}') if '/' not in config_path: raise FileNotFoundError(path) compound, key = config_path.rsplit('/', 1) diff --git a/test/unit/python/jw/pkg/lib/ec/secret_store/KvFile/test.py b/test/unit/python/jw/pkg/lib/ec/secret_store/KvFile/test.py index 6313f998..594dd9cc 100644 --- a/test/unit/python/jw/pkg/lib/ec/secret_store/KvFile/test.py +++ b/test/unit/python/jw/pkg/lib/ec/secret_store/KvFile/test.py @@ -82,6 +82,17 @@ async def run_tests() -> None: except FileNotFoundError: pass + # -- A directory refuses a get: stat() answers a directory, + # get() raises IsADirectoryError, the two agree + for path in ('', os.path.dirname(target)): + st = await store.stat(path) + assert st.ftype is FT_DIR + try: + await store.get(path) + raise AssertionError(f'expected IsADirectoryError for {path}') + except IsADirectoryError: + pass + # put writes a key into the entry file, merging with the # existing keys await store.put(f'{target}/key4', b'value4', ftype = FT_SECRET_KEY)