Browse Source
Merge pull request #11917 from owncloud/fix-11909
Merge pull request #11917 from owncloud/fix-11909
Add checkbox to enforce SSL for subdomainsremotes/origin/fix-10825
10 changed files with 311 additions and 36 deletions
-
6config/config.sample.php
-
15lib/base.php
-
3settings/admin.php
-
21settings/ajax/setsecurity.php
-
9settings/application.php
-
95settings/controller/securitysettingscontroller.php
-
30settings/js/admin.js
-
8settings/routes.php
-
22settings/templates/admin.php
-
138tests/settings/controller/securitysettingscontrollertest.php
@ -1,21 +0,0 @@ |
|||
<?php |
|||
/** |
|||
* Copyright (c) 2013-2014, Lukas Reschke <lukas@owncloud.com> |
|||
* This file is licensed under the Affero General Public License version 3 or later. |
|||
* See the COPYING-README file. |
|||
*/ |
|||
|
|||
OC_Util::checkAdminUser(); |
|||
OCP\JSON::callCheck(); |
|||
|
|||
if(isset($_POST['enforceHTTPS'])) { |
|||
\OC::$server->getConfig()->setSystemValue('forcessl', filter_var($_POST['enforceHTTPS'], FILTER_VALIDATE_BOOLEAN)); |
|||
} |
|||
|
|||
if(isset($_POST['trustedDomain'])) { |
|||
$trustedDomains = \OC::$server->getConfig()->getSystemValue('trusted_domains'); |
|||
$trustedDomains[] = $_POST['trustedDomain']; |
|||
\OC::$server->getConfig()->setSystemValue('trusted_domains', $trustedDomains); |
|||
} |
|||
|
|||
echo 'true'; |
|||
@ -0,0 +1,95 @@ |
|||
<?php |
|||
/** |
|||
* @author Lukas Reschke |
|||
* @copyright 2014 Lukas Reschke lukas@owncloud.com |
|||
* |
|||
* This file is licensed under the Affero General Public License version 3 or |
|||
* later. |
|||
* See the COPYING-README file. |
|||
*/ |
|||
|
|||
namespace OC\Settings\Controller; |
|||
|
|||
use \OCP\AppFramework\Controller; |
|||
use OCP\IRequest; |
|||
use OCP\IConfig; |
|||
|
|||
/** |
|||
* @package OC\Settings\Controller |
|||
*/ |
|||
class SecuritySettingsController extends Controller { |
|||
/** @var \OCP\IConfig */ |
|||
private $config; |
|||
|
|||
/** |
|||
* @param string $appName |
|||
* @param IRequest $request |
|||
* @param IConfig $config |
|||
*/ |
|||
public function __construct($appName, |
|||
IRequest $request, |
|||
IConfig $config) { |
|||
parent::__construct($appName, $request); |
|||
$this->config = $config; |
|||
} |
|||
|
|||
/** |
|||
* @return array |
|||
*/ |
|||
protected function returnSuccess() { |
|||
return array( |
|||
'status' => 'success' |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* @return array |
|||
*/ |
|||
protected function returnError() { |
|||
return array( |
|||
'status' => 'error' |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Enforce or disable the enforcement of SSL |
|||
* @param boolean $enforceHTTPS Whether SSL should be enforced |
|||
* @return array |
|||
*/ |
|||
public function enforceSSL($enforceHTTPS = false) { |
|||
if(!is_bool($enforceHTTPS)) { |
|||
return $this->returnError(); |
|||
} |
|||
$this->config->setSystemValue('forcessl', $enforceHTTPS); |
|||
|
|||
return $this->returnSuccess(); |
|||
} |
|||
|
|||
/** |
|||
* Enforce or disable the enforcement for SSL on subdomains |
|||
* @param bool $forceSSLforSubdomains Whether SSL on subdomains should be enforced |
|||
* @return array |
|||
*/ |
|||
public function enforceSSLForSubdomains($forceSSLforSubdomains = false) { |
|||
if(!is_bool($forceSSLforSubdomains)) { |
|||
return $this->returnError(); |
|||
} |
|||
$this->config->setSystemValue('forceSSLforSubdomains', $forceSSLforSubdomains); |
|||
|
|||
return $this->returnSuccess(); |
|||
} |
|||
|
|||
/** |
|||
* Add a new trusted domain |
|||
* @param string $newTrustedDomain The newly to add trusted domain |
|||
* @return array |
|||
*/ |
|||
public function trustedDomains($newTrustedDomain) { |
|||
$trustedDomains = $this->config->getSystemValue('trusted_domains'); |
|||
$trustedDomains[] = $newTrustedDomain; |
|||
$this->config->setSystemValue('trusted_domains', $trustedDomains); |
|||
|
|||
return $this->returnSuccess(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,138 @@ |
|||
<?php |
|||
/** |
|||
* @author Lukas Reschke |
|||
* @copyright 2014 Lukas Reschke lukas@owncloud.com |
|||
* |
|||
* This file is licensed under the Affero General Public License version 3 or |
|||
* later. |
|||
* See the COPYING-README file. |
|||
*/ |
|||
namespace OC\Settings\Controller; |
|||
|
|||
use \OC\Settings\Application; |
|||
|
|||
/** |
|||
* @package OC\Settings\Controller |
|||
*/ |
|||
class SecuritySettingsControllerTest extends \PHPUnit_Framework_TestCase { |
|||
|
|||
/** @var \OCP\AppFramework\IAppContainer */ |
|||
private $container; |
|||
|
|||
/** @var SecuritySettingsController */ |
|||
private $securitySettingsController; |
|||
|
|||
protected function setUp() { |
|||
$app = new Application(); |
|||
$this->container = $app->getContainer(); |
|||
$this->container['Config'] = $this->getMockBuilder('\OCP\IConfig') |
|||
->disableOriginalConstructor()->getMock(); |
|||
$this->container['AppName'] = 'settings'; |
|||
$this->securitySettingsController = $this->container['SecuritySettingsController']; |
|||
} |
|||
|
|||
|
|||
public function testEnforceSSLEmpty() { |
|||
$this->container['Config'] |
|||
->expects($this->once()) |
|||
->method('setSystemValue') |
|||
->with('forcessl', false); |
|||
|
|||
$response = $this->securitySettingsController->enforceSSL(); |
|||
$expectedResponse = array('status' => 'success'); |
|||
|
|||
$this->assertSame($expectedResponse, $response); |
|||
} |
|||
|
|||
public function testEnforceSSL() { |
|||
$this->container['Config'] |
|||
->expects($this->once()) |
|||
->method('setSystemValue') |
|||
->with('forcessl', true); |
|||
|
|||
$response = $this->securitySettingsController->enforceSSL(true); |
|||
$expectedResponse = array('status' => 'success'); |
|||
|
|||
$this->assertSame($expectedResponse, $response); |
|||
} |
|||
|
|||
public function testEnforceSSLInvalid() { |
|||
$this->container['Config'] |
|||
->expects($this->exactly(0)) |
|||
->method('setSystemValue'); |
|||
|
|||
$response = $this->securitySettingsController->enforceSSL('blah'); |
|||
$expectedResponse = array('status' => 'error'); |
|||
|
|||
$this->assertSame($expectedResponse, $response); |
|||
} |
|||
|
|||
public function testEnforceSSLForSubdomainsEmpty() { |
|||
$this->container['Config'] |
|||
->expects($this->once()) |
|||
->method('setSystemValue') |
|||
->with('forceSSLforSubdomains', false); |
|||
|
|||
$response = $this->securitySettingsController->enforceSSLForSubdomains(); |
|||
$expectedResponse = array('status' => 'success'); |
|||
|
|||
$this->assertSame($expectedResponse, $response); |
|||
} |
|||
|
|||
public function testEnforceSSLForSubdomains() { |
|||
$this->container['Config'] |
|||
->expects($this->once()) |
|||
->method('setSystemValue') |
|||
->with('forceSSLforSubdomains', true); |
|||
|
|||
$response = $this->securitySettingsController->enforceSSLForSubdomains(true); |
|||
$expectedResponse = array('status' => 'success'); |
|||
|
|||
$this->assertSame($expectedResponse, $response); |
|||
} |
|||
|
|||
public function testEnforceSSLForSubdomainsInvalid() { |
|||
$this->container['Config'] |
|||
->expects($this->exactly(0)) |
|||
->method('setSystemValue'); |
|||
|
|||
$response = $this->securitySettingsController->enforceSSLForSubdomains('blah'); |
|||
$expectedResponse = array('status' => 'error'); |
|||
|
|||
$this->assertSame($expectedResponse, $response); |
|||
} |
|||
|
|||
public function testTrustedDomainsWithExistingValues() { |
|||
$this->container['Config'] |
|||
->expects($this->once()) |
|||
->method('setSystemValue') |
|||
->with('trusted_domains', array('owncloud.org', 'owncloud.com', 'newdomain.com')); |
|||
$this->container['Config'] |
|||
->expects($this->once()) |
|||
->method('getSystemValue') |
|||
->with('trusted_domains') |
|||
->will($this->returnValue(array('owncloud.org', 'owncloud.com'))); |
|||
|
|||
$response = $this->securitySettingsController->trustedDomains('newdomain.com'); |
|||
$expectedResponse = array('status' => 'success'); |
|||
|
|||
$this->assertSame($expectedResponse, $response); |
|||
} |
|||
|
|||
public function testTrustedDomainsEmpty() { |
|||
$this->container['Config'] |
|||
->expects($this->once()) |
|||
->method('setSystemValue') |
|||
->with('trusted_domains', array('newdomain.com')); |
|||
$this->container['Config'] |
|||
->expects($this->once()) |
|||
->method('getSystemValue') |
|||
->with('trusted_domains') |
|||
->will($this->returnValue('')); |
|||
|
|||
$response = $this->securitySettingsController->trustedDomains('newdomain.com'); |
|||
$expectedResponse = array('status' => 'success'); |
|||
|
|||
$this->assertSame($expectedResponse, $response); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue