summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/federation/lib/BackgroundJob/GetSharedSecret.php7
-rw-r--r--apps/federation/lib/BackgroundJob/RequestSharedSecret.php7
-rw-r--r--apps/federation/tests/BackgroundJob/GetSharedSecretTest.php38
-rw-r--r--apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php38
-rw-r--r--lib/private/Files/View.php6
-rw-r--r--lib/private/Server.php32
6 files changed, 125 insertions, 3 deletions
diff --git a/apps/federation/lib/BackgroundJob/GetSharedSecret.php b/apps/federation/lib/BackgroundJob/GetSharedSecret.php
index 6090f521fcc..92bb31e369e 100644
--- a/apps/federation/lib/BackgroundJob/GetSharedSecret.php
+++ b/apps/federation/lib/BackgroundJob/GetSharedSecret.php
@@ -32,6 +32,8 @@ namespace OCA\Federation\BackgroundJob;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ConnectException;
+use GuzzleHttp\Exception\RequestException;
+use GuzzleHttp\Ring\Exception\RingException;
use OC\BackgroundJob\JobList;
use OC\BackgroundJob\Job;
use OCA\Federation\DbHandler;
@@ -197,7 +199,10 @@ class GetSharedSecret extends Job {
} else {
$this->logger->info($target . ' responded with a ' . $status . ' containing: ' . $e->getMessage(), ['app' => 'federation']);
}
- } catch (ConnectException $e) {
+ } catch (RequestException $e) {
+ $status = -1; // There is no status code if we could not connect
+ $this->logger->info('Could not connect to ' . $target, ['app' => 'federation']);
+ } catch (RingException $e) {
$status = -1; // There is no status code if we could not connect
$this->logger->info('Could not connect to ' . $target, ['app' => 'federation']);
} catch (\Exception $e) {
diff --git a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php
index a201c9dccb6..ad7504da7ad 100644
--- a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php
+++ b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php
@@ -33,6 +33,8 @@ namespace OCA\Federation\BackgroundJob;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ConnectException;
+use GuzzleHttp\Exception\RequestException;
+use GuzzleHttp\Ring\Exception\RingException;
use OC\BackgroundJob\JobList;
use OC\BackgroundJob\Job;
use OCA\Federation\DbHandler;
@@ -197,7 +199,10 @@ class RequestSharedSecret extends Job {
} else {
$this->logger->info($target . ' responded with a ' . $status . ' containing: ' . $e->getMessage(), ['app' => 'federation']);
}
- } catch (ConnectException $e) {
+ } catch (RequestException $e) {
+ $status = -1; // There is no status code if we could not connect
+ $this->logger->info('Could not connect to ' . $target, ['app' => 'federation']);
+ } catch (RingException $e) {
$status = -1; // There is no status code if we could not connect
$this->logger->info('Could not connect to ' . $target, ['app' => 'federation']);
} catch (\Exception $e) {
diff --git a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
index 2058b2592c8..1e264919e78 100644
--- a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
+++ b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
@@ -29,6 +29,7 @@ namespace OCA\Federation\Tests\BackgroundJob;
use GuzzleHttp\Exception\ConnectException;
+use GuzzleHttp\Ring\Exception\RingException;
use OCA\Federation\BackgroundJob\GetSharedSecret;
use OCA\Files_Sharing\Tests\TestCase;
use OCA\Federation\DbHandler;
@@ -315,4 +316,41 @@ class GetSharedSecretTest extends TestCase {
$this->assertTrue($this->invokePrivate($this->getSharedSecret, 'retainJob'));
}
+
+ public function testRunRingException() {
+ $target = 'targetURL';
+ $source = 'sourceURL';
+ $token = 'token';
+
+ $argument = ['url' => $target, 'token' => $token];
+
+ $this->timeFactory->method('getTime')
+ ->willReturn(42);
+
+ $this->urlGenerator
+ ->expects($this->once())
+ ->method('getAbsoluteURL')
+ ->with('/')
+ ->willReturn($source);
+ $this->httpClient->expects($this->once())->method('get')
+ ->with(
+ $target . '/ocs/v2.php/apps/federation/api/v1/shared-secret?format=json',
+ [
+ 'query' =>
+ [
+ 'url' => $source,
+ 'token' => $token
+ ],
+ 'timeout' => 3,
+ 'connect_timeout' => 3,
+ ]
+ )->willThrowException($this->createMock(RingException::class));
+
+ $this->dbHandler->expects($this->never())->method('addToken');
+ $this->trustedServers->expects($this->never())->method('addSharedSecret');
+
+ $this->invokePrivate($this->getSharedSecret, 'run', [$argument]);
+
+ $this->assertTrue($this->invokePrivate($this->getSharedSecret, 'retainJob'));
+ }
}
diff --git a/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php b/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
index 57a85f1be0b..20610f1f0fb 100644
--- a/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
+++ b/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
@@ -28,6 +28,7 @@ namespace OCA\Federation\Tests\BackgroundJob;
use GuzzleHttp\Exception\ConnectException;
+use GuzzleHttp\Ring\Exception\RingException;
use OCA\Federation\BackgroundJob\RequestSharedSecret;
use OCA\Federation\DbHandler;
use OCA\Federation\TrustedServers;
@@ -300,4 +301,41 @@ class RequestSharedSecretTest extends TestCase {
$this->invokePrivate($this->requestSharedSecret, 'run', [$argument]);
$this->assertTrue($this->invokePrivate($this->requestSharedSecret, 'retainJob'));
}
+
+ public function testRunRingException() {
+ $target = 'targetURL';
+ $source = 'sourceURL';
+ $token = 'token';
+
+ $argument = ['url' => $target, 'token' => $token];
+
+ $this->timeFactory->method('getTime')->willReturn(42);
+
+ $this->urlGenerator
+ ->expects($this->once())
+ ->method('getAbsoluteURL')
+ ->with('/')
+ ->willReturn($source);
+
+ $this->httpClient
+ ->expects($this->once())
+ ->method('post')
+ ->with(
+ $target . '/ocs/v2.php/apps/federation/api/v1/request-shared-secret?format=json',
+ [
+ 'body' =>
+ [
+ 'url' => $source,
+ 'token' => $token
+ ],
+ 'timeout' => 3,
+ 'connect_timeout' => 3,
+ ]
+ )->willThrowException($this->createMock(RingException::class));
+
+ $this->dbHandler->expects($this->never())->method('addToken');
+
+ $this->invokePrivate($this->requestSharedSecret, 'run', [$argument]);
+ $this->assertTrue($this->invokePrivate($this->requestSharedSecret, 'retainJob'));
+ }
}
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index 58552be2609..592d4b717ce 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -1362,6 +1362,9 @@ class View {
$path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
$mount = Filesystem::getMountManager()->find($path);
+ if (!$mount) {
+ return false;
+ }
$storage = $mount->getStorage();
$internalPath = $mount->getInternalPath($path);
if ($storage) {
@@ -1411,6 +1414,9 @@ class View {
$path = $this->getAbsolutePath($directory);
$path = Filesystem::normalizePath($path);
$mount = $this->getMount($directory);
+ if (!$mount) {
+ return [];
+ }
$storage = $mount->getStorage();
$internalPath = $mount->getInternalPath($path);
if ($storage) {
diff --git a/lib/private/Server.php b/lib/private/Server.php
index f4f7cb75ad1..0dfbcbb75ec 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -118,12 +118,14 @@ use OCP\Defaults;
use OCA\Theming\Util;
use OCP\Federation\ICloudIdManager;
use OCP\Authentication\LoginCredentials\IStore;
+use OCP\Files\NotFoundException;
use OCP\ICacheFactory;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IServerContainer;
use OCP\ITempManager;
use OCP\Contacts\ContactsMenu\IActionFactory;
+use OCP\IUser;
use OCP\Lock\ILockingProvider;
use OCP\Remote\Api\IApiFactory;
use OCP\Remote\IInstanceFactory;
@@ -133,6 +135,7 @@ use OCP\Share;
use OCP\Share\IShareHelper;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Class Server
@@ -348,6 +351,8 @@ class Server extends ServerContainer implements IServerContainer {
$defaultTokenProvider = null;
}
+ $dispatcher = $c->getEventDispatcher();
+
$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
@@ -356,9 +361,10 @@ class Server extends ServerContainer implements IServerContainer {
/** @var $user \OC\User\User */
\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
});
- $userSession->listen('\OC\User', 'preDelete', function ($user) {
+ $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
/** @var $user \OC\User\User */
\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
+ $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
});
$userSession->listen('\OC\User', 'postDelete', function ($user) {
/** @var $user \OC\User\User */
@@ -1122,6 +1128,8 @@ class Server extends ServerContainer implements IServerContainer {
$memcacheFactory = $c->getMemCacheFactory();
return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
});
+
+ $this->connectDispatcher();
}
/**
@@ -1131,6 +1139,28 @@ class Server extends ServerContainer implements IServerContainer {
return $this->query('CalendarManager');
}
+ private function connectDispatcher() {
+ $dispatcher = $this->getEventDispatcher();
+
+ // Delete avatar on user deletion
+ $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
+ $logger = $this->getLogger();
+ $manager = $this->getAvatarManager();
+ /** @var IUser $user */
+ $user = $e->getSubject();
+
+ try {
+ $avatar = $manager->getAvatar($user->getUID());
+ $avatar->remove();
+ } catch (NotFoundException $e) {
+ // no avatar to remove
+ } catch (\Exception $e) {
+ // Ignore exceptions
+ $logger->info('Could not cleanup avatar of ' . $user->getUID());
+ }
+ });
+ }
+
/**
* @return \OCP\Contacts\IManager
*/