New option to impose a particular tarball hash

This commit is contained in:
nemunaire 2017-10-20 13:38:14 +02:00
parent 42409660a5
commit b308fe4669
2 changed files with 12 additions and 7 deletions

View File

@ -44,13 +44,15 @@ def find(cnt):
yield (data, login) yield (data, login)
def hash_archive(cnt, dest=None): def hash_archive(cnt, dest=None, imposed_hash=None):
data, login = cnt data, login = cnt
sha = hashlib.sha1(data.encode() if isinstance(data, str) else data).hexdigest() sha = hashlib.sha1(data.encode() if isinstance(data, str) else data).hexdigest()
yield MailTest("Your tarball SHA-1 is %s." % sha, -1) yield MailTest("Your tarball SHA-1 is %s." % sha, -1)
if dest is not None and os.path.exists(os.path.join(dest, login + "." + sha)): if dest is not None and os.path.exists(os.path.join(dest, login + "." + sha)):
yield MailTest("You have already uploaded this tarball.", 1) yield MailTest("You have already uploaded this tarball.", 1)
yield False yield False
elif imposed_hash is not None and imposed_hash != sha:
yield MailTest("This is not the expected hash. Your tarball's hash must be: %s." % imposed_hash, 1)
else: else:
yield (data, sha, login) yield (data, sha, login)

View File

@ -28,17 +28,17 @@ def signcheck(data):
yield data yield data
def gen_checks(submissions_dir, check_content=False): def gen_checks(submissions_dir, check_content=False, check_submission_hash=None):
if HARD_MAX_SUBMISSION is not None and check_content: if HARD_MAX_SUBMISSION is not None and check_content:
yield (late.check, [HARD_MAX_SUBMISSION, SOFT_MAX_SUBMISSION]) yield (late.check, [HARD_MAX_SUBMISSION, SOFT_MAX_SUBMISSION])
else: elif not check_content:
yield signcheck yield signcheck
yield (envelope.check, [GNUPG_DIRECTORY, BETA]) yield (envelope.check, [GNUPG_DIRECTORY, BETA])
yield (signature.check, [GNUPG_DIRECTORY]) yield (signature.check, [GNUPG_DIRECTORY])
yield (login.check, ["/home/nemunaire/workspace/check_mail/SRS2017.csv"]) yield (login.check, ["/home/nemunaire/workspace/check_mail/SRS2017.csv"])
if check_content: if check_content:
yield archive.find yield archive.find
yield ( archive.hash_archive, [submissions_dir] ) yield ( archive.hash_archive, [submissions_dir, check_submission_hash] )
yield archive.guess_mime yield archive.guess_mime
yield ( archive.extract, [submissions_dir] ) yield ( archive.extract, [submissions_dir] )
@ -122,14 +122,14 @@ def readmail(fp):
return cnt, frm, subject, ref return cnt, frm, subject, ref
def check_mail(cnt, submissions_dir, check_content=False): def check_mail(cnt, submissions_dir, check_content=False, check_submission_hash=None):
results = [] results = []
# sentinel # sentinel
results.append([(None, [cnt])]) results.append([(None, [cnt])])
lvl = 0 lvl = 0
for check in gen_checks(submissions_dir=submissions_dir, check_content=check_content): for check in gen_checks(submissions_dir=submissions_dir, check_content=check_content, check_submission_hash=check_submission_hash):
lvl += 1 lvl += 1
curr = [] curr = []
curc = [] curc = []
@ -207,6 +207,9 @@ if __name__ == '__main__':
parser.add_argument('--submissions', default="/tmp/rendus", parser.add_argument('--submissions', default="/tmp/rendus",
help="directory where store submissions") help="directory where store submissions")
parser.add_argument('--expected-submission-hash',
help="imposed tarball hash")
parser.add_argument('--beta', action="store_true", parser.add_argument('--beta', action="store_true",
help="enable beta features") help="enable beta features")
@ -226,4 +229,4 @@ if __name__ == '__main__':
BETA = args.beta BETA = args.beta
cnt, frm, subject, ref = readmail(sys.stdin.buffer) cnt, frm, subject, ref = readmail(sys.stdin.buffer)
respondmail(frm, subject, ref, [c for c in check_mail(cnt, submissions_dir=args.submissions, check_content=not args.sign)]) respondmail(frm, subject, ref, [c for c in check_mail(cnt, submissions_dir=args.submissions, check_content=not args.sign, check_submission_hash=args.expected_submission_hash)])