diff --git a/roles/web-app-moodle/files/build/config.php b/roles/web-app-moodle/files/build/config.php index 3ac7ee66a2..a2c2bb9305 100644 --- a/roles/web-app-moodle/files/build/config.php +++ b/roles/web-app-moodle/files/build/config.php @@ -1,5 +1,4 @@ admin = 'admin'; $CFG->directorypermissions = 02770; $CFG->routerconfigured = true; +$CFG->session_handler_class = '\core\session\database'; + $CFG->reverseproxy = moodle_env_bool('MOODLE_REVERSEPROXY'); $CFG->sslproxy = moodle_env_bool('MOODLE_SSLPROXY'); diff --git a/tests/unit/php/roles/web-app-moodle/files/build/ConfigTest.php b/tests/unit/php/roles/web-app-moodle/files/build/ConfigTest.php new file mode 100644 index 0000000000..74c5fca9b8 --- /dev/null +++ b/tests/unit/php/roles/web-app-moodle/files/build/ConfigTest.php @@ -0,0 +1,61 @@ + 'mariadb', + 'MOODLE_DB_HOST' => 'mariadb', + 'MOODLE_DB_NAME' => 'moodle', + 'MOODLE_DB_USER' => 'moodle', + 'MOODLE_DB_PASS' => 'secret', + 'MOODLE_DB_PREFIX' => 'mdl_', + 'MOODLE_DB_PORT' => '3306', + 'MOODLE_WWWROOT' => 'https://academy.example.test', + 'MOODLE_DATAROOT' => '/var/www/moodledata', + 'MOODLE_LOCALCACHEDIR' => '/var/cache/moodle', + 'MOODLE_REVERSEPROXY' => 'false', + 'MOODLE_SSLPROXY' => 'true', + 'MOODLE_EGRESS_BLOCKED_HOSTS' => '10.0.0.0/8', + 'MOODLE_EGRESS_ALLOWED_PORTS' => '443', + 'MOODLE_INTERNAL_HOST' => 'moodle', + 'MOODLE_OBJECTFS_ENABLED' => 'false', + ]; + + private string $root; + + protected function setUp(): void + { + $this->root = sys_get_temp_dir() . '/mdlconfig' . bin2hex(random_bytes(6)); + mkdir($this->root . '/lib', 0700, true); + copy(dirname(__DIR__, 7) . '/roles/web-app-moodle/files/build/config.php', $this->root . '/config.php'); + file_put_contents($this->root . '/lib/setup.php', "root . '/lib/setup.php'); + unlink($this->root . '/config.php'); + rmdir($this->root . '/lib'); + rmdir($this->root); + } + + public function testEveryReplicaReadsSessionsFromTheSharedDatabase(): void + { + $process = proc_open( + [PHP_BINARY, '-r', 'require $argv[1]; echo $CFG->session_handler_class ?? "";', $this->root . '/config.php'], + [1 => ['pipe', 'w'], 2 => ['redirect', 1]], + $pipes, + null, + self::ENV + ['PATH' => (string) getenv('PATH')] + ); + $output = (string) stream_get_contents($pipes[1]); + fclose($pipes[1]); + + $this->assertSame(0, proc_close($process), $output); + $this->assertSame('\core\session\database', $output); + } +}