Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix viewing testrun results (issue #123) #124

Merged
merged 3 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions oioioi/testrun/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,20 @@ def adjust_submission_form(self, request, form, problem_instance):
if form.kind != 'TESTRUN':
return

# We need to check using is_zipfile, as sioworkers do the same.
# Otherwise one could bypass checks and limits for example by
# uploading a zipfile without the '.zip' extension.
def validate_file_size(file):
if (
file.name.upper().endswith(".ZIP")
is_zipfile(file)
and file.size > self.get_testrun_zipped_input_limit()
):
raise ValidationError(_("Zipped input file size limit exceeded."))
elif file.size > self.get_testrun_input_limit():
raise ValidationError(_("Input file size limit exceeded."))

def validate_zip(file):
if file.name.upper().endswith(".ZIP"):
if is_zipfile(file):
archive = Archive(file, '.zip')
if len(archive.filenames()) != 1:
raise ValidationError(_("Archive should have only 1 file inside."))
Expand Down Expand Up @@ -279,7 +282,7 @@ def render_submission(self, request, submission):
context={
'submission': submission_template_context(request, sbm_testrun),
'supported_extra_args': self.get_supported_extra_args(submission),
'input_is_zip': is_zipfile(sbm_testrun.input_file),
'input_is_zip': is_zipfile(sbm_testrun.input_file.read_using_cache()),
},
)

Expand All @@ -295,7 +298,7 @@ def _render_testrun_report(
input_is_zip = False
if testrun_report:
input_is_zip = is_zipfile(
testrun_report.submission_report.submission.programsubmission.testrunprogramsubmission.input_file
testrun_report.submission_report.submission.programsubmission.testrunprogramsubmission.input_file.read_using_cache()
)

return render_to_string(
Expand Down
7 changes: 6 additions & 1 deletion oioioi/testrun/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from zipfile import is_zipfile

from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
from django.urls import reverse
Expand Down Expand Up @@ -127,7 +129,10 @@ def download_input_file_view(request, submission_id):
submission = get_submission_or_error(
request, submission_id, TestRunProgramSubmission
)
return stream_file(submission.input_file, name='input.in')
filename = 'input.in'
if is_zipfile(submission.input_file.read_using_cache()):
filename = 'input.zip'
return stream_file(submission.input_file, name=filename)


@enforce_condition(contest_exists & can_enter_contest)
Expand Down