X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fsecurity%2FSessionManagerTest.php;h=3f9c3ef59fd2138faeb95fe07b715890a0f09ab4;hb=a5a9cf23acd1248585173aa32757d9720b5f2d62;hp=7961e7710dc3581a2d7f63659fc6f2aa500c25b2;hpb=067c2dd8f5f6eb6cc808ddc4bd30aec104caf73d;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/security/SessionManagerTest.php b/tests/security/SessionManagerTest.php index 7961e771..3f9c3ef5 100644 --- a/tests/security/SessionManagerTest.php +++ b/tests/security/SessionManagerTest.php @@ -1,12 +1,8 @@ conf = new FakeConfigManager([ + $this->conf = new \FakeConfigManager([ 'credentials.login' => 'johndoe', 'credentials.salt' => 'salt', 'security.session_protection_disabled' => false, ]); $this->session = []; - $this->sessionManager = new SessionManager($this->session, $this->conf); + $this->sessionManager = new SessionManager($this->session, $this->conf, 'session_path'); } /** @@ -69,7 +65,7 @@ class SessionManagerTest extends TestCase $token => 1, ], ]; - $sessionManager = new SessionManager($session, $this->conf); + $sessionManager = new SessionManager($session, $this->conf, 'session_path'); // check and destroy the token $this->assertTrue($sessionManager->checkToken($token)); @@ -211,15 +207,16 @@ class SessionManagerTest extends TestCase 'expires_on' => time() + 1000, 'username' => 'johndoe', 'visibility' => 'public', - 'untaggedonly' => false, + 'untaggedonly' => true, ]; $this->sessionManager->logout(); - $this->assertFalse(isset($this->session['ip'])); - $this->assertFalse(isset($this->session['expires_on'])); - $this->assertFalse(isset($this->session['username'])); - $this->assertFalse(isset($this->session['visibility'])); - $this->assertFalse(isset($this->session['untaggedonly'])); + $this->assertArrayNotHasKey('ip', $this->session); + $this->assertArrayNotHasKey('expires_on', $this->session); + $this->assertArrayNotHasKey('username', $this->session); + $this->assertArrayNotHasKey('visibility', $this->session); + $this->assertArrayHasKey('untaggedonly', $this->session); + $this->assertTrue($this->session['untaggedonly']); } /** @@ -269,4 +266,61 @@ class SessionManagerTest extends TestCase $this->session['ip'] = 'ip_id_one'; $this->assertTrue($this->sessionManager->hasClientIpChanged('ip_id_two')); } + + /** + * Test creating an entry in the session array + */ + public function testSetSessionParameterCreate(): void + { + $this->sessionManager->setSessionParameter('abc', 'def'); + + static::assertSame('def', $this->session['abc']); + } + + /** + * Test updating an entry in the session array + */ + public function testSetSessionParameterUpdate(): void + { + $this->session['abc'] = 'ghi'; + + $this->sessionManager->setSessionParameter('abc', 'def'); + + static::assertSame('def', $this->session['abc']); + } + + /** + * Test updating an entry in the session array with null value + */ + public function testSetSessionParameterUpdateNull(): void + { + $this->session['abc'] = 'ghi'; + + $this->sessionManager->setSessionParameter('abc', null); + + static::assertArrayHasKey('abc', $this->session); + static::assertNull($this->session['abc']); + } + + /** + * Test deleting an existing entry in the session array + */ + public function testDeleteSessionParameter(): void + { + $this->session['abc'] = 'def'; + + $this->sessionManager->deleteSessionParameter('abc'); + + static::assertArrayNotHasKey('abc', $this->session); + } + + /** + * Test deleting a non existent entry in the session array + */ + public function testDeleteSessionParameterNotExisting(): void + { + $this->sessionManager->deleteSessionParameter('abc'); + + static::assertArrayNotHasKey('abc', $this->session); + } }