summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2018-01-16 21:10:53 +0100
committerGitHub <noreply@github.com>2018-01-16 21:10:53 +0100
commite7605d9adc80ce586b6f1c55507360750e2e5693 (patch)
tree942331a4c1cc4ce3f98a94e044f3b112d44400be
parent34e112739d12f8c21017a22bbfd57ca707af5f82 (diff)
parentfde1ada916c092b2255b6e0eb736a66edfa78c41 (diff)
downloadnextcloud-server-e7605d9adc80ce586b6f1c55507360750e2e5693.tar.gz
nextcloud-server-e7605d9adc80ce586b6f1c55507360750e2e5693.zip
Merge pull request #7892 from nextcloud/cloudid_strict
Make OCP\Federation strict
-rw-r--r--apps/federatedfilesharing/tests/FederatedShareProviderTest.php18
-rw-r--r--lib/private/Federation/CloudId.php11
-rw-r--r--lib/private/Federation/CloudIdManager.php11
-rw-r--r--lib/public/Federation/ICloudId.php9
-rw-r--r--lib/public/Federation/ICloudIdManager.php7
5 files changed, 39 insertions, 17 deletions
diff --git a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
index 0a6d95d9d9e..52266383b36 100644
--- a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
+++ b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
@@ -490,6 +490,9 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->addressHandler->expects($this->at(1))->method('splitUserRemote')
->willReturn(['user2', 'server.com']);
+ $this->addressHandler->method('generateRemoteURL')
+ ->willReturn('remoteurl.com');
+
$this->tokenHandler->method('generateToken')->willReturn('token');
$this->notifications
->method('sendRemoteShare')
@@ -532,6 +535,9 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->rootFolder->expects($this->never())->method($this->anything());
+ $this->addressHandler->method('generateRemoteURL')
+ ->willReturn('remoteurl.com');
+
$share = $this->shareManager->newShare();
$share->setSharedWith('user@server.com')
->setSharedBy('sharedBy')
@@ -570,6 +576,9 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->rootFolder->expects($this->never())->method($this->anything());
+ $this->addressHandler->method('generateRemoteURL')
+ ->willReturn('remoteurl.com');
+
$share = $this->shareManager->newShare();
$share->setSharedWith('user@server.com')
->setSharedBy('shareOwner')
@@ -611,6 +620,9 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->rootFolder->expects($this->never())->method($this->anything());
+ $this->addressHandler->method('generateRemoteURL')
+ ->willReturn('remoteurl.com');
+
$share = $this->shareManager->newShare();
$share->setSharedWith('user@server.com')
->setSharedBy('sharedBy')
@@ -806,6 +818,9 @@ class FederatedShareProviderTest extends \Test\TestCase {
->method('sendRemoteShare')
->willReturn(true);
+ $this->addressHandler->method('generateRemoteURL')
+ ->willReturn('remoteurl.com');
+
$share1 = $this->shareManager->newShare();
$share1->setSharedWith('user@server.com')
->setSharedBy($u1->getUID())
@@ -857,6 +872,9 @@ class FederatedShareProviderTest extends \Test\TestCase {
$result = $this->provider->getAccessList([$file1], false);
$this->assertEquals(['remote' => false], $result);
+ $this->addressHandler->method('generateRemoteURL')
+ ->willReturn('remoteurl.com');
+
$share1 = $this->shareManager->newShare();
$share1->setSharedWith('user@server.com')
->setSharedBy($u1->getUID())
diff --git a/lib/private/Federation/CloudId.php b/lib/private/Federation/CloudId.php
index f1d08f0687d..4c93650e0fc 100644
--- a/lib/private/Federation/CloudId.php
+++ b/lib/private/Federation/CloudId.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2017, Robin Appelman <robin@icewind.nl>
*
@@ -40,7 +41,7 @@ class CloudId implements ICloudId {
* @param string $user
* @param string $remote
*/
- public function __construct($id, $user, $remote) {
+ public function __construct(string $id, string $user, string $remote) {
$this->id = $id;
$this->user = $user;
$this->remote = $remote;
@@ -51,11 +52,11 @@ class CloudId implements ICloudId {
*
* @return string
*/
- public function getId() {
+ public function getId(): string {
return $this->id;
}
- public function getDisplayId() {
+ public function getDisplayId(): string {
return str_replace('https://', '', str_replace('http://', '', $this->getId()));
}
@@ -64,7 +65,7 @@ class CloudId implements ICloudId {
*
* @return string
*/
- public function getUser() {
+ public function getUser(): string {
return $this->user;
}
@@ -73,7 +74,7 @@ class CloudId implements ICloudId {
*
* @return string
*/
- public function getRemote() {
+ public function getRemote(): string {
return $this->remote;
}
}
diff --git a/lib/private/Federation/CloudIdManager.php b/lib/private/Federation/CloudIdManager.php
index 3b7aaae5392..0beb6cf6d29 100644
--- a/lib/private/Federation/CloudIdManager.php
+++ b/lib/private/Federation/CloudIdManager.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2017, Robin Appelman <robin@icewind.nl>
*
@@ -33,7 +34,7 @@ class CloudIdManager implements ICloudIdManager {
* @return ICloudId
* @throws \InvalidArgumentException
*/
- public function resolveCloudId($cloudId) {
+ public function resolveCloudId(string $cloudId): ICloudId {
// TODO magic here to get the url and user instead of just splitting on @
if (!$this->isValidCloudId($cloudId)) {
@@ -46,7 +47,7 @@ class CloudIdManager implements ICloudIdManager {
$posColon = strpos($id, ':');
if ($posSlash === false && $posColon === false) {
- $invalidPos = strlen($id);
+ $invalidPos = \strlen($id);
} else if ($posSlash === false) {
$invalidPos = $posColon;
} else if ($posColon === false) {
@@ -77,7 +78,7 @@ class CloudIdManager implements ICloudIdManager {
* @param string $remote
* @return CloudId
*/
- public function getCloudId($user, $remote) {
+ public function getCloudId(string $user, string $remote): ICloudId {
// TODO check what the correct url is for remote (asking the remote)
return new CloudId($user. '@' . $remote, $user, $remote);
}
@@ -94,7 +95,7 @@ class CloudIdManager implements ICloudIdManager {
* @param string $remote
* @return string
*/
- protected function fixRemoteURL($remote) {
+ protected function fixRemoteURL(string $remote): string {
$remote = str_replace('\\', '/', $remote);
if ($fileNamePosition = strpos($remote, '/index.php')) {
$remote = substr($remote, 0, $fileNamePosition);
@@ -108,7 +109,7 @@ class CloudIdManager implements ICloudIdManager {
* @param string $cloudId
* @return bool
*/
- public function isValidCloudId($cloudId) {
+ public function isValidCloudId(string $cloudId): bool {
return strpos($cloudId, '@') !== false;
}
}
diff --git a/lib/public/Federation/ICloudId.php b/lib/public/Federation/ICloudId.php
index b03acb4f5f2..6cc17984f96 100644
--- a/lib/public/Federation/ICloudId.php
+++ b/lib/public/Federation/ICloudId.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2017, Robin Appelman <robin@icewind.nl>
*
@@ -35,7 +36,7 @@ interface ICloudId {
* @return string
* @since 12.0.0
*/
- public function getId();
+ public function getId(): string;
/**
* Get a clean representation of the cloud id for display
@@ -43,7 +44,7 @@ interface ICloudId {
* @return string
* @since 12.0.0
*/
- public function getDisplayId();
+ public function getDisplayId(): string;
/**
* The username on the remote server
@@ -51,7 +52,7 @@ interface ICloudId {
* @return string
* @since 12.0.0
*/
- public function getUser();
+ public function getUser(): string;
/**
* The base address of the remote server
@@ -59,5 +60,5 @@ interface ICloudId {
* @return string
* @since 12.0.0
*/
- public function getRemote();
+ public function getRemote(): string;
}
diff --git a/lib/public/Federation/ICloudIdManager.php b/lib/public/Federation/ICloudIdManager.php
index b5b3436e6fc..c139cfda6cd 100644
--- a/lib/public/Federation/ICloudIdManager.php
+++ b/lib/public/Federation/ICloudIdManager.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2017, Robin Appelman <robin@icewind.nl>
*
@@ -37,7 +38,7 @@ interface ICloudIdManager {
*
* @since 12.0.0
*/
- public function resolveCloudId($cloudId);
+ public function resolveCloudId(string $cloudId): ICloudId;
/**
* Get the cloud id for a remote user
@@ -48,7 +49,7 @@ interface ICloudIdManager {
*
* @since 12.0.0
*/
- public function getCloudId($user, $remote);
+ public function getCloudId(string $user, string $remote): ICloudId;
/**
* Check if the input is a correctly formatted cloud id
@@ -58,5 +59,5 @@ interface ICloudIdManager {
*
* @since 12.0.0
*/
- public function isValidCloudId($cloudId);
+ public function isValidCloudId(string $cloudId): bool;
}