-
Notifications
You must be signed in to change notification settings - Fork 76
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
Add support for validation of XML submission files #2437
base: master
Are you sure you want to change the base?
Changes from all commits
2a23bce
1e536cf
cd8c554
63bef62
4602d25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Exceptions; | ||
|
||
use Exception; | ||
use RuntimeException; | ||
|
||
class CDashXMLValidationException extends RuntimeException | ||
{ | ||
/** | ||
* @param array<int,string> $message | ||
*/ | ||
public function __construct(array $message = [], int $code = 0, Exception $previous = null) | ||
{ | ||
$encoded_msg = json_encode($message); | ||
$encoded_msg = $encoded_msg===false ? "" : $encoded_msg; | ||
parent::__construct($encoded_msg, $code, $previous); | ||
} | ||
|
||
/** | ||
* @return array<int,string> | ||
*/ | ||
public function getDecodedMessage(bool $assoc = false): array | ||
{ | ||
$decoded_msg = json_decode($this->getMessage(), $assoc); | ||
if (!isset($decoded_msg) || is_bool($decoded_msg)) { | ||
$decoded_msg = ["An XML validation error has occurred!"]; | ||
} | ||
return $decoded_msg; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Support\Facades\Storage; | ||
use App\Utils\SubmissionUtils; | ||
use App\Exceptions\CDashXMLValidationException; | ||
|
||
class CDashParseException extends RuntimeException | ||
{ | ||
|
@@ -148,7 +149,7 @@ function parse_put_submission($filehandler, $projectid, $expected_md5) | |
} | ||
|
||
/** Main function to parse the incoming xml from ctest */ | ||
function ctest_parse($filehandle, $projectid, $expected_md5 = '') | ||
function ctest_parse($filehandle, string $filename, $projectid, $expected_md5 = '') | ||
{ | ||
// Check if this is a new style PUT submission. | ||
try { | ||
|
@@ -168,10 +169,32 @@ function ctest_parse($filehandle, $projectid, $expected_md5 = '') | |
} | ||
|
||
// Figure out what type of XML file this is. | ||
$xml_info = SubmissionUtils::get_xml_type($filehandle); | ||
try { | ||
$xml_info = SubmissionUtils::get_xml_type($filehandle, $filename); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that the path passed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sbelsk, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. Might still be worth changing it for the logging in lines 191-193 |
||
} catch (CDashXMLValidationException $e) { | ||
foreach ($e->getDecodedMessage() as $error) { | ||
Log::error($error); | ||
} | ||
return false; | ||
} | ||
$filehandle = $xml_info['file_handle']; | ||
$handler_ref = $xml_info['xml_handler']; | ||
$file = $xml_info['xml_type']; | ||
$schema_file = $xml_info['xml_schema']; | ||
|
||
// If validation is enabled and if this file has a corresponding schema, validate it | ||
\Log::critical(((bool) config('cdash.validate_xml_submissions'))); | ||
\Log::critical($schema_file); | ||
if (((bool) config('cdash.validate_xml_submissions')) === true && isset($schema_file)) { | ||
try { | ||
SubmissionUtils::validate_xml($filename, $schema_file); | ||
} catch (CDashXMLValidationException $e) { | ||
foreach ($e->getDecodedMessage() as $error) { | ||
Log::error("Validating $filename: ".$error); | ||
} | ||
abort(400, "Xml validation failed: rejected file $filename"); | ||
} | ||
} | ||
|
||
$handler = isset($handler_ref) ? new $handler_ref($projectid) : null; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is what's causing the local testing of mine to fail. If I remove the
LIBXML_ERR_ERROR
part of the check, the submissions are successful.My submission is from CTest
3.22.1
while the testing is3.25.1
. Otherwise the configuration files seem to be the same structure. If I submit via CTest, it fails, but copying the content over to the Docker machine and running the manual validation passes.@williamjallen, I'm happy to demonstrate if you'd like to see my setup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unable to replicate the issue above on further testing. I'm not quite sure what happenedForgot to reintroduce the environment variable, failures are still around. Sorry!