If a file /submission/.sh is present, run it as a tests suite

This commit is contained in:
nemunaire 2021-10-05 12:30:55 +02:00
parent a52c756159
commit d1b358fcd1
2 changed files with 27 additions and 0 deletions

View File

@ -4,6 +4,7 @@ from datetime import datetime
import email import email
import email.policy import email.policy
import os import os
from os.path import exists
import sys import sys
import stat import stat
import subprocess import subprocess
@ -24,6 +25,7 @@ import late
import login import login
import signature import signature
from test import MailTest from test import MailTest
import tests
def signcheck(data): def signcheck(data):
yield MailTest("Those tests are limited to signature checking. THIS IS NOT THE SUBMISSION INTERFACE.", 2) yield MailTest("Those tests are limited to signature checking. THIS IS NOT THE SUBMISSION INTERFACE.", 2)
@ -54,6 +56,8 @@ def gen_checks(gpgmail, submissions_dir, check_content=False, check_submission_h
yield ( archive.hash_archive, [submissions_dir, check_submission_hash] ) 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] )
if exists(submissions_dir + ".sh"):
yield ( tests.run_script, [submissions_dir + ".sh"] )
def respondissueemail(to, subject, ref, initial_to=None): def respondissueemail(to, subject, ref, initial_to=None):

23
tests.py Normal file
View File

@ -0,0 +1,23 @@
import subprocess
from test import MailTest
def run_script(dest, script):
with subprocess.Popen(
["/bin/sh", script],
cwd=dest,
env={"LANG": 'C'},
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
) as p:
p.wait()
err = p.stdout.read().decode('utf-8', 'replace')
err += p.stderr.read().decode('utf-8', 'replace')
if p.returncode == 0:
yield MailTest("Preliminary tests:", details=err.replace(dest, "/rendu/"))
yield dest
elif p.returncode == 124 or p.returncode == 137:
yield MailTest("Preliminary tests aborted for too long execution:", 1, details=err.replace(dest, "/rendu/"))
else:
yield MailTest("An error occured during preliminary tests:", 2, details=err.replace(dest, "/rendu/"))
yield dest