mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-55314 mod_lti: Several fixes to lti_load_cartridge
* Fixed XML loading when there is an error * Fixed exception thrown by lti_load_cartridge * By default, don't allow LTI mod generator to use a toolurl as that results in a cURL call.
This commit is contained in:
parent
90a8bdbfc0
commit
123cc912ec
@ -2700,24 +2700,32 @@ function lti_load_tool_from_cartridge($url, $lti) {
|
||||
function lti_load_cartridge($url, $map, $propertiesmap = array()) {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir. "/filelib.php");
|
||||
// TODO MDL-46023 Replace this code with a call to the new library.
|
||||
$origentity = libxml_disable_entity_loader(true);
|
||||
|
||||
$curl = new curl();
|
||||
$response = $curl->get($url);
|
||||
|
||||
// TODO MDL-46023 Replace this code with a call to the new library.
|
||||
$origerrors = libxml_use_internal_errors(true);
|
||||
$origentity = libxml_disable_entity_loader(true);
|
||||
libxml_clear_errors();
|
||||
|
||||
$document = new DOMDocument();
|
||||
@$document->loadXML($response, LIBXML_DTDLOAD | LIBXML_DTDATTR);
|
||||
|
||||
$cartridge = new DomXpath($document);
|
||||
|
||||
$errors = libxml_get_errors();
|
||||
|
||||
libxml_clear_errors();
|
||||
libxml_use_internal_errors($origerrors);
|
||||
libxml_disable_entity_loader($origentity);
|
||||
|
||||
if (count($errors) > 0) {
|
||||
$message = 'Failed to load cartridge.';
|
||||
foreach ($errors as $error) {
|
||||
$message .= "\n" . trim($error->message, "\n\r\t .") . " at line " . $error->line;
|
||||
}
|
||||
throw new moodle_exception($message);
|
||||
throw new moodle_exception('errorreadingfile', '', '', $url, $message);
|
||||
}
|
||||
|
||||
$toolinfo = array();
|
||||
@ -2735,7 +2743,7 @@ function lti_load_cartridge($url, $map, $propertiesmap = array()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
libxml_disable_entity_loader($origentity);
|
||||
|
||||
return $toolinfo;
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,8 @@ class mod_lti_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// Setup test data.
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->lti = $this->getDataGenerator()->create_module('lti', array('course' => $this->course->id));
|
||||
$this->lti = $this->getDataGenerator()->create_module('lti',
|
||||
array('course' => $this->course->id, 'toolurl' => 'http://localhost/not/real/tool.php'));
|
||||
$this->context = context_module::instance($this->lti->cmid);
|
||||
$this->cm = get_coursemodule_from_instance('lti', $this->lti->id);
|
||||
|
||||
|
@ -41,7 +41,7 @@ class mod_lti_generator extends testing_module_generator {
|
||||
$record = (object) (array) $record;
|
||||
|
||||
if (!isset($record->toolurl)) {
|
||||
$record->toolurl = 'http://www.imsglobal.org/developers/LTI/test/v1p1/tool.php';
|
||||
$record->toolurl = '';
|
||||
}
|
||||
if (!isset($record->resourcekey)) {
|
||||
$record->resourcekey = '12345';
|
||||
|
Loading…
x
Reference in New Issue
Block a user