mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-10-28 14:08:45 -04:00
Slightly more robust SessionTest and cleanup (#9376)
* Slightly more robust SessionTest and cleanup Improvement of #9311 I noticed that my `/tmp` directory got filled up with random `sess_*` files and empty `frss_test_sessions_*` directories after repeatedly running PHPUnit, which means there was no proper cleanup being done in the tests. See the first commit for changes, since I also moved the test to a more appropriate directory name (alongside `tests/lib/Minz`, `tests/app/Minz` was newly added in #9311). Before the PR: * Check output of `ls -lah /tmp/{frss_test_sessions_*,sess_*}; rm -r /tmp/{frss_test_sessions_*,sess_*}` to confirm there are initially no temporary files existing. * Run `composer run phpunit`. * Check output of the previous command again to confirm there is a new `sess_*` file and an empty `frss_test_sessions_*` directory. After the PR: * Check output of `ls -lah /tmp/{frss_test_sessions_*,sess_*}; rm -r /tmp/{frss_test_sessions_*,sess_*}` to confirm that no temporary files exist initially. * Run `composer run phpunit`. * Check output of the previous command again to confirm there are no temporary files, since they are now being cleaned up correctly. * Move SessionTest from tests/app/Minz to tests/lib/Minz
This commit is contained in:
1 parent
e247edb1fb
commit
01afc061d7
2 files changed
+47
-38
No files matched your search
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
final class SessionTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
private string $originalSavePath;
|
||||
|
||||
#[\Override]
|
||||
protected function setUp(): void {
|
||||
$this->originalSavePath = (string)ini_get('session.save_path');
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected function tearDown(): void {
|
||||
ini_set('session.save_path', $this->originalSavePath);
|
||||
}
|
||||
|
||||
public function testRegenerateIDOnHealthyStorage(): void {
|
||||
$previous = $_SESSION ?? [];
|
||||
|
||||
Minz_Session::regenerateID('FreshRSS');
|
||||
|
||||
$_SESSION['probe'] = 'ok';
|
||||
self::assertSame('ok', $_SESSION['probe']);
|
||||
$_SESSION = $previous;
|
||||
session_write_close();
|
||||
}
|
||||
|
||||
public function testRegenerateIDOnBrokenStorage(): void {
|
||||
$save_path = sys_get_temp_dir() . '/frss_test_sessions_' . bin2hex(random_bytes(4));
|
||||
self::assertNotFalse(mkdir($save_path, 0700));
|
||||
$broken_path = $save_path . '/missing_subdir';
|
||||
ini_set('session.save_path', $broken_path);
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
Minz_Session::regenerateID('FreshRSS');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
final class SessionTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
private string $originalSavePath = '';
|
||||
private string $testSavePath = '';
|
||||
|
||||
#[\Override]
|
||||
protected function setUp(): void {
|
||||
$this->originalSavePath = (string)ini_get('session.save_path');
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected function tearDown(): void {
|
||||
if (is_dir($this->testSavePath)) {
|
||||
rmdir($this->testSavePath);
|
||||
}
|
||||
|
||||
ini_set('session.save_path', $this->originalSavePath);
|
||||
}
|
||||
|
||||
public function testRegenerateIDOnHealthyStorage(): void {
|
||||
$save_path = session_save_path() ?: sys_get_temp_dir();
|
||||
Minz_Session::init('FreshRSS', volatile: false);
|
||||
self::assertTrue(file_exists($save_path . '/sess_' . session_id()));
|
||||
$previous_id = session_id();
|
||||
Minz_Session::_param('probe', 'ok');
|
||||
Minz_Session::regenerateID('FreshRSS');
|
||||
self::assertNotSame($previous_id, session_id());
|
||||
self::assertFalse(file_exists($save_path . '/sess_' . $previous_id));
|
||||
self::assertTrue(file_exists($save_path . '/sess_' . session_id()));
|
||||
self::assertSame('ok', Minz_Session::paramString('probe'));
|
||||
session_unset();
|
||||
session_write_close();
|
||||
unlink($save_path . '/sess_' . session_id());
|
||||
}
|
||||
|
||||
public function testRegenerateIDOnBrokenStorage(): void {
|
||||
$this->testSavePath = sys_get_temp_dir() . '/frss_test_sessions_' . bin2hex(random_bytes(4));
|
||||
self::assertNotFalse(mkdir($this->testSavePath, 0700));
|
||||
ini_set('session.save_path', $this->testSavePath . '/missing_subdir');
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
Minz_Session::regenerateID('FreshRSS');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user