From f6cd5200a20f7adfe3b3f7b48d0ade4a75829a31 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 9 Feb 2017 13:31:06 +0100 Subject: [PATCH] clean cloud ids Signed-off-by: Robin Appelman --- .../lib/FederatedShareProvider.php | 2 +- lib/private/Federation/CloudIdManager.php | 5 ++--- tests/lib/Federation/CloudIdManagerTest.php | 14 +++++++------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/apps/federatedfilesharing/lib/FederatedShareProvider.php b/apps/federatedfilesharing/lib/FederatedShareProvider.php index b8a584ce6b..fb49978b7a 100644 --- a/apps/federatedfilesharing/lib/FederatedShareProvider.php +++ b/apps/federatedfilesharing/lib/FederatedShareProvider.php @@ -171,7 +171,7 @@ class FederatedShareProvider implements IShareProvider { } - $share->setSharedWith(rtrim($cloudId->getId(), '/')); + $share->setSharedWith($cloudId->getId()); try { $remoteShare = $this->getShareFromExternalShareTable($share); diff --git a/lib/private/Federation/CloudIdManager.php b/lib/private/Federation/CloudIdManager.php index 0df8f080d2..2e6232fa86 100644 --- a/lib/private/Federation/CloudIdManager.php +++ b/lib/private/Federation/CloudIdManager.php @@ -34,7 +34,7 @@ class CloudIdManager implements ICloudIdManager { } // Find the first character that is not allowed in user names - $id = str_replace('\\', '/', $cloudId); + $id = $this->fixRemoteURL($cloudId); $posSlash = strpos($id, '/'); $posColon = strpos($id, ':'); @@ -58,9 +58,8 @@ class CloudIdManager implements ICloudIdManager { if ($pos !== false) { $user = substr($id, 0, $pos); $remote = substr($id, $pos + 1); - $remote = $this->fixRemoteURL($remote); if (!empty($user) && !empty($remote)) { - return new CloudId($cloudId, $user, $remote); + return new CloudId($id, $user, $remote); } } throw new \InvalidArgumentException('Invalid cloud id'); diff --git a/tests/lib/Federation/CloudIdManagerTest.php b/tests/lib/Federation/CloudIdManagerTest.php index 3f1cfabe20..fe673588bb 100644 --- a/tests/lib/Federation/CloudIdManagerTest.php +++ b/tests/lib/Federation/CloudIdManagerTest.php @@ -35,12 +35,11 @@ class CloudIdManagerTest extends TestCase { public function cloudIdProvider() { return [ - ['test@example.com', 'test', 'example.com'], - ['test@example.com/cloud', 'test', 'example.com/cloud'], - ['test@example.com/cloud/', 'test', 'example.com/cloud'], - ['test@example.com/cloud/index.php', 'test', 'example.com/cloud'], - ['test@example.com@example.com', 'test@example.com', 'example.com'], - ['test@example.com@example.com', 'test@example.com', 'example.com'], + ['test@example.com', 'test', 'example.com', 'test@example.com'], + ['test@example.com/cloud', 'test', 'example.com/cloud', 'test@example.com/cloud'], + ['test@example.com/cloud/', 'test', 'example.com/cloud', 'test@example.com/cloud'], + ['test@example.com/cloud/index.php', 'test', 'example.com/cloud', 'test@example.com/cloud'], + ['test@example.com@example.com', 'test@example.com', 'example.com', 'test@example.com@example.com'], ]; } @@ -51,11 +50,12 @@ class CloudIdManagerTest extends TestCase { * @param string $user * @param string $remote */ - public function testResolveCloudId($cloudId, $user, $remote) { + public function testResolveCloudId($cloudId, $user, $remote, $cleanId) { $cloudId = $this->cloudIdManager->resolveCloudId($cloudId); $this->assertEquals($user, $cloudId->getUser()); $this->assertEquals($remote, $cloudId->getRemote()); + $this->assertEquals($cleanId, $cloudId->getId()); } public function invalidCloudIdProvider() {