From af290059d10319e76d1e7d78b592cab99c26d91a Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 22 May 2020 11:02:56 +0200 Subject: Process session filters through Slim controllers Including: - visibility - links per page - untagged only --- tests/security/SessionManagerTest.php | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'tests/security/SessionManagerTest.php') diff --git a/tests/security/SessionManagerTest.php b/tests/security/SessionManagerTest.php index f264505e..d9db775e 100644 --- a/tests/security/SessionManagerTest.php +++ b/tests/security/SessionManagerTest.php @@ -269,4 +269,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); + } } -- cgit v1.2.3 From c4ad3d4f061d05a01db25aa54dda830ba776792d Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 7 Jul 2020 10:15:56 +0200 Subject: Process Shaarli install through Slim controller --- tests/security/SessionManagerTest.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'tests/security/SessionManagerTest.php') diff --git a/tests/security/SessionManagerTest.php b/tests/security/SessionManagerTest.php index d9db775e..60695dcf 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)); -- cgit v1.2.3 From 63b0059ed55dceaa58396b7baeb2b490b57ce9cc Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 31 Aug 2020 13:58:09 +0200 Subject: Fix broken route to filter not tagged bookmarks Also display the filter for visitors. Fixes #1529 --- tests/security/SessionManagerTest.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'tests/security/SessionManagerTest.php') diff --git a/tests/security/SessionManagerTest.php b/tests/security/SessionManagerTest.php index 60695dcf..11a59f9c 100644 --- a/tests/security/SessionManagerTest.php +++ b/tests/security/SessionManagerTest.php @@ -207,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']); } /** -- cgit v1.2.3 From 8f60e1206e45e67c96a7630d4ff94e72fe875f09 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 26 Sep 2020 15:08:39 +0200 Subject: Comply with PHPUnit V8: setup/teardown functions must return void --- tests/security/SessionManagerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/security/SessionManagerTest.php') diff --git a/tests/security/SessionManagerTest.php b/tests/security/SessionManagerTest.php index 11a59f9c..27e3b1a9 100644 --- a/tests/security/SessionManagerTest.php +++ b/tests/security/SessionManagerTest.php @@ -24,7 +24,7 @@ class SessionManagerTest extends TestCase /** * Assign reference data */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { self::$sidHashes = \ReferenceSessionIdHashes::getHashes(); } @@ -32,7 +32,7 @@ class SessionManagerTest extends TestCase /** * Initialize or reset test resources */ - public function setUp() + protected function setUp(): void { $this->conf = new \FakeConfigManager([ 'credentials.login' => 'johndoe', -- cgit v1.2.3 From a5a9cf23acd1248585173aa32757d9720b5f2d62 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 29 Sep 2020 14:41:40 +0200 Subject: Compatibility with PHPUnit 9 --- tests/security/SessionManagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/security/SessionManagerTest.php') diff --git a/tests/security/SessionManagerTest.php b/tests/security/SessionManagerTest.php index 27e3b1a9..3f9c3ef5 100644 --- a/tests/security/SessionManagerTest.php +++ b/tests/security/SessionManagerTest.php @@ -2,7 +2,7 @@ namespace Shaarli\Security; -use PHPUnit\Framework\TestCase; +use Shaarli\TestCase; /** * Test coverage for SessionManager -- cgit v1.2.3