This commit is contained in:
Ilya Tregubov 2023-09-01 10:29:41 +08:00
commit 9d4dba81b7
No known key found for this signature in database
GPG Key ID: 0F58186F748E55C1
2 changed files with 7 additions and 7 deletions

View File

@ -318,7 +318,7 @@ class external extends external_api {
$timenow = time();
if ($timenow - $last < $mintimereq) {
$minutes = $mintimereq / MINSECS;
throw new moodle_exception('autologinkeygenerationlockout', 'tool_mobile', $minutes);
throw new moodle_exception('autologinkeygenerationlockout', 'tool_mobile', '', $minutes);
}
set_user_preference('tool_mobile_autologin_request_last', $timenow, $USER);

View File

@ -414,18 +414,18 @@ class externallib_test extends externallib_advanced_testcase {
$result = external::get_autologin_key($token->privatetoken);
$result = external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
// Change min time between requests to 30 seconds.
set_config('autologinmintimebetweenreq', 30, 'tool_mobile');
// Change min time between requests to 3 minutes.
set_config('autologinmintimebetweenreq', 3 * MINSECS, 'tool_mobile');
// Mock a previous request, 60 seconds ago.
$mocktime = time() - MINSECS;
// Mock a previous request, 4 minutes ago.
$mocktime = time() - (4 * MINSECS);
set_user_preference('tool_mobile_autologin_request_last', $mocktime, $USER);
$result = external::get_autologin_key($token->privatetoken); // All good, we were expecint 30 seconds or more.
$result = external::get_autologin_key($token->privatetoken);
$result = external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
// We just requested one token, we must wait.
$this->expectException('moodle_exception');
$this->expectExceptionMessage(get_string('autologinkeygenerationlockout', 'tool_mobile'));
$this->expectExceptionMessage(get_string('autologinkeygenerationlockout', 'tool_mobile', 3));
$result = external::get_autologin_key($token->privatetoken);
}