Skip to content

Commit

Permalink
Merge branch 'MDL-73826_311' of https://github.com/stronk7/moodle int…
Browse files Browse the repository at this point in the history
…o MOODLE_311_STABLE
  • Loading branch information
junpataleta committed Feb 15, 2022
2 parents 6994e82 + ad1c072 commit ef6a2e5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/filelib.php
Expand Up @@ -3706,7 +3706,8 @@ protected function request($url, $options = array()) {
$this->reset_request_state_vars();

if ((defined('PHPUNIT_TEST') && PHPUNIT_TEST)) {
if ($mockresponse = array_pop(self::$mockresponses)) {
$mockresponse = array_pop(self::$mockresponses);
if ($mockresponse !== null) {
$this->info = [ 'http_code' => 200 ];
return $mockresponse;
}
Expand Down
7 changes: 7 additions & 0 deletions mod/lti/locallib.php
Expand Up @@ -4392,6 +4392,13 @@ function lti_load_cartridge($url, $map, $propertiesmap = array()) {
$curl = new curl();
$response = $curl->get($url);

// Got a completely empty response (real or error), cannot process this with
// DOMDocument::loadXML() because it errors with ValueError. So let's throw
// the moodle_exception before waiting to examine the errors later.
if (trim($response) === '') {
throw new moodle_exception('errorreadingfile', '', '', $url);
}

// TODO MDL-46023 Replace this code with a call to the new library.
$origerrors = libxml_use_internal_errors(true);
$origentity = lti_libxml_disable_entity_loader(true);
Expand Down
14 changes: 14 additions & 0 deletions mod/lti/tests/locallib_test.php
Expand Up @@ -1841,6 +1841,20 @@ public function lti_get_ims_role_provider() {
];
}

/**
* Verify that empty curl responses lead to the proper moodle_exception, not to XML ValueError.
*
* @covers ::lti_load_cartridge()
*/
public function test_empty_reponse_lti_load_cartridge() {
// Mock the curl response to empty string, this is hardly
// reproducible in real life (only Windows + GHA).
\curl::mock_response('');

$this->expectException(\moodle_exception::class);
lti_load_cartridge('http://example.com/mocked/empty/response', []);
}

/**
* Create an LTI Tool.
*
Expand Down

0 comments on commit ef6a2e5

Please sign in to comment.