MDL-80946 quizaccess_seb: Remove invalidkeys text if not using SEB.

This commit is contained in:
Michael Kotlyar
2024-09-05 09:06:52 +01:00
parent d14f5eaa6c
commit c3d725a3cd
2 changed files with 31 additions and 2 deletions
+5 -2
View File
@@ -376,8 +376,11 @@ class quizaccess_seb extends access_rule_base {
*/
private function get_invalid_key_error_message() : string {
// Return error message with download link and links to get the seb config.
return get_string('invalidkeys', 'quizaccess_seb')
. $this->display_buttons($this->get_action_buttons());
if ($this->accessmanager->is_using_seb()) {
return get_string('invalidkeys', 'quizaccess_seb')
. $this->display_buttons($this->get_action_buttons());
}
return $this->display_buttons($this->get_action_buttons());
}
/**
@@ -370,6 +370,7 @@ class rule_test extends \advanced_testcase {
// Set up dummy request.
$FULLME = 'https://example.com/moodle/mod/quiz/attempt.php?attemptid=123&page=4';
$_SERVER['HTTP_USER_AGENT'] = 'SEB';
$_SERVER['HTTP_X_SAFEEXAMBROWSER_CONFIGKEYHASH'] = 'Broken config key';
$user = $this->getDataGenerator()->create_user();
@@ -378,6 +379,28 @@ class rule_test extends \advanced_testcase {
$this->check_invalid_config_key();
}
/**
* Test access prevented if config key is invalid when not using the Safe Exam Browser.
*/
public function test_access_prevented_if_config_key_invalid_not_using_seb(): void {
global $FULLME;
$this->setAdminUser();
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
// Set up dummy request.
$FULLME = 'https://example.com/moodle/mod/quiz/attempt.php?attemptid=123&page=4';
$_SERVER['HTTP_X_SAFEEXAMBROWSER_CONFIGKEYHASH'] = 'Broken config key';
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
$errormsg = $this->make_rule()->prevent_access();
$this->assertNotEmpty($errormsg);
$this->assertStringNotContainsString("The Safe Exam Browser keys could not be validated. "
. "Check that you're using Safe Exam Browser with the correct configuration file.", $errormsg);
}
/**
* Test access prevented if config keys is invalid and using uploaded config.
*/
@@ -396,6 +419,7 @@ class rule_test extends \advanced_testcase {
// Set up dummy request.
$FULLME = 'https://example.com/moodle/mod/quiz/attempt.php?attemptid=123&page=4';
$_SERVER['HTTP_USER_AGENT'] = 'SEB';
$_SERVER['HTTP_X_SAFEEXAMBROWSER_CONFIGKEYHASH'] = 'Broken config key';
$user = $this->getDataGenerator()->create_user();
@@ -421,6 +445,7 @@ class rule_test extends \advanced_testcase {
// Set up dummy request.
$FULLME = 'https://example.com/moodle/mod/quiz/attempt.php?attemptid=123&page=4';
$_SERVER['HTTP_USER_AGENT'] = 'SEB';
$_SERVER['HTTP_X_SAFEEXAMBROWSER_CONFIGKEYHASH'] = 'Broken config key';
$user = $this->getDataGenerator()->create_user();
@@ -676,6 +701,7 @@ class rule_test extends \advanced_testcase {
// Set up dummy request.
$FULLME = 'https://example.com/moodle/mod/quiz/attempt.php?attemptid=123&page=4';
$expectedhash = hash('sha256', $FULLME . $quizsettings->get_config_key());
$_SERVER['HTTP_USER_AGENT'] = 'SEB';
$_SERVER['HTTP_X_SAFEEXAMBROWSER_CONFIGKEYHASH'] = $expectedhash;
// Set up broken browser key.