No longer add trusted servers on federated share creation
It was disabled by default for ages. And often resulted in unwanted behavior. If admins want trusted servers they just have to do it manually. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
d18aa63560
commit
771dfc8170
|
@ -34,11 +34,6 @@ return [
|
||||||
'url' => '/trusted-servers/{id}',
|
'url' => '/trusted-servers/{id}',
|
||||||
'verb' => 'DELETE'
|
'verb' => 'DELETE'
|
||||||
],
|
],
|
||||||
[
|
|
||||||
'name' => 'Settings#autoAddServers',
|
|
||||||
'url' => '/auto-add-servers',
|
|
||||||
'verb' => 'POST'
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
'ocs' => [
|
'ocs' => [
|
||||||
// old endpoints, only used by Nextcloud and ownCloud
|
// old endpoints, only used by Nextcloud and ownCloud
|
||||||
|
|
|
@ -37,11 +37,13 @@ namespace Composer\Autoload;
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
* @see http://www.php-fig.org/psr/psr-0/
|
* @see https://www.php-fig.org/psr/psr-0/
|
||||||
* @see http://www.php-fig.org/psr/psr-4/
|
* @see https://www.php-fig.org/psr/psr-4/
|
||||||
*/
|
*/
|
||||||
class ClassLoader
|
class ClassLoader
|
||||||
{
|
{
|
||||||
|
private $vendorDir;
|
||||||
|
|
||||||
// PSR-4
|
// PSR-4
|
||||||
private $prefixLengthsPsr4 = array();
|
private $prefixLengthsPsr4 = array();
|
||||||
private $prefixDirsPsr4 = array();
|
private $prefixDirsPsr4 = array();
|
||||||
|
@ -57,10 +59,17 @@ class ClassLoader
|
||||||
private $missingClasses = array();
|
private $missingClasses = array();
|
||||||
private $apcuPrefix;
|
private $apcuPrefix;
|
||||||
|
|
||||||
|
private static $registeredLoaders = array();
|
||||||
|
|
||||||
|
public function __construct($vendorDir = null)
|
||||||
|
{
|
||||||
|
$this->vendorDir = $vendorDir;
|
||||||
|
}
|
||||||
|
|
||||||
public function getPrefixes()
|
public function getPrefixes()
|
||||||
{
|
{
|
||||||
if (!empty($this->prefixesPsr0)) {
|
if (!empty($this->prefixesPsr0)) {
|
||||||
return call_user_func_array('array_merge', $this->prefixesPsr0);
|
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
|
||||||
}
|
}
|
||||||
|
|
||||||
return array();
|
return array();
|
||||||
|
@ -300,6 +309,17 @@ class ClassLoader
|
||||||
public function register($prepend = false)
|
public function register($prepend = false)
|
||||||
{
|
{
|
||||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||||
|
|
||||||
|
if (null === $this->vendorDir) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($prepend) {
|
||||||
|
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
|
||||||
|
} else {
|
||||||
|
unset(self::$registeredLoaders[$this->vendorDir]);
|
||||||
|
self::$registeredLoaders[$this->vendorDir] = $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -308,6 +328,10 @@ class ClassLoader
|
||||||
public function unregister()
|
public function unregister()
|
||||||
{
|
{
|
||||||
spl_autoload_unregister(array($this, 'loadClass'));
|
spl_autoload_unregister(array($this, 'loadClass'));
|
||||||
|
|
||||||
|
if (null !== $this->vendorDir) {
|
||||||
|
unset(self::$registeredLoaders[$this->vendorDir]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -367,6 +391,16 @@ class ClassLoader
|
||||||
return $file;
|
return $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the currently registered loaders indexed by their corresponding vendor directories.
|
||||||
|
*
|
||||||
|
* @return self[]
|
||||||
|
*/
|
||||||
|
public static function getRegisteredLoaders()
|
||||||
|
{
|
||||||
|
return self::$registeredLoaders;
|
||||||
|
}
|
||||||
|
|
||||||
private function findFileWithExtension($class, $ext)
|
private function findFileWithExtension($class, $ext)
|
||||||
{
|
{
|
||||||
// PSR-4 lookup
|
// PSR-4 lookup
|
||||||
|
|
|
@ -6,6 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
|
||||||
$baseDir = $vendorDir;
|
$baseDir = $vendorDir;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
|
||||||
'OCA\\Federation\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
|
'OCA\\Federation\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
|
||||||
'OCA\\Federation\\BackgroundJob\\GetSharedSecret' => $baseDir . '/../lib/BackgroundJob/GetSharedSecret.php',
|
'OCA\\Federation\\BackgroundJob\\GetSharedSecret' => $baseDir . '/../lib/BackgroundJob/GetSharedSecret.php',
|
||||||
'OCA\\Federation\\BackgroundJob\\RequestSharedSecret' => $baseDir . '/../lib/BackgroundJob/RequestSharedSecret.php',
|
'OCA\\Federation\\BackgroundJob\\RequestSharedSecret' => $baseDir . '/../lib/BackgroundJob/RequestSharedSecret.php',
|
||||||
|
@ -14,7 +15,6 @@ return array(
|
||||||
'OCA\\Federation\\Controller\\SettingsController' => $baseDir . '/../lib/Controller/SettingsController.php',
|
'OCA\\Federation\\Controller\\SettingsController' => $baseDir . '/../lib/Controller/SettingsController.php',
|
||||||
'OCA\\Federation\\DAV\\FedAuth' => $baseDir . '/../lib/DAV/FedAuth.php',
|
'OCA\\Federation\\DAV\\FedAuth' => $baseDir . '/../lib/DAV/FedAuth.php',
|
||||||
'OCA\\Federation\\DbHandler' => $baseDir . '/../lib/DbHandler.php',
|
'OCA\\Federation\\DbHandler' => $baseDir . '/../lib/DbHandler.php',
|
||||||
'OCA\\Federation\\Hooks' => $baseDir . '/../lib/Hooks.php',
|
|
||||||
'OCA\\Federation\\Middleware\\AddServerMiddleware' => $baseDir . '/../lib/Middleware/AddServerMiddleware.php',
|
'OCA\\Federation\\Middleware\\AddServerMiddleware' => $baseDir . '/../lib/Middleware/AddServerMiddleware.php',
|
||||||
'OCA\\Federation\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php',
|
'OCA\\Federation\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php',
|
||||||
'OCA\\Federation\\SyncFederationAddressBooks' => $baseDir . '/../lib/SyncFederationAddressBooks.php',
|
'OCA\\Federation\\SyncFederationAddressBooks' => $baseDir . '/../lib/SyncFederationAddressBooks.php',
|
||||||
|
|
|
@ -23,12 +23,12 @@ class ComposerAutoloaderInitFederation
|
||||||
}
|
}
|
||||||
|
|
||||||
spl_autoload_register(array('ComposerAutoloaderInitFederation', 'loadClassLoader'), true, true);
|
spl_autoload_register(array('ComposerAutoloaderInitFederation', 'loadClassLoader'), true, true);
|
||||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||||
spl_autoload_unregister(array('ComposerAutoloaderInitFederation', 'loadClassLoader'));
|
spl_autoload_unregister(array('ComposerAutoloaderInitFederation', 'loadClassLoader'));
|
||||||
|
|
||||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||||
if ($useStaticLoader) {
|
if ($useStaticLoader) {
|
||||||
require_once __DIR__ . '/autoload_static.php';
|
require __DIR__ . '/autoload_static.php';
|
||||||
|
|
||||||
call_user_func(\Composer\Autoload\ComposerStaticInitFederation::getInitializer($loader));
|
call_user_func(\Composer\Autoload\ComposerStaticInitFederation::getInitializer($loader));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -21,6 +21,7 @@ class ComposerStaticInitFederation
|
||||||
);
|
);
|
||||||
|
|
||||||
public static $classMap = array (
|
public static $classMap = array (
|
||||||
|
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
|
||||||
'OCA\\Federation\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
|
'OCA\\Federation\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
|
||||||
'OCA\\Federation\\BackgroundJob\\GetSharedSecret' => __DIR__ . '/..' . '/../lib/BackgroundJob/GetSharedSecret.php',
|
'OCA\\Federation\\BackgroundJob\\GetSharedSecret' => __DIR__ . '/..' . '/../lib/BackgroundJob/GetSharedSecret.php',
|
||||||
'OCA\\Federation\\BackgroundJob\\RequestSharedSecret' => __DIR__ . '/..' . '/../lib/BackgroundJob/RequestSharedSecret.php',
|
'OCA\\Federation\\BackgroundJob\\RequestSharedSecret' => __DIR__ . '/..' . '/../lib/BackgroundJob/RequestSharedSecret.php',
|
||||||
|
@ -29,7 +30,6 @@ class ComposerStaticInitFederation
|
||||||
'OCA\\Federation\\Controller\\SettingsController' => __DIR__ . '/..' . '/../lib/Controller/SettingsController.php',
|
'OCA\\Federation\\Controller\\SettingsController' => __DIR__ . '/..' . '/../lib/Controller/SettingsController.php',
|
||||||
'OCA\\Federation\\DAV\\FedAuth' => __DIR__ . '/..' . '/../lib/DAV/FedAuth.php',
|
'OCA\\Federation\\DAV\\FedAuth' => __DIR__ . '/..' . '/../lib/DAV/FedAuth.php',
|
||||||
'OCA\\Federation\\DbHandler' => __DIR__ . '/..' . '/../lib/DbHandler.php',
|
'OCA\\Federation\\DbHandler' => __DIR__ . '/..' . '/../lib/DbHandler.php',
|
||||||
'OCA\\Federation\\Hooks' => __DIR__ . '/..' . '/../lib/Hooks.php',
|
|
||||||
'OCA\\Federation\\Middleware\\AddServerMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/AddServerMiddleware.php',
|
'OCA\\Federation\\Middleware\\AddServerMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/AddServerMiddleware.php',
|
||||||
'OCA\\Federation\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php',
|
'OCA\\Federation\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php',
|
||||||
'OCA\\Federation\\SyncFederationAddressBooks' => __DIR__ . '/..' . '/../lib/SyncFederationAddressBooks.php',
|
'OCA\\Federation\\SyncFederationAddressBooks' => __DIR__ . '/..' . '/../lib/SyncFederationAddressBooks.php',
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function( $ ) {
|
(function( $ ) {
|
||||||
|
|
||||||
// ocFederationAddServer
|
// ocFederationAddServer
|
||||||
$.fn.ocFederationAddServer = function() {
|
$.fn.ocFederationAddServer = function() {
|
||||||
|
|
||||||
|
@ -27,14 +27,13 @@
|
||||||
========================================================================== */
|
========================================================================== */
|
||||||
|
|
||||||
var $wrapper = $(this),
|
var $wrapper = $(this),
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
$btnAddServer = $wrapper.find("#ocFederationAddServerButton"),
|
$btnAddServer = $wrapper.find("#ocFederationAddServerButton"),
|
||||||
$btnSubmit = $wrapper.find("#ocFederationSubmit"),
|
$btnSubmit = $wrapper.find("#ocFederationSubmit"),
|
||||||
|
|
||||||
// Inputs
|
// Inputs
|
||||||
$inpServerUrl = $wrapper.find("#serverUrl"),
|
$inpServerUrl = $wrapper.find("#serverUrl"),
|
||||||
$inpAutoAddServers = $wrapper.find("#autoAddServers"),
|
|
||||||
|
|
||||||
// misc
|
// misc
|
||||||
$msgBox = $wrapper.find("#ocFederationAddServer .msg"),
|
$msgBox = $wrapper.find("#ocFederationAddServer .msg"),
|
||||||
|
@ -55,17 +54,8 @@
|
||||||
$srvList.on('click', 'li > .icon-delete', function() {
|
$srvList.on('click', 'li > .icon-delete', function() {
|
||||||
var $this = $(this).parent();
|
var $this = $(this).parent();
|
||||||
var id = $this.attr('id');
|
var id = $this.attr('id');
|
||||||
|
|
||||||
removeServer( id );
|
|
||||||
});
|
|
||||||
|
|
||||||
$inpAutoAddServers.on("change", function() {
|
removeServer( id );
|
||||||
$.post(
|
|
||||||
OC.generateUrl('/apps/federation/auto-add-servers'),
|
|
||||||
{
|
|
||||||
autoAddServers: $(this).is(":checked")
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$btnSubmit.on("click", function()
|
$btnSubmit.on("click", function()
|
||||||
|
@ -94,7 +84,7 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/* private Functions
|
/* private Functions
|
||||||
========================================================================== */
|
========================================================================== */
|
||||||
|
|
||||||
|
@ -132,11 +122,11 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
})( jQuery );
|
})( jQuery );
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
||||||
$('#ocFederationSettings').ocFederationAddServer();
|
$('#ocFederationSettings').ocFederationAddServer();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
namespace OCA\Federation\AppInfo;
|
namespace OCA\Federation\AppInfo;
|
||||||
|
|
||||||
use OCA\Federation\DAV\FedAuth;
|
use OCA\Federation\DAV\FedAuth;
|
||||||
use OCA\Federation\Hooks;
|
|
||||||
use OCA\Federation\Middleware\AddServerMiddleware;
|
use OCA\Federation\Middleware\AddServerMiddleware;
|
||||||
use OCP\AppFramework\App;
|
use OCP\AppFramework\App;
|
||||||
use OCP\SabrePluginEvent;
|
use OCP\SabrePluginEvent;
|
||||||
|
@ -53,20 +52,8 @@ class Application extends App {
|
||||||
$container->registerMiddleWare('AddServerMiddleware');
|
$container->registerMiddleWare('AddServerMiddleware');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* listen to federated_share_added hooks to auto-add new servers to the
|
|
||||||
* list of trusted servers.
|
|
||||||
*/
|
|
||||||
public function registerHooks() {
|
public function registerHooks() {
|
||||||
$container = $this->getContainer();
|
$container = $this->getContainer();
|
||||||
$hooksManager = $container->query(Hooks::class);
|
|
||||||
|
|
||||||
Util::connectHook(
|
|
||||||
Share::class,
|
|
||||||
'federated_share_added',
|
|
||||||
$hooksManager,
|
|
||||||
'addServerHook'
|
|
||||||
);
|
|
||||||
|
|
||||||
$dispatcher = $container->getServer()->getEventDispatcher();
|
$dispatcher = $container->getServer()->getEventDispatcher();
|
||||||
$dispatcher->addListener('OCA\DAV\Connector\Sabre::authInit', function ($event) use ($container) {
|
$dispatcher->addListener('OCA\DAV\Connector\Sabre::authInit', function ($event) use ($container) {
|
||||||
|
|
|
@ -87,16 +87,6 @@ class SettingsController extends Controller {
|
||||||
return new DataResponse();
|
return new DataResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* enable/disable to automatically add servers to the list of trusted servers
|
|
||||||
* once a federated share was created and accepted successfully
|
|
||||||
*
|
|
||||||
* @param bool $autoAddServers
|
|
||||||
*/
|
|
||||||
public function autoAddServers($autoAddServers) {
|
|
||||||
$this->trustedServers->setAutoAddServers($autoAddServers);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the server should be added to the list of trusted servers or not
|
* check if the server should be added to the list of trusted servers or not
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
||||||
*
|
|
||||||
* @author Björn Schießle <bjoern@schiessle.org>
|
|
||||||
*
|
|
||||||
* @license AGPL-3.0
|
|
||||||
*
|
|
||||||
* This code is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License, version 3,
|
|
||||||
* as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* 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, version 3,
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace OCA\Federation;
|
|
||||||
|
|
||||||
class Hooks {
|
|
||||||
|
|
||||||
/** @var TrustedServers */
|
|
||||||
private $trustedServers;
|
|
||||||
|
|
||||||
public function __construct(TrustedServers $trustedServers) {
|
|
||||||
$this->trustedServers = $trustedServers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* add servers to the list of trusted servers once a federated share was established
|
|
||||||
*
|
|
||||||
* @param array $params
|
|
||||||
*/
|
|
||||||
public function addServerHook($params) {
|
|
||||||
if (
|
|
||||||
$this->trustedServers->getAutoAddServers() === true &&
|
|
||||||
$this->trustedServers->isTrustedServer($params['server']) === false
|
|
||||||
) {
|
|
||||||
$this->trustedServers->addServer($params['server']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -10,13 +10,6 @@ style('federation', 'settings-admin')
|
||||||
<h2><?php p($l->t('Trusted servers')); ?></h2>
|
<h2><?php p($l->t('Trusted servers')); ?></h2>
|
||||||
<p class="settings-hint"><?php p($l->t('Federation allows you to connect with other trusted servers to exchange the user directory. For example this will be used to auto-complete external users for federated sharing.')); ?></p>
|
<p class="settings-hint"><?php p($l->t('Federation allows you to connect with other trusted servers to exchange the user directory. For example this will be used to auto-complete external users for federated sharing.')); ?></p>
|
||||||
|
|
||||||
<p>
|
|
||||||
<input id="autoAddServers" type="checkbox" class="checkbox" <?php if ($_['autoAddServers']) {
|
|
||||||
p('checked');
|
|
||||||
} ?> />
|
|
||||||
<label for="autoAddServers"><?php p($l->t('Add server automatically once a federated share was created successfully')); ?></label>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<ul id="listOfTrustedServers">
|
<ul id="listOfTrustedServers">
|
||||||
<?php foreach ($_['trustedServers'] as $trustedServer) { ?>
|
<?php foreach ($_['trustedServers'] as $trustedServer) { ?>
|
||||||
<li id="<?php p($trustedServer['id']); ?>">
|
<li id="<?php p($trustedServer['id']); ?>">
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
||||||
*
|
|
||||||
* @author Björn Schießle <bjoern@schiessle.org>
|
|
||||||
* @author Joas Schilling <coding@schilljs.com>
|
|
||||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
||||||
*
|
|
||||||
* @license AGPL-3.0
|
|
||||||
*
|
|
||||||
* This code is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License, version 3,
|
|
||||||
* as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* 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, version 3,
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace OCA\Federation\Tests;
|
|
||||||
|
|
||||||
use OCA\Federation\Hooks;
|
|
||||||
use OCA\Federation\TrustedServers;
|
|
||||||
use Test\TestCase;
|
|
||||||
|
|
||||||
class HooksTest extends TestCase {
|
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject | TrustedServers */
|
|
||||||
private $trustedServers;
|
|
||||||
|
|
||||||
/** @var Hooks */
|
|
||||||
private $hooks;
|
|
||||||
|
|
||||||
protected function setUp(): void {
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$this->trustedServers = $this->getMockBuilder('OCA\Federation\TrustedServers')
|
|
||||||
->disableOriginalConstructor()->getMock();
|
|
||||||
|
|
||||||
$this->hooks = new Hooks($this->trustedServers);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider dataTestAddServerHook
|
|
||||||
*
|
|
||||||
* @param bool $autoAddEnabled is auto-add enabled
|
|
||||||
* @param bool $isTrustedServer is the server already in the list of trusted servers
|
|
||||||
* @param bool $addServer should the server be added
|
|
||||||
*/
|
|
||||||
public function testAddServerHook($autoAddEnabled, $isTrustedServer, $addServer) {
|
|
||||||
$this->trustedServers->expects($this->any())->method('getAutoAddServers')
|
|
||||||
->willReturn($autoAddEnabled);
|
|
||||||
$this->trustedServers->expects($this->any())->method('isTrustedServer')
|
|
||||||
->with('url')->willReturn($isTrustedServer);
|
|
||||||
|
|
||||||
if ($addServer) {
|
|
||||||
$this->trustedServers->expects($this->once())->method('addServer')
|
|
||||||
->with('url');
|
|
||||||
} else {
|
|
||||||
$this->trustedServers->expects($this->never())->method('addServer');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->hooks->addServerHook(['server' => 'url']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dataTestAddServerHook() {
|
|
||||||
return [
|
|
||||||
[true, true, false],
|
|
||||||
[false, true, false],
|
|
||||||
[true, false, true],
|
|
||||||
[false, false, false],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue