Refactor BaseURL.php to UriInterface compatible class
- remove parts - added tests
This commit is contained in:
parent
08754b2bab
commit
45749c14be
3 changed files with 237 additions and 745 deletions
191
tests/src/App/BaseURLTest.php
Normal file
191
tests/src/App/BaseURLTest.php
Normal file
|
@ -0,0 +1,191 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @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\Test\src\App;
|
||||
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\Core\Config\Model\ReadOnlyFileConfig;
|
||||
use Friendica\Core\Config\ValueObject\Cache;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
class BaseURLTest extends MockedTest
|
||||
{
|
||||
public function dataSystemUrl(): array
|
||||
{
|
||||
return [
|
||||
'default' => [
|
||||
'input' => ['system' => ['url' => 'https://friendica.local',],],
|
||||
'server' => [],
|
||||
'assertion' => 'https://friendica.local',
|
||||
],
|
||||
'subPath' => [
|
||||
'input' => ['system' => ['url' => 'https://friendica.local/subpath',],],
|
||||
'server' => [],
|
||||
'assertion' => 'https://friendica.local/subpath',
|
||||
],
|
||||
'empty' => [
|
||||
'input' => [],
|
||||
'server' => [],
|
||||
'assertion' => 'http://localhost',
|
||||
],
|
||||
'serverArrayStandard' => [
|
||||
'input' => [],
|
||||
'server' => [
|
||||
'HTTPS' => 'on',
|
||||
'HTTP_HOST' => 'friendica.server',
|
||||
'REQUEST_URI' => '/test/it?with=query',
|
||||
'QUERY_STRING' => 'pagename=test/it',
|
||||
],
|
||||
'assertion' => 'https://friendica.server',
|
||||
],
|
||||
'serverArraySubPath' => [
|
||||
'input' => [],
|
||||
'server' => [
|
||||
'HTTPS' => 'on',
|
||||
'HTTP_HOST' => 'friendica.server',
|
||||
'REQUEST_URI' => '/test/it/now?with=query',
|
||||
'QUERY_STRING' => 'pagename=it/now',
|
||||
],
|
||||
'assertion' => 'https://friendica.server/test',
|
||||
],
|
||||
'serverArraySubPath2' => [
|
||||
'input' => [],
|
||||
'server' => [
|
||||
'HTTPS' => 'on',
|
||||
'HTTP_HOST' => 'friendica.server',
|
||||
'REQUEST_URI' => '/test/it/now?with=query',
|
||||
'QUERY_STRING' => 'pagename=now',
|
||||
],
|
||||
'assertion' => 'https://friendica.server/test/it',
|
||||
],
|
||||
'serverArraySubPath3' => [
|
||||
'input' => [],
|
||||
'server' => [
|
||||
'HTTPS' => 'on',
|
||||
'HTTP_HOST' => 'friendica.server',
|
||||
'REQUEST_URI' => '/test/it/now?with=query',
|
||||
'QUERY_STRING' => 'pagename=test/it/now',
|
||||
],
|
||||
'assertion' => 'https://friendica.server',
|
||||
],
|
||||
'serverArrayWithoutQueryString1' => [
|
||||
'input' => [],
|
||||
'server' => [
|
||||
'HTTPS' => 'on',
|
||||
'HTTP_HOST' => 'friendica.server',
|
||||
'REQUEST_URI' => '/test/it/now?with=query',
|
||||
],
|
||||
'assertion' => 'https://friendica.server/test/it/now',
|
||||
],
|
||||
'serverArrayWithoutQueryString2' => [
|
||||
'input' => [],
|
||||
'server' => [
|
||||
'HTTPS' => 'on',
|
||||
'HTTP_HOST' => 'friendica.server',
|
||||
'REQUEST_URI' => '',
|
||||
],
|
||||
'assertion' => 'https://friendica.server',
|
||||
],
|
||||
'serverArrayWithoutQueryString3' => [
|
||||
'input' => [],
|
||||
'server' => [
|
||||
'HTTPS' => 'on',
|
||||
'HTTP_HOST' => 'friendica.server',
|
||||
'REQUEST_URI' => '/',
|
||||
],
|
||||
'assertion' => 'https://friendica.server',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSystemUrl
|
||||
*/
|
||||
public function testDetermine(array $input, array $server, string $assertion)
|
||||
{
|
||||
$origServerGlobal = $_SERVER;
|
||||
|
||||
$_SERVER = array_merge_recursive($_SERVER, $server);
|
||||
$config = new ReadOnlyFileConfig(new Cache($input));
|
||||
|
||||
$baseUrl = new BaseURL($config, new NullLogger(), $server);
|
||||
|
||||
self::assertEquals($assertion, (string)$baseUrl);
|
||||
|
||||
$_SERVER = $origServerGlobal;
|
||||
}
|
||||
|
||||
public function dataRemove(): array
|
||||
{
|
||||
return [
|
||||
'same' => [
|
||||
'base' => ['system' => ['url' => 'https://friendica.local',],],
|
||||
'origUrl' => 'https://friendica.local/test/picture.png',
|
||||
'assertion' => 'test/picture.png',
|
||||
],
|
||||
'other' => [
|
||||
'base' => ['system' => ['url' => 'https://friendica.local',],],
|
||||
'origUrl' => 'https://friendica.other/test/picture.png',
|
||||
'assertion' => 'https://friendica.other/test/picture.png',
|
||||
],
|
||||
'samSubPath' => [
|
||||
'base' => ['system' => ['url' => 'https://friendica.local/test',],],
|
||||
'origUrl' => 'https://friendica.local/test/picture.png',
|
||||
'assertion' => 'picture.png',
|
||||
],
|
||||
'otherSubPath' => [
|
||||
'base' => ['system' => ['url' => 'https://friendica.local/test',],],
|
||||
'origUrl' => 'https://friendica.other/test/picture.png',
|
||||
'assertion' => 'https://friendica.other/test/picture.png',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataRemove
|
||||
*/
|
||||
public function testRemove(array $base, string $origUrl, string $assertion)
|
||||
{
|
||||
$config = new ReadOnlyFileConfig(new Cache($base));
|
||||
$baseUrl = new BaseURL($config, new NullLogger());
|
||||
|
||||
self::assertEquals($assertion, $baseUrl->remove($origUrl));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that redirect to external domains fails
|
||||
*/
|
||||
public function testRedirectException()
|
||||
{
|
||||
self::expectException(InternalServerErrorException::class);
|
||||
self::expectErrorMessage('https://friendica.other is not a relative path, please use System::externalRedirect');
|
||||
|
||||
$config = new ReadOnlyFileConfig(new Cache([
|
||||
'system' => [
|
||||
'url' => 'https://friendica.local',
|
||||
]
|
||||
]));
|
||||
$baseUrl = new BaseURL($config, new NullLogger());
|
||||
$baseUrl->redirect('https://friendica.other');
|
||||
}
|
||||
}
|
|
@ -1,473 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @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\Test\src\Util;
|
||||
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\Config\Model\DatabaseConfig;
|
||||
use Friendica\Core\Config\Model\ReadOnlyFileConfig;
|
||||
use Friendica\Core\Config\Util\ConfigFileManager;
|
||||
use Friendica\Core\Config\ValueObject\Cache;
|
||||
use Friendica\Test\DatabaseTest;
|
||||
use Friendica\Test\Util\CreateDatabaseTrait;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
|
||||
class BaseURLTest extends DatabaseTest
|
||||
{
|
||||
use VFSTrait;
|
||||
use CreateDatabaseTrait;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->setUpVfsDir();
|
||||
}
|
||||
|
||||
public function dataDefault()
|
||||
{
|
||||
return [
|
||||
'null' => [
|
||||
'server' => [],
|
||||
'input' => [
|
||||
'hostname' => null,
|
||||
'urlPath' => null,
|
||||
'sslPolicy' => null,
|
||||
'url' => null,
|
||||
],
|
||||
'assert' => [
|
||||
'hostname' => '',
|
||||
'urlPath' => '',
|
||||
'sslPolicy' => BaseURL::DEFAULT_SSL_SCHEME,
|
||||
'url' => 'http://',
|
||||
'scheme' => 'http',
|
||||
],
|
||||
],
|
||||
'WithSubDirectory' => [
|
||||
'server' => [
|
||||
'SERVER_NAME' => 'friendica.local',
|
||||
'REDIRECT_URI' => 'test/module/more',
|
||||
'QUERY_STRING' => 'module/more',
|
||||
],
|
||||
'input' => [
|
||||
'hostname' => null,
|
||||
'urlPath' => null,
|
||||
'sslPolicy' => null,
|
||||
'url' => null,
|
||||
],
|
||||
'assert' => [
|
||||
'hostname' => 'friendica.local',
|
||||
'urlPath' => 'test',
|
||||
'sslPolicy' => BaseURL::DEFAULT_SSL_SCHEME,
|
||||
'url' => 'http://friendica.local/test',
|
||||
'scheme' => 'http',
|
||||
],
|
||||
],
|
||||
'input' => [
|
||||
'server' => [],
|
||||
'input' => [
|
||||
'hostname' => 'friendica.local',
|
||||
'urlPath' => 'test',
|
||||
'sslPolicy' => BaseURL::SSL_POLICY_FULL,
|
||||
'url' => 'http://friendica.local/test',
|
||||
],
|
||||
'assert' => [
|
||||
'hostname' => 'friendica.local',
|
||||
'urlPath' => 'test',
|
||||
'sslPolicy' => BaseURL::SSL_POLICY_FULL,
|
||||
'url' => 'http://friendica.local/test',
|
||||
'scheme' => 'http',
|
||||
],
|
||||
],
|
||||
'WithHttpsScheme' => [
|
||||
'server' => [
|
||||
'SERVER_NAME' => 'friendica.local',
|
||||
'REDIRECT_URI' => 'test/module/more',
|
||||
'QUERY_STRING' => 'module/more',
|
||||
'HTTPS' => true,
|
||||
],
|
||||
'input' => [
|
||||
'hostname' => null,
|
||||
'urlPath' => null,
|
||||
'sslPolicy' => null,
|
||||
'url' => null,
|
||||
],
|
||||
'assert' => [
|
||||
'hostname' => 'friendica.local',
|
||||
'urlPath' => 'test',
|
||||
'sslPolicy' => BaseURL::SSL_POLICY_FULL,
|
||||
'url' => 'https://friendica.local/test',
|
||||
'scheme' => 'https',
|
||||
],
|
||||
],
|
||||
'WithoutQueryString' => [
|
||||
'server' => [
|
||||
'SERVER_NAME' => 'friendica.local',
|
||||
'REDIRECT_URI' => 'test/more',
|
||||
'HTTPS' => true,
|
||||
],
|
||||
'input' => [
|
||||
'hostname' => null,
|
||||
'urlPath' => null,
|
||||
'sslPolicy' => null,
|
||||
'url' => null,
|
||||
],
|
||||
'assert' => [
|
||||
'hostname' => 'friendica.local',
|
||||
'urlPath' => 'test/more',
|
||||
'sslPolicy' => BaseURL::SSL_POLICY_FULL,
|
||||
'url' => 'https://friendica.local/test/more',
|
||||
'scheme' => 'https',
|
||||
],
|
||||
],
|
||||
'WithPort' => [
|
||||
'server' => [
|
||||
'SERVER_NAME' => 'friendica.local',
|
||||
'SERVER_PORT' => '1234',
|
||||
'REDIRECT_URI' => 'test/more',
|
||||
'HTTPS' => true,
|
||||
],
|
||||
'input' => [
|
||||
'hostname' => null,
|
||||
'urlPath' => null,
|
||||
'sslPolicy' => null,
|
||||
'url' => null,
|
||||
],
|
||||
'assert' => [
|
||||
'hostname' => 'friendica.local:1234',
|
||||
'urlPath' => 'test/more',
|
||||
'sslPolicy' => BaseURL::SSL_POLICY_FULL,
|
||||
'url' => 'https://friendica.local:1234/test/more',
|
||||
'scheme' => 'https',
|
||||
],
|
||||
],
|
||||
'With443Port' => [
|
||||
'server' => [
|
||||
'SERVER_NAME' => 'friendica.local',
|
||||
'SERVER_PORT' => '443',
|
||||
'REDIRECT_URI' => 'test/more',
|
||||
],
|
||||
'input' => [
|
||||
'hostname' => null,
|
||||
'urlPath' => null,
|
||||
'sslPolicy' => null,
|
||||
'url' => null,
|
||||
],
|
||||
'assert' => [
|
||||
'hostname' => 'friendica.local',
|
||||
'urlPath' => 'test/more',
|
||||
'sslPolicy' => BaseURL::SSL_POLICY_FULL,
|
||||
'url' => 'https://friendica.local/test/more',
|
||||
'scheme' => 'https',
|
||||
],
|
||||
],
|
||||
'With80Port' => [
|
||||
'server' => [
|
||||
'SERVER_NAME' => 'friendica.local',
|
||||
'SERVER_PORT' => '80',
|
||||
'REDIRECT_URI' => 'test/more',
|
||||
],
|
||||
'input' => [
|
||||
'hostname' => null,
|
||||
'urlPath' => null,
|
||||
'sslPolicy' => null,
|
||||
'url' => null,
|
||||
],
|
||||
'assert' => [
|
||||
'hostname' => 'friendica.local',
|
||||
'urlPath' => 'test/more',
|
||||
'sslPolicy' => BaseURL::DEFAULT_SSL_SCHEME,
|
||||
'url' => 'http://friendica.local/test/more',
|
||||
'scheme' => 'http',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function dataSave()
|
||||
{
|
||||
return [
|
||||
'no_change' => [
|
||||
'input' => [
|
||||
'hostname' => 'friendica.local',
|
||||
'urlPath' => 'path',
|
||||
'sslPolicy' => BaseURL::SSL_POLICY_FULL,
|
||||
'url' => 'https://friendica.local/path',
|
||||
'force_ssl' => true,
|
||||
],
|
||||
'save' => [
|
||||
'hostname' => 'friendica.local',
|
||||
'urlPath' => 'path',
|
||||
'sslPolicy' => BaseURL::SSL_POLICY_FULL,
|
||||
],
|
||||
'url' => 'https://friendica.local/path',
|
||||
],
|
||||
'default' => [
|
||||
'input' => [
|
||||
'hostname' => 'friendica.old',
|
||||
'urlPath' => 'is/old/path',
|
||||
'sslPolicy' => BaseURL::DEFAULT_SSL_SCHEME,
|
||||
'url' => 'http://friendica.old/is/old/path',
|
||||
'force_ssl' => true,
|
||||
],
|
||||
'save' => [
|
||||
'hostname' => 'friendica.local',
|
||||
'urlPath' => 'new/path',
|
||||
'sslPolicy' => BaseURL::SSL_POLICY_FULL,
|
||||
],
|
||||
'url' => 'https://friendica.local/new/path',
|
||||
],
|
||||
'null' => [
|
||||
'input' => [
|
||||
'hostname' => 'friendica.old',
|
||||
'urlPath' => 'is/old/path',
|
||||
'sslPolicy' => BaseURL::DEFAULT_SSL_SCHEME,
|
||||
'url' => 'http://friendica.old/is/old/path',
|
||||
'force_ssl' => true,
|
||||
],
|
||||
'save' => [
|
||||
'hostname' => null,
|
||||
'urlPath' => null,
|
||||
'sslPolicy' => null,
|
||||
],
|
||||
'url' => 'http://friendica.old/is/old/path',
|
||||
],
|
||||
'changeHostname' => [
|
||||
'input' => [
|
||||
'hostname' => 'friendica.old',
|
||||
'urlPath' => 'is/old/path',
|
||||
'sslPolicy' => BaseURL::DEFAULT_SSL_SCHEME,
|
||||
'url' => 'http://friendica.old/is/old/path',
|
||||
'force_ssl' => true,
|
||||
],
|
||||
'save' => [
|
||||
'hostname' => 'friendica.local',
|
||||
'urlPath' => null,
|
||||
'sslPolicy' => null,
|
||||
],
|
||||
'url' => 'http://friendica.local/is/old/path',
|
||||
],
|
||||
'changeUrlPath' => [
|
||||
'input' => [
|
||||
'hostname' => 'friendica.old',
|
||||
'urlPath' => 'is/old/path',
|
||||
'sslPolicy' => BaseURL::DEFAULT_SSL_SCHEME,
|
||||
'url' => 'http://friendica.old/is/old/path',
|
||||
'force_ssl' => true,
|
||||
],
|
||||
'save' => [
|
||||
'hostname' => null,
|
||||
'urlPath' => 'new/path',
|
||||
'sslPolicy' => null,
|
||||
],
|
||||
'url' => 'http://friendica.old/new/path',
|
||||
],
|
||||
'changeSSLPolicy' => [
|
||||
'input' => [
|
||||
'hostname' => 'friendica.old',
|
||||
'urlPath' => 'is/old/path',
|
||||
'sslPolicy' => BaseURL::DEFAULT_SSL_SCHEME,
|
||||
'url' => 'http://friendica.old/is/old/path',
|
||||
'force_ssl' => true,
|
||||
],
|
||||
'save' => [
|
||||
'hostname' => null,
|
||||
'urlPath' => null,
|
||||
'sslPolicy' => BaseURL::SSL_POLICY_FULL,
|
||||
],
|
||||
'url' => 'https://friendica.old/is/old/path',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the save() method
|
||||
* @dataProvider dataSave
|
||||
*/
|
||||
public function testSave($input, $save, $url)
|
||||
{
|
||||
$config = new DatabaseConfig($this->getDbInstance(), new Cache([
|
||||
'config' => [
|
||||
'hostname' => $input['hostname'] ?? null,
|
||||
],
|
||||
'system' => [
|
||||
'urlpath' => $input['urlPath'] ?? null,
|
||||
'ssl_policy' => $input['sslPolicy'] ?? null,
|
||||
'url' => $input['url'] ?? null,
|
||||
'force_ssl' => $input['force_ssl'] ?? null,
|
||||
],
|
||||
]));
|
||||
|
||||
$baseUrl = new BaseURL($config, []);
|
||||
|
||||
$baseUrl->save($save['hostname'], $save['sslPolicy'], $save['urlPath']);
|
||||
|
||||
self::assertEquals($url, $baseUrl->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the saveByUrl() method
|
||||
* @dataProvider dataSave
|
||||
*
|
||||
* @param $input
|
||||
* @param $save
|
||||
* @param $url
|
||||
*/
|
||||
public function testSaveByUrl($input, $save, $url)
|
||||
{
|
||||
$config = new DatabaseConfig($this->getDbInstance(), new Cache([
|
||||
'config' => [
|
||||
'hostname' => $input['hostname'] ?? null,
|
||||
],
|
||||
'system' => [
|
||||
'urlpath' => $input['urlPath'] ?? null,
|
||||
'ssl_policy' => $input['sslPolicy'] ?? null,
|
||||
'url' => $input['url'] ?? null,
|
||||
'force_ssl' => $input['force_ssl'] ?? null,
|
||||
],
|
||||
]));
|
||||
|
||||
$baseUrl = new BaseURL($config, []);
|
||||
|
||||
$baseUrl->saveByURL($url);
|
||||
|
||||
self::assertEquals($url, $baseUrl->get());
|
||||
}
|
||||
|
||||
public function dataGetBaseUrl()
|
||||
{
|
||||
return [
|
||||
'default' => [
|
||||
'sslPolicy' => BaseURL::DEFAULT_SSL_SCHEME,
|
||||
'ssl' => false,
|
||||
'url' => 'http://friendica.local/new/test',
|
||||
'assert' => 'http://friendica.local/new/test',
|
||||
],
|
||||
'DefaultWithSSL' => [
|
||||
'sslPolicy' => BaseURL::DEFAULT_SSL_SCHEME,
|
||||
'ssl' => true,
|
||||
'url' => 'http://friendica.local/new/test',
|
||||
'assert' => 'https://friendica.local/new/test',
|
||||
],
|
||||
'SSLFullWithSSL' => [
|
||||
'sslPolicy' => BaseURL::SSL_POLICY_FULL,
|
||||
'ssl' => true,
|
||||
'url' => 'http://friendica.local/new/test',
|
||||
'assert' => 'http://friendica.local/new/test',
|
||||
],
|
||||
'SSLFullWithoutSSL' => [
|
||||
'sslPolicy' => BaseURL::SSL_POLICY_FULL,
|
||||
'ssl' => false,
|
||||
'url' => 'https://friendica.local/new/test',
|
||||
'assert' => 'https://friendica.local/new/test',
|
||||
],
|
||||
'NoSSLWithSSL' => [
|
||||
'sslPolicy' => BaseURL::SSL_POLICY_NONE,
|
||||
'ssl' => true,
|
||||
'url' => 'http://friendica.local/new/test',
|
||||
'assert' => 'http://friendica.local/new/test',
|
||||
],
|
||||
'NoSSLWithoutSSL' => [
|
||||
'sslPolicy' => BaseURL::SSL_POLICY_NONE,
|
||||
'ssl' => false,
|
||||
'url' => 'http://friendica.local/new/test',
|
||||
'assert' => 'http://friendica.local/new/test',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the get() method
|
||||
* @dataProvider dataGetBaseUrl
|
||||
*/
|
||||
public function testGetURL($sslPolicy, $ssl, $url, $assert)
|
||||
{
|
||||
$configMock = \Mockery::mock(IManageConfigValues::class);
|
||||
$configMock->shouldReceive('get')->with('config', 'hostname')->andReturn('friendica.local');
|
||||
$configMock->shouldReceive('get')->with('system', 'urlpath')->andReturn('new/test');
|
||||
$configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($sslPolicy);
|
||||
$configMock->shouldReceive('get')->with('system', 'url')->andReturn($url);
|
||||
|
||||
$baseUrl = new BaseURL($configMock, []);
|
||||
|
||||
self::assertEquals($assert, $baseUrl->get($ssl));
|
||||
}
|
||||
|
||||
public function dataCheckRedirectHTTPS()
|
||||
{
|
||||
return [
|
||||
'default' => [
|
||||
'server' => [
|
||||
'REQUEST_METHOD' => 'GET',
|
||||
'HTTPS' => true,
|
||||
],
|
||||
'forceSSL' => false,
|
||||
'sslPolicy' => BaseURL::DEFAULT_SSL_SCHEME,
|
||||
'url' => 'https://friendica.local',
|
||||
'redirect' => false,
|
||||
],
|
||||
'forceSSL' => [
|
||||
'server' => [
|
||||
'REQUEST_METHOD' => 'GET',
|
||||
],
|
||||
'forceSSL' => true,
|
||||
'sslPolicy' => BaseURL::DEFAULT_SSL_SCHEME,
|
||||
'url' => 'https://friendica.local',
|
||||
'redirect' => false,
|
||||
],
|
||||
'forceSSLWithSSLPolicy' => [
|
||||
'server' => [],
|
||||
'forceSSL' => true,
|
||||
'sslPolicy' => BaseURL::SSL_POLICY_FULL,
|
||||
'url' => 'https://friendica.local',
|
||||
'redirect' => false,
|
||||
],
|
||||
'forceSSLWithSSLPolicyAndGet' => [
|
||||
'server' => [
|
||||
'REQUEST_METHOD' => 'GET',
|
||||
],
|
||||
'forceSSL' => true,
|
||||
'sslPolicy' => BaseURL::SSL_POLICY_FULL,
|
||||
'url' => 'https://friendica.local',
|
||||
'redirect' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the checkRedirectHTTPS() method
|
||||
* @dataProvider dataCheckRedirectHTTPS
|
||||
*/
|
||||
public function testCheckRedirectHTTPS($server, $forceSSL, $sslPolicy, $url, $redirect)
|
||||
{
|
||||
$configMock = \Mockery::mock(IManageConfigValues::class);
|
||||
$configMock->shouldReceive('get')->with('config', 'hostname')->andReturn('friendica.local');
|
||||
$configMock->shouldReceive('get')->with('system', 'urlpath')->andReturn('new/test');
|
||||
$configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($sslPolicy);
|
||||
$configMock->shouldReceive('get')->with('system', 'url')->andReturn($url);
|
||||
$configMock->shouldReceive('get')->with('system', 'force_ssl')->andReturn($forceSSL);
|
||||
|
||||
$baseUrl = new BaseURL($configMock, $server);
|
||||
|
||||
self::assertEquals($redirect, $baseUrl->checkRedirectHttps());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue