aboutsummaryrefslogtreecommitdiffstats
path: root/tests/settings/controller/CheckSetupControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/settings/controller/CheckSetupControllerTest.php')
-rw-r--r--tests/settings/controller/CheckSetupControllerTest.php92
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/settings/controller/CheckSetupControllerTest.php b/tests/settings/controller/CheckSetupControllerTest.php
index 6096aae8652..414b1b91e17 100644
--- a/tests/settings/controller/CheckSetupControllerTest.php
+++ b/tests/settings/controller/CheckSetupControllerTest.php
@@ -31,11 +31,24 @@ use OC_Util;
use Test\TestCase;
/**
+ * Mock version_compare
+ * @param string $version1
+ * @param string $version2
+ * @return int
+ */
+function version_compare($version1, $version2) {
+ return CheckSetupControllerTest::$version_compare;
+}
+
+/**
* Class CheckSetupControllerTest
*
* @package OC\Settings\Controller
*/
class CheckSetupControllerTest extends TestCase {
+ /** @var int */
+ public static $version_compare;
+
/** @var CheckSetupController */
private $checkSetupController;
/** @var IRequest */
@@ -209,6 +222,66 @@ class CheckSetupControllerTest extends TestCase {
);
}
+ public function testIsPhpSupportedFalse() {
+ self::$version_compare = -1;
+
+ $this->assertEquals(
+ ['eol' => true, 'version' => PHP_VERSION],
+ self::invokePrivate($this->checkSetupController, 'isPhpSupported')
+ );
+ }
+
+ public function testIsPhpSupportedTrue() {
+ self::$version_compare = 0;
+
+ $this->assertEquals(
+ ['eol' => false, 'version' => PHP_VERSION],
+ self::invokePrivate($this->checkSetupController, 'isPhpSupported')
+ );
+
+
+ self::$version_compare = 1;
+
+ $this->assertEquals(
+ ['eol' => false, 'version' => PHP_VERSION],
+ self::invokePrivate($this->checkSetupController, 'isPhpSupported')
+ );
+ }
+
+ public function testForwardedForHeadersWorkingFalse() {
+ $this->config->expects($this->once())
+ ->method('getSystemValue')
+ ->with('trusted_proxies', [])
+ ->willReturn(['1.2.3.4']);
+ $this->request->expects($this->once())
+ ->method('getRemoteAddress')
+ ->willReturn('1.2.3.4');
+
+ $this->assertFalse(
+ self::invokePrivate(
+ $this->checkSetupController,
+ 'forwardedForHeadersWorking'
+ )
+ );
+ }
+
+ public function testForwardedForHeadersWorkingTrue() {
+ $this->config->expects($this->once())
+ ->method('getSystemValue')
+ ->with('trusted_proxies', [])
+ ->willReturn(['1.2.3.4']);
+ $this->request->expects($this->once())
+ ->method('getRemoteAddress')
+ ->willReturn('4.3.2.1');
+
+ $this->assertTrue(
+ self::invokePrivate(
+ $this->checkSetupController,
+ 'forwardedForHeadersWorking'
+ )
+ );
+ }
+
public function testCheck() {
$this->config->expects($this->at(0))
->method('getSystemValue')
@@ -218,6 +291,14 @@ class CheckSetupControllerTest extends TestCase {
->method('getSystemValue')
->with('memcache.local', null)
->will($this->returnValue('SomeProvider'));
+ $this->config->expects($this->at(2))
+ ->method('getSystemValue')
+ ->with('trusted_proxies', [])
+ ->willReturn(['1.2.3.4']);
+
+ $this->request->expects($this->once())
+ ->method('getRemoteAddress')
+ ->willReturn('4.3.2.1');
$client = $this->getMockBuilder('\OCP\Http\Client\IClient')
->disableOriginalConstructor()->getMock();
@@ -244,6 +325,11 @@ class CheckSetupControllerTest extends TestCase {
->method('linkToDocs')
->with('admin-security')
->willReturn('https://doc.owncloud.org/server/8.1/admin_manual/configuration_server/hardening.html');
+ self::$version_compare = -1;
+ $this->urlGenerator->expects($this->at(2))
+ ->method('linkToDocs')
+ ->with('admin-reverse-proxy')
+ ->willReturn('reverse-proxy-doc-link');
$expected = new DataResponse(
[
@@ -254,6 +340,12 @@ class CheckSetupControllerTest extends TestCase {
'isUrandomAvailable' => self::invokePrivate($this->checkSetupController, 'isUrandomAvailable'),
'securityDocs' => 'https://doc.owncloud.org/server/8.1/admin_manual/configuration_server/hardening.html',
'isUsedTlsLibOutdated' => '',
+ 'phpSupported' => [
+ 'eol' => true,
+ 'version' => PHP_VERSION
+ ],
+ 'forwardedForHeadersWorking' => true,
+ 'reverseProxyDocs' => 'reverse-proxy-doc-link',
]
);
$this->assertEquals($expected, $this->checkSetupController->check());