Merge pull request #26780 from nextcloud/backport/26765/stable19

[stable19] No longer add trusted servers on federated share creation
This commit is contained in:
Roeland Jago Douma 2021-04-29 08:19:44 +02:00 committed by GitHub
commit 4369d1cf1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 32 additions and 207 deletions

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -34,11 +34,6 @@ return [
'url' => '/trusted-servers/{id}',
'verb' => 'DELETE'
],
[
'name' => 'Settings#autoAddServers',
'url' => '/auto-add-servers',
'verb' => 'POST'
],
],
'ocs' => [
// old endpoints, only used by Nextcloud and ownCloud

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -14,7 +14,6 @@ return array(
'OCA\\Federation\\Controller\\SettingsController' => $baseDir . '/../lib/Controller/SettingsController.php',
'OCA\\Federation\\DAV\\FedAuth' => $baseDir . '/../lib/DAV/FedAuth.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\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php',
'OCA\\Federation\\SyncFederationAddressBooks' => $baseDir . '/../lib/SyncFederationAddressBooks.php',

View File

@ -29,7 +29,6 @@ class ComposerStaticInitFederation
'OCA\\Federation\\Controller\\SettingsController' => __DIR__ . '/..' . '/../lib/Controller/SettingsController.php',
'OCA\\Federation\\DAV\\FedAuth' => __DIR__ . '/..' . '/../lib/DAV/FedAuth.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\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php',
'OCA\\Federation\\SyncFederationAddressBooks' => __DIR__ . '/..' . '/../lib/SyncFederationAddressBooks.php',

View File

@ -19,7 +19,7 @@
*/
(function( $ ) {
// ocFederationAddServer
$.fn.ocFederationAddServer = function() {
@ -27,14 +27,13 @@
========================================================================== */
var $wrapper = $(this),
// Buttons
$btnAddServer = $wrapper.find("#ocFederationAddServerButton"),
$btnSubmit = $wrapper.find("#ocFederationSubmit"),
// Inputs
$inpServerUrl = $wrapper.find("#serverUrl"),
$inpAutoAddServers = $wrapper.find("#autoAddServers"),
// misc
$msgBox = $wrapper.find("#ocFederationAddServer .msg"),
@ -55,17 +54,8 @@
$srvList.on('click', 'li > .icon-delete', function() {
var $this = $(this).parent();
var id = $this.attr('id');
removeServer( id );
});
$inpAutoAddServers.on("change", function() {
$.post(
OC.generateUrl('/apps/federation/auto-add-servers'),
{
autoAddServers: $(this).is(":checked")
}
);
removeServer( id );
});
$btnSubmit.on("click", function()
@ -94,7 +84,7 @@
}
});
};
/* private Functions
========================================================================== */
@ -132,11 +122,11 @@
});
}
})( jQuery );
$(document).ready(function () {
$('#ocFederationSettings').ocFederationAddServer();
});

View File

@ -28,12 +28,9 @@
namespace OCA\Federation\AppInfo;
use OCA\Federation\DAV\FedAuth;
use OCA\Federation\Hooks;
use OCA\Federation\Middleware\AddServerMiddleware;
use OCP\AppFramework\App;
use OCP\SabrePluginEvent;
use OCP\Share;
use OCP\Util;
use Sabre\DAV\Auth\Plugin;
use Sabre\DAV\Server;
@ -53,20 +50,8 @@ class Application extends App {
$container->registerMiddleWare('AddServerMiddleware');
}
/**
* listen to federated_share_added hooks to auto-add new servers to the
* list of trusted servers.
*/
public function registerHooks() {
$container = $this->getContainer();
$hooksManager = $container->query(Hooks::class);
Util::connectHook(
Share::class,
'federated_share_added',
$hooksManager,
'addServerHook'
);
$dispatcher = $container->getServer()->getEventDispatcher();
$dispatcher->addListener('OCA\DAV\Connector\Sabre::authInit', function ($event) use ($container) {

View File

@ -87,16 +87,6 @@ class SettingsController extends Controller {
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
*

View File

@ -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']);
}
}
}

View File

@ -10,13 +10,6 @@ style('federation', 'settings-admin')
<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>
<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">
<?php foreach ($_['trustedServers'] as $trustedServer) { ?>
<li id="<?php p($trustedServer['id']); ?>">

View File

@ -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],
];
}
}

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();

View File

@ -60,7 +60,7 @@ class ClassLoader
public function getPrefixes()
{
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();