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/LoginManagerTest.php | 30 ++++++++++++++++++------------ tests/security/SessionManagerTest.php | 14 +++++--------- 2 files changed, 23 insertions(+), 21 deletions(-) (limited to 'tests/security') diff --git a/tests/security/LoginManagerTest.php b/tests/security/LoginManagerTest.php index 8fd1698c..f242be09 100644 --- a/tests/security/LoginManagerTest.php +++ b/tests/security/LoginManagerTest.php @@ -1,7 +1,6 @@ cookie = []; $this->session = []; - $this->sessionManager = new SessionManager($this->session, $this->configManager); - $this->loginManager = new LoginManager($this->configManager, $this->sessionManager); + $this->cookieManager = $this->createMock(CookieManager::class); + $this->cookieManager->method('getCookieParameter')->willReturnCallback(function (string $key) { + return $this->cookie[$key] ?? null; + }); + $this->sessionManager = new SessionManager($this->session, $this->configManager, 'session_path'); + $this->loginManager = new LoginManager($this->configManager, $this->sessionManager, $this->cookieManager); $this->server['REMOTE_ADDR'] = $this->ipAddr; } @@ -193,8 +199,8 @@ class LoginManagerTest extends TestCase $configManager = new \FakeConfigManager([ 'resource.ban_file' => $this->banFile, ]); - $loginManager = new LoginManager($configManager, null); - $loginManager->checkLoginState([], ''); + $loginManager = new LoginManager($configManager, null, $this->cookieManager); + $loginManager->checkLoginState(''); $this->assertFalse($loginManager->isLoggedIn()); } @@ -210,9 +216,9 @@ class LoginManagerTest extends TestCase 'expires_on' => time() + 100, ]; $this->loginManager->generateStaySignedInToken($this->clientIpAddress); - $this->cookie[LoginManager::$STAY_SIGNED_IN_COOKIE] = 'nope'; + $this->cookie[CookieManager::STAY_SIGNED_IN] = 'nope'; - $this->loginManager->checkLoginState($this->cookie, $this->clientIpAddress); + $this->loginManager->checkLoginState($this->clientIpAddress); $this->assertTrue($this->loginManager->isLoggedIn()); $this->assertTrue(empty($this->session['username'])); @@ -224,9 +230,9 @@ class LoginManagerTest extends TestCase public function testCheckLoginStateStaySignedInWithValidToken() { $this->loginManager->generateStaySignedInToken($this->clientIpAddress); - $this->cookie[LoginManager::$STAY_SIGNED_IN_COOKIE] = $this->loginManager->getStaySignedInToken(); + $this->cookie[CookieManager::STAY_SIGNED_IN] = $this->loginManager->getStaySignedInToken(); - $this->loginManager->checkLoginState($this->cookie, $this->clientIpAddress); + $this->loginManager->checkLoginState($this->clientIpAddress); $this->assertTrue($this->loginManager->isLoggedIn()); $this->assertEquals($this->login, $this->session['username']); @@ -241,7 +247,7 @@ class LoginManagerTest extends TestCase $this->loginManager->generateStaySignedInToken($this->clientIpAddress); $this->session['expires_on'] = time() - 100; - $this->loginManager->checkLoginState($this->cookie, $this->clientIpAddress); + $this->loginManager->checkLoginState($this->clientIpAddress); $this->assertFalse($this->loginManager->isLoggedIn()); } @@ -253,7 +259,7 @@ class LoginManagerTest extends TestCase { $this->loginManager->generateStaySignedInToken($this->clientIpAddress); - $this->loginManager->checkLoginState($this->cookie, '10.7.157.98'); + $this->loginManager->checkLoginState('10.7.157.98'); $this->assertFalse($this->loginManager->isLoggedIn()); } 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