Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/federatedfilesharing/tests/FederatedShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ public function testGetSharedBy() {
$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')
Expand Down Expand Up @@ -532,6 +535,9 @@ public function testGetSharedByWithNode() {

$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')
Expand Down Expand Up @@ -570,6 +576,9 @@ public function testGetSharedByWithReshares() {

$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')
Expand Down Expand Up @@ -611,6 +620,9 @@ public function testGetSharedByWithLimit() {

$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')
Expand Down Expand Up @@ -806,6 +818,9 @@ public function testGetSharesInFolder() {
->method('sendRemoteShare')
->willReturn(true);

$this->addressHandler->method('generateRemoteURL')
->willReturn('remoteurl.com');

$share1 = $this->shareManager->newShare();
$share1->setSharedWith('user@server.com')
->setSharedBy($u1->getUID())
Expand Down Expand Up @@ -857,6 +872,9 @@ public function testGetAccessList() {
$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())
Expand Down
11 changes: 6 additions & 5 deletions lib/private/Federation/CloudId.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017, Robin Appelman <robin@icewind.nl>
*
Expand Down Expand Up @@ -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;
Expand All @@ -51,11 +52,11 @@ public function __construct($id, $user, $remote) {
*
* @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()));
}

Expand All @@ -64,7 +65,7 @@ public function getDisplayId() {
*
* @return string
*/
public function getUser() {
public function getUser(): string {
return $this->user;
}

Expand All @@ -73,7 +74,7 @@ public function getUser() {
*
* @return string
*/
public function getRemote() {
public function getRemote(): string {
return $this->remote;
}
}
11 changes: 6 additions & 5 deletions lib/private/Federation/CloudIdManager.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017, Robin Appelman <robin@icewind.nl>
*
Expand Down Expand Up @@ -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)) {
Expand All @@ -46,7 +47,7 @@ public function resolveCloudId($cloudId) {
$posColon = strpos($id, ':');

if ($posSlash === false && $posColon === false) {
$invalidPos = strlen($id);
$invalidPos = \strlen($id);
} else if ($posSlash === false) {
$invalidPos = $posColon;
} else if ($posColon === false) {
Expand Down Expand Up @@ -77,7 +78,7 @@ public function resolveCloudId($cloudId) {
* @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);
}
Expand All @@ -94,7 +95,7 @@ public function getCloudId($user, $remote) {
* @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);
Expand All @@ -108,7 +109,7 @@ protected function fixRemoteURL($remote) {
* @param string $cloudId
* @return bool
*/
public function isValidCloudId($cloudId) {
public function isValidCloudId(string $cloudId): bool {
return strpos($cloudId, '@') !== false;
}
}
9 changes: 5 additions & 4 deletions lib/public/Federation/ICloudId.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017, Robin Appelman <robin@icewind.nl>
*
Expand Down Expand Up @@ -35,29 +36,29 @@ 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
*
* @return string
* @since 12.0.0
*/
public function getDisplayId();
public function getDisplayId(): string;

/**
* The username on the remote server
*
* @return string
* @since 12.0.0
*/
public function getUser();
public function getUser(): string;

/**
* The base address of the remote server
*
* @return string
* @since 12.0.0
*/
public function getRemote();
public function getRemote(): string;
}
7 changes: 4 additions & 3 deletions lib/public/Federation/ICloudIdManager.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017, Robin Appelman <robin@icewind.nl>
*
Expand Down Expand Up @@ -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
Expand All @@ -48,7 +49,7 @@ public function resolveCloudId($cloudId);
*
* @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
Expand All @@ -58,5 +59,5 @@ public function getCloudId($user, $remote);
*
* @since 12.0.0
*/
public function isValidCloudId($cloudId);
public function isValidCloudId(string $cloudId): bool;
}