Skip to content

Commit

Permalink
update md5 validation for case insensitivity (#2032)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Oct 29, 2024
1 parent cde2d41 commit 624e3de
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Changed
- Unify user name parameter naming in flows (#1653)
- Refactor ``landing_zone_move`` flow (#1846)
- Move ``lock_project()`` into ``TaskflowTestMixin`` (#1847)
- Make MD5 checksum comparison case insensitive (#2032)

Fixed
-----
Expand Down
6 changes: 5 additions & 1 deletion taskflowbackend/tasks/irods_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,11 @@ def _compare_checksums(cls, data_obj, checksum):
:raises: Exception if checksums do not match
"""
for replica in data_obj.replicas:
if checksum != replica.checksum:
if (
not checksum
or not replica.checksum
or checksum.lower() != replica.checksum.lower()
):
msg = (
'Checksums do not match for "{}" in resource "{}" '
'(File: {}; iRODS: {})'.format(
Expand Down
25 changes: 24 additions & 1 deletion taskflowbackend/tests/test_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
UserDoesNotExist,
UserGroupDoesNotExist,
)
from irods.test.helpers import make_object
from irods.ticket import Ticket
from irods.user import iRODSUser, iRODSUserGroup

Expand Down Expand Up @@ -995,8 +996,30 @@ def test_validate(self):
sample_coll_path = os.path.join(self.sample_path, COLL_NAME)
self.assertEqual(self.irods.collections.exists(sample_coll_path), False)

def test_validate_upper_case(self):
"""Test landing_zone_move validation with upper case checksum in file"""
coll_path = os.path.join(self.zone_path, COLL_NAME)
zone_coll = self.irods.collections.create(coll_path)
obj = self.make_irods_object(zone_coll, OBJ_NAME)
md5_path = obj.path + '.md5'
md5_content = self.get_md5_checksum(obj).upper()
make_object(self.irods, md5_path, md5_content)
flow_data = {
'zone_uuid': str(self.zone.sodar_uuid),
'validate_only': True,
}
flow = self.taskflow.get_flow(
irods_backend=self.irods_backend,
project=self.project,
flow_name='landing_zone_move',
flow_data=flow_data,
)
self.build_and_run(flow)
self.zone.refresh_from_db()
self.assertEqual(self.zone.status, ZONE_STATUS_ACTIVE)

def test_validate_no_checksum(self):
"""Test landing_zone_validation with missing checksum"""
"""Test landing_zone_move validation with missing checksum"""
coll_path = os.path.join(self.zone_path, COLL_NAME)
zone_coll = self.irods.collections.create(coll_path)
obj = self.make_irods_object(zone_coll, OBJ_NAME, checksum=False)
Expand Down

0 comments on commit 624e3de

Please sign in to comment.