]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/Model/User/CookieTest.php
Merge pull request #8277 from MrPetovan/task/8251-use-about-for-pdesc
[friendica.git] / tests / src / Model / User / CookieTest.php
index bff1698e8375d7215199114a5c16f43cd5007707..cac278076cc1cd4c538bce3f0dcc6ad9aaec60a5 100644 (file)
@@ -1,8 +1,28 @@
 <?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Testsrc\Model\User;
 
-use Friendica\Core\Config\Configuration;
+use Friendica\App\BaseURL;
+use Friendica\Core\Config\IConfig;
 use Friendica\Model\User\Cookie;
 use Friendica\Test\DatabaseTest;
 use Friendica\Test\Util\StaticCookie;
@@ -10,8 +30,10 @@ use Mockery\MockInterface;
 
 class CookieTest extends DatabaseTest
 {
-       /** @var MockInterface|Configuration */
+       /** @var MockInterface|IConfig */
        private $config;
+       /** @var MockInterface|BaseURL */
+       private $baseUrl;
 
        protected function setUp()
        {
@@ -19,7 +41,8 @@ class CookieTest extends DatabaseTest
 
                parent::setUp();
 
-               $this->config = \Mockery::mock(Configuration::class);
+               $this->config = \Mockery::mock(IConfig::class);
+               $this->baseUrl = \Mockery::mock(BaseURL::class);
        }
 
        protected function tearDown()
@@ -32,11 +55,11 @@ class CookieTest extends DatabaseTest
         */
        public function testInstance()
        {
-               $this->config->shouldReceive('get')->with('system', 'ssl_policy')->andReturn(1)->once();
+               $this->baseUrl->shouldReceive('getSSLPolicy')->andReturn(true)->once();
                $this->config->shouldReceive('get')->with('system', 'site_prvkey')->andReturn('1235')->once();
                $this->config->shouldReceive('get')->with('system', 'auth_cookie_lifetime', Cookie::DEFAULT_EXPIRE)->andReturn('7')->once();
 
-               $cookie = new Cookie($this->config, []);
+               $cookie = new Cookie($this->config, $this->baseUrl);
                $this->assertInstanceOf(Cookie::class, $cookie);
        }
 
@@ -96,11 +119,11 @@ class CookieTest extends DatabaseTest
         */
        public function testGet(array $cookieData, bool $hasValues, $uid, $hash, $ip)
        {
-               $this->config->shouldReceive('get')->with('system', 'ssl_policy')->andReturn(1)->once();
+               $this->baseUrl->shouldReceive('getSSLPolicy')->andReturn(true)->once();
                $this->config->shouldReceive('get')->with('system', 'site_prvkey')->andReturn('1235')->once();
                $this->config->shouldReceive('get')->with('system', 'auth_cookie_lifetime', Cookie::DEFAULT_EXPIRE)->andReturn('7')->once();
 
-               $cookie = new Cookie($this->config, [], $cookieData);
+               $cookie = new Cookie($this->config, $this->baseUrl, [], $cookieData);
                $this->assertInstanceOf(Cookie::class, $cookie);
 
                $assertData = $cookie->getData();
@@ -164,11 +187,11 @@ class CookieTest extends DatabaseTest
         */
        public function testCheck(string $serverPrivateKey, string $userPrivateKey, string $password, string $assertHash, bool $assertTrue)
        {
-               $this->config->shouldReceive('get')->with('system', 'ssl_policy')->andReturn(1)->once();
+               $this->baseUrl->shouldReceive('getSSLPolicy')->andReturn(true)->once();
                $this->config->shouldReceive('get')->with('system', 'site_prvkey')->andReturn($serverPrivateKey)->once();
                $this->config->shouldReceive('get')->with('system', 'auth_cookie_lifetime', Cookie::DEFAULT_EXPIRE)->andReturn('7')->once();
 
-               $cookie = new Cookie($this->config, []);
+               $cookie = new Cookie($this->config, $this->baseUrl);
                $this->assertInstanceOf(Cookie::class, $cookie);
 
                $this->assertEquals($assertTrue, $cookie->check($assertHash, $password, $userPrivateKey));
@@ -247,11 +270,11 @@ class CookieTest extends DatabaseTest
         */
        public function testSet($serverKey, $uid, $password, $privateKey, $assertHash, $remoteIp, $serverArray, $lifetime)
        {
-               $this->config->shouldReceive('get')->with('system', 'ssl_policy')->andReturn(1)->once();
+               $this->baseUrl->shouldReceive('getSSLPolicy')->andReturn(true)->once();
                $this->config->shouldReceive('get')->with('system', 'site_prvkey')->andReturn($serverKey)->once();
                $this->config->shouldReceive('get')->with('system', 'auth_cookie_lifetime', Cookie::DEFAULT_EXPIRE)->andReturn(Cookie::DEFAULT_EXPIRE)->once();
 
-               $cookie = new StaticCookie($this->config, $serverArray);
+               $cookie = new StaticCookie($this->config, $this->baseUrl, $serverArray);
                $this->assertInstanceOf(Cookie::class, $cookie);
 
                $cookie->set($uid, $password, $privateKey, $lifetime);
@@ -266,11 +289,11 @@ class CookieTest extends DatabaseTest
         */
        public function testDoubleSet($serverKey, $uid, $password, $privateKey, $assertHash, $remoteIp, $serverArray, $lifetime)
        {
-               $this->config->shouldReceive('get')->with('system', 'ssl_policy')->andReturn(1)->once();
+               $this->baseUrl->shouldReceive('getSSLPolicy')->andReturn(true)->once();
                $this->config->shouldReceive('get')->with('system', 'site_prvkey')->andReturn($serverKey)->once();
                $this->config->shouldReceive('get')->with('system', 'auth_cookie_lifetime', Cookie::DEFAULT_EXPIRE)->andReturn(Cookie::DEFAULT_EXPIRE)->once();
 
-               $cookie = new StaticCookie($this->config, $serverArray);
+               $cookie = new StaticCookie($this->config, $this->baseUrl, $serverArray);
                $this->assertInstanceOf(Cookie::class, $cookie);
 
                // Invalid set, should get overwritten
@@ -290,11 +313,11 @@ class CookieTest extends DatabaseTest
                        Cookie::NAME => 'test'
                ];
 
-               $this->config->shouldReceive('get')->with('system', 'ssl_policy')->andReturn(1)->once();
+               $this->baseUrl->shouldReceive('getSSLPolicy')->andReturn(true)->once();
                $this->config->shouldReceive('get')->with('system', 'site_prvkey')->andReturn(24)->once();
                $this->config->shouldReceive('get')->with('system', 'auth_cookie_lifetime', Cookie::DEFAULT_EXPIRE)->andReturn(Cookie::DEFAULT_EXPIRE)->once();
 
-               $cookie = new StaticCookie($this->config, []);
+               $cookie = new StaticCookie($this->config, $this->baseUrl);
                $this->assertInstanceOf(Cookie::class, $cookie);
 
                $this->assertEquals('test', StaticCookie::$_COOKIE[Cookie::NAME]);