Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Only validate hash algorithms that the user can upload on the model.
Browse files Browse the repository at this point in the history
  • Loading branch information
werwty committed Jan 23, 2018
1 parent 6d8e79b commit ad4c40a
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions pulpcore/pulpcore/app/serializers/content.py
Expand Up @@ -94,19 +94,21 @@ def validate(self, data):
data['size'] = data['file'].size

for algorithm in hashlib.algorithms_guaranteed:
digest = data['file'].hashers[algorithm].hexdigest()

if algorithm in data and digest != data[algorithm]:
raise serializers.ValidationError(_("The %s checksum did not match.") % algorithm)
else:
data[algorithm] = digest
if algorithm in UNIQUE_ALGORITHMS:
validator = UniqueValidator(models.Artifact.objects.all(),
message=_("{0} checksum must be "
"unique.").format(algorithm))
validator.field_name = algorithm
validator.instance = None
validator(digest)
if algorithm in models.Artifact.DIGEST_FIELDS:
digest = data['file'].hashers[algorithm].hexdigest()

if algorithm in data and digest != data[algorithm]:
raise serializers.ValidationError(_("The %s checksum did not match.")
% algorithm)
else:
data[algorithm] = digest
if algorithm in UNIQUE_ALGORITHMS:
validator = UniqueValidator(models.Artifact.objects.all(),
message=_("{0} checksum must be "
"unique.").format(algorithm))
validator.field_name = algorithm
validator.instance = None
validator(digest)
return data

class Meta:
Expand Down

0 comments on commit ad4c40a

Please sign in to comment.