MDL-76362 enrol_lti: Prevent calling to DataConnector with null keys

While it could have been fixed in DataConnector (3rd part lib), better
prevent in our code to call to it with null keys.

Covered by unit tests.
This commit is contained in:
Eloy Lafuente (stronk7) 2023-01-21 16:01:33 +01:00 committed by Andrew Nicols
parent e6dfa9ff3c
commit 03bc275093

View File

@ -88,16 +88,18 @@ class data_connector extends DataConnector {
global $DB;
$id = $consumer->getRecordId();
$key = $consumer->getKey();
$result = false;
if (!empty($id)) {
$result = $DB->get_record($this->consumertable, ['id' => $id]);
} else {
$key256 = DataConnector::getConsumerKey($consumer->getKey());
} else if (!empty($key)) {
$key256 = DataConnector::getConsumerKey($key);
$result = $DB->get_record($this->consumertable, ['consumerkey256' => $key256]);
}
if ($result) {
if (empty($key256) || empty($result->consumerkey) || ($consumer->getKey() === $result->consumerkey)) {
if (empty($key256) || empty($result->consumerkey) || ($key === $result->consumerkey)) {
$this->build_tool_consumer_object($result, $consumer);
return true;
}