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

Account for non-xml submission objects #2663

Merged
merged 2 commits into from
Jan 24, 2025
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
31 changes: 21 additions & 10 deletions app/Http/Controllers/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,28 @@ private function submitProcess(): Response

// Figure out what type of XML file this is.
$stored_filename = 'inbox/' . $filename;
$xml_info = SubmissionUtils::get_xml_type(fopen(Storage::path($stored_filename), 'r'), $stored_filename);

// If validation is enabled and if this file has a corresponding schema, validate it
$validation_errors = $xml_info['xml_handler']::validate(storage_path('app/' . $stored_filename));
if (count($validation_errors) > 0) {
$error_string = implode(PHP_EOL, $validation_errors);

// We always log validation failures, but we only send messages back to the client if configured to do so
Log::warning("Submission validation failed for file '$filename':" . PHP_EOL);
$xml_info = [];
try {
$xml_info = SubmissionUtils::get_xml_type(fopen(Storage::path($stored_filename), 'r'), $stored_filename);
} catch (BadSubmissionException $e) {
$xml_info['xml_handler'] = '';
$message = "Could not determine submission file type for: '{$stored_filename}'";
Log::warning($message);
if ((bool) config('cdash.validate_xml_submissions') === true) {
abort(400, "XML validation failed: rejected file $filename:" . PHP_EOL . $error_string);
abort(400, $message);
}
}
if ($xml_info['xml_handler'] !== '') {
// If validation is enabled and if this file has a corresponding schema, validate it
$validation_errors = $xml_info['xml_handler']::validate(storage_path('app/' . $stored_filename));
if (count($validation_errors) > 0) {
$error_string = implode(PHP_EOL, $validation_errors);

// We always log validation failures, but we only send messages back to the client if configured to do so
Log::warning("Submission validation failed for file '$filename':" . PHP_EOL);
if ((bool) config('cdash.validate_xml_submissions') === true) {
abort(400, "XML validation failed: rejected file $filename:" . PHP_EOL . $error_string);
}
}
}

Expand Down
4 changes: 0 additions & 4 deletions app/Jobs/ProcessSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use AbstractSubmissionHandler;
use ActionableBuildInterface;
use App\Exceptions\BadSubmissionException;
use App\Models\SuccessfulJob;
use App\Utils\UnparsedSubmissionProcessor;
use BuildPropertiesJSONHandler;
Expand Down Expand Up @@ -133,8 +132,6 @@ private function requeueSubmissionFile($buildid): bool
* Execute the job.
*
* @return void
*
* @throws BadSubmissionException
*/
public function handle()
{
Expand Down Expand Up @@ -199,7 +196,6 @@ public function failed(Throwable $exception): void
* This method could be running on a worker that is either remote or local, so it accepts
* a file handle or a filename that it can query the CDash API for.
*
* @throws BadSubmissionException
**/
private function doSubmit($filename, $projectid, $buildid = null, $expected_md5 = ''): AbstractSubmissionHandler|UnparsedSubmissionProcessor|false
{
Expand Down
17 changes: 13 additions & 4 deletions app/cdash/include/ctestparser.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ function parse_put_submission($filehandler, $projectid, $expected_md5, ?int $bui

/**
* Main function to parse the incoming xml from ctest
*
* @throws BadSubmissionException
*/
function ctest_parse($filehandle, string $filename, $projectid, $expected_md5 = '', ?int $buildid = null): AbstractSubmissionHandler|false
{
Expand All @@ -185,9 +183,20 @@ function ctest_parse($filehandle, string $filename, $projectid, $expected_md5 =

$Project = new Project();
$Project->Id = $projectid;

$xml_info = [];
// Figure out what type of XML file this is.
$xml_info = SubmissionUtils::get_xml_type($filehandle, $filename);
try {
$xml_info = SubmissionUtils::get_xml_type($filehandle, $filename);
} catch (BadSubmissionException $e) {
$xml_info['file_handle'] = $filehandle;
$xml_info['xml_handler'] = null;
$xml_info['xml_type'] = '';
$message = "Could not determine submission file type for: '{$filename}'";
Log::warning($message);
if ((bool) config('cdash.validate_xml_submissions') === true) {
abort(400, $message);
}
}
$filehandle = $xml_info['file_handle'];
$handler_ref = $xml_info['xml_handler'];
$file = $xml_info['xml_type'];
Expand Down
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14002,21 +14002,6 @@ parameters:
count: 1
path: app/cdash/include/ctestparser.php

-
message: "#^Parameter \\#1 \\$stream of function feof expects resource, mixed given\\.$#"
count: 1
path: app/cdash/include/ctestparser.php

-
message: "#^Parameter \\#1 \\$stream of function fread expects resource, mixed given\\.$#"
count: 2
path: app/cdash/include/ctestparser.php

-
message: "#^Parameter \\#1 \\$stream of function rewind expects resource, mixed given\\.$#"
count: 1
path: app/cdash/include/ctestparser.php

-
message: "#^Parameter \\#2 \\$data of function xml_parse expects string, string\\|false given\\.$#"
count: 2
Expand Down
Loading