mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-28 13:57:43 +00:00
Merge pull request #2386 from infinito-nexus/fix/web-app-moodle/swarm-database-sessions
fix(web-app-moodle): keep sessions in the database so swarm replicas share them
This commit is contained in:
2 files changed
+63
-1
No files matched your search
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
// nocheck: mirrored-unit-test - env-driven Moodle configuration; the file assigns globals and calls Moodle's setup.php, it exposes no unit
|
||||
// Env-driven Moodle config. Single source of truth for defaults is
|
||||
// env.j2 (rendered by Ansible into .env/env). All MOODLE_* env vars
|
||||
// MUST be set; missing values fail fast.
|
||||
@@ -46,6 +45,8 @@ $CFG->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');
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class ConfigTest extends TestCase
|
||||
{
|
||||
private const ENV = [
|
||||
'MOODLE_DB_TYPE' => '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', "<?php\n");
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unlink($this->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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user