Skip to content

Commit

Permalink
Add file checksum and dir list integration tests
Browse files Browse the repository at this point in the history
Co-authored-by: Lazlo Westerhof <[email protected]>
  • Loading branch information
stsnel and lwesterhof committed Dec 3, 2024
1 parent 9bb667e commit ab484ba
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
72 changes: 72 additions & 0 deletions integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,36 @@ def _test_folder_secure_func(ctx, func):
{"name": "msvc.msi_vault_stat.outsidevault2",
"test": lambda ctx: _call_msvc_stat_vault_check_exc(ctx, "dev001_1", "/var/lib/irods/Vault1_2/yoda/licenses/GNU General Public License v3.0.uri"),
"check": lambda x: x},
{"name": "msvc.msi_file_checksum.file",
"test": lambda ctx: _call_file_checksum_either_resc(ctx, "/var/lib/irods/VaultX/yoda/licenses/GNU General Public License v3.0.txt"),
"check": lambda x: x == "sha2:OXLcl0T2SZ8Pmy2/dmlvKuetivmyPd5m1q+Gyd+zaYY="},
{"name": "msvc.msi_file_checksum.file_not_exist",
"test": lambda ctx: _call_file_checksum_check_exc(ctx, '/var/lib/irods/Vault1_2/yoda/licenses/doesnotexist.txt', 'dev001_2'),
"check": lambda x: x},
{"name": "msvc.msi_file_checksum.resc_not_exist",
"test": lambda ctx: _call_file_checksum_check_exc(ctx, '/var/lib/irods/Vault1_1/yoda/licenses/GNU General Public License v3.0.txt', 'non-existent-resource'),
"check": lambda x: x},
{"name": "msvc.msi_file_checksum.outside_vault",
"test": lambda ctx: _call_file_checksum_check_exc(ctx, '/etc/passwd', 'dev001_2'),
"check": lambda x: x},
{"name": "msvc.msi_dir_list.dir",
"test": lambda ctx: _call_dir_list(ctx, "/var/lib/irods/Vault1_1/yoda", "dev001_1"),
"check": lambda x: len(x) == len([entry for entry in os.listdir("/var/lib/irods/Vault1_1/yoda") if os.path.isdir("/var/lib/irods/Vault1_1/yoda/" + entry)])},
{"name": "msvc.msi_dir_list.dir_not_exist",
"test": lambda ctx: _call_dir_list_check_exc(ctx, '/var/lib/irods/Vault1_2/yoda/doesnotexist', 'dev001_2'),
"check": lambda x: x},
{"name": "msvc.msi_dir_list.file_resc_1",
"test": lambda ctx: _call_dir_list_check_exc(ctx, '/var/lib/irods/Vault1_1/yoda/licenses/GNU General Public License v3.0.txt', 'dev001_1'),
"check": lambda x: x},
{"name": "msvc.msi_dir_list.file_resc_2",
"test": lambda ctx: _call_dir_list_check_exc(ctx, '/var/lib/irods/Vault1_2/yoda/licenses/GNU General Public License v3.0.txt', 'dev001_2'),
"check": lambda x: x},
{"name": "msvc.msi_dir_list.resc_not_exist",
"test": lambda ctx: _call_dir_list_check_exc(ctx, '/var/lib/irods/Vault1_1/yoda', 'non-existent-resource'),
"check": lambda x: x},
{"name": "msvc.msi_dir_list.outside_vault",
"test": lambda ctx: _call_dir_list_check_exc(ctx, '/etc/passwd', 'dev001_2'),
"check": lambda x: x},
{"name": "msvc.rmw_avu_collection_literal",
"test": lambda ctx: _test_msvc_rmw_avu_collection(ctx, ("foo", "bar", "baz")),
"check": lambda x: (("aap", "noot", "mies") in x
Expand Down Expand Up @@ -706,3 +736,45 @@ def rule_run_integration_tests(ctx, tests):
return_value += name + " " + verdict + "\n"

return return_value


def _call_file_checksum_either_resc(ctx, filename):
"""Returns result of file checksum microservice for either of the
two main UFS resources (dev001_1, dev001_2). If one returns an
exception, we try the other.
:param ctx: combined type of a callback and rei struct
:param filename: name of file to checksum
:returns: output of file checksum microservice
"""
try:
vault_filename = filename.replace("VaultX", "Vault1_1")
ret = msi.file_checksum(ctx, vault_filename, 'dev001_1', '')
except Exception:
vault_filename = filename.replace("VaultX", "Vault1_2")
ret = msi.file_checksum(ctx, vault_filename, 'dev001_2', '')
return ret['arguments'][2]


def _call_file_checksum_check_exc(ctx, filename, resc_name):
"""Verifies whether a call to the file checksum microservice raises an exception"""
try:
msi.file_checksum(ctx, filename, resc_name, '')
return False
except Exception:
return True


def _call_dir_list(ctx, dirname, resc_name):
ret = msi.dir_list(ctx, dirname, resc_name, "")
print(ret['arguments'][2])
return json.loads(ret['arguments'][2])


def _call_dir_list_check_exc(ctx, dirname, resc_name):
try:
msi.dir_list(ctx, dirname, resc_name, "")
return False
except Exception:
return True
2 changes: 2 additions & 0 deletions util/msi.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def _make_exception(name, message):
get_obj_type, GetObjTypeError = make('GetObjType', 'Could not get object type')
mod_avu_metadata, ModAVUMetadataError = make('ModAVUMetadata', 'Could not modify AVU metadata')
stat_vault, MSIStatVaultError = make("_stat_vault", 'Could not stat file system object in vault.')
file_checksum, FileChecksumError = make("_file_checksum", 'Could not calculate non-persistent checksum of vault file.')
dir_list, DirListError = make("_dir_list", 'Could not list vault directory contents.')

archive_create, ArchiveCreateError = make('ArchiveCreate', 'Could not create archive')
archive_index, ArchiveIndexError = make('ArchiveIndex', 'Could not index archive')
Expand Down

0 comments on commit ab484ba

Please sign in to comment.