MDL-68696 sessions: Fixed redis session handler for readonly

In 39770792ca read-only sessions were allowed.
In the redis case, as called from the mobile application,
this can lead to returning 'false' for session rather than ''.
This commit is contained in:
Don Bowman 2020-05-14 08:38:20 -04:00
parent 206e179df5
commit cf7b00b8cf
No known key found for this signature in database
GPG key ID: D21D0E75160D9894
2 changed files with 12 additions and 2 deletions

View file

@ -259,8 +259,10 @@ class redis extends handler {
$this->lock_session($id); $this->lock_session($id);
} }
$sessiondata = $this->connection->get($id); $sessiondata = $this->connection->get($id);
if ($sessiondata === false && $this->requires_write_lock()) { if ($sessiondata === false) {
$this->unlock_session($id); if ($this->requires_write_lock()) {
$this->unlock_session($id);
}
return ''; return '';
} }
$this->connection->expire($id, $this->timeout); $this->connection->expire($id, $this->timeout);

View file

@ -91,6 +91,14 @@ class core_session_redis_testcase extends advanced_testcase {
$this->redis->close(); $this->redis->close();
} }
public function test_normal_session_read_only() {
$sess = new \core\session\redis();
$sess->set_requires_write_lock(false);
$sess->init();
$this->assertSame('', $sess->handler_read('sess1'));
$this->assertTrue($sess->handler_close());
}
public function test_normal_session_start_stop_works() { public function test_normal_session_start_stop_works() {
$sess = new \core\session\redis(); $sess = new \core\session\redis();
$sess->init(); $sess->init();