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
11 changes: 10 additions & 1 deletion apps/federatedfilesharing/tests/AddressHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@

use OC\Federation\CloudIdManager;
use OCA\FederatedFileSharing\AddressHandler;
use OCP\Contacts\IManager;
use OCP\IL10N;
use OCP\IURLGenerator;

class AddressHandlerTest extends \Test\TestCase {
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
protected $contactsManager;

/** @var AddressHandler */
private $addressHandler;
Expand All @@ -54,7 +57,9 @@ protected function setUp(): void {
$this->il10n = $this->getMockBuilder(IL10N::class)
->getMock();

$this->cloudIdManager = new CloudIdManager();
$this->contactsManager = $this->createMock(IManager::class);

$this->cloudIdManager = new CloudIdManager($this->contactsManager);

$this->addressHandler = new AddressHandler($this->urlGenerator, $this->il10n, $this->cloudIdManager);
}
Expand Down Expand Up @@ -98,6 +103,10 @@ public function dataTestSplitUserRemote() {
* @param string $expectedUrl
*/
public function testSplitUserRemote($remote, $expectedUser, $expectedUrl) {
$this->contactsManager->expects($this->any())
->method('search')
->willReturn([]);

list($remoteUser, $remoteUrl) = $this->addressHandler->splitUserRemote($remote);
$this->assertSame($expectedUser, $remoteUser);
$this->assertSame($expectedUrl, $remoteUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCA\FederatedFileSharing\Controller\MountPublicLinkController;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\AppFramework\Http;
use OCP\Contacts\IManager as IContactsManager;
use OCP\Federation\ICloudIdManager;
use OCP\Files\IRootFolder;
use OCP\Http\Client\IClientService;
Expand All @@ -46,6 +47,8 @@
use OCP\Share\IShare;

class MountPublicLinkControllerTest extends \Test\TestCase {
/** @var IContactsManager|\PHPUnit\Framework\MockObject\MockObject */
protected $contactsManager;

/** @var MountPublicLinkController */
private $controller;
Expand Down Expand Up @@ -102,7 +105,8 @@ protected function setUp(): void {
$this->l10n = $this->getMockBuilder(IL10N::class)->disableOriginalConstructor()->getMock();
$this->userSession = $this->getMockBuilder(IUserSession::class)->disableOriginalConstructor()->getMock();
$this->clientService = $this->getMockBuilder('OCP\Http\Client\IClientService')->disableOriginalConstructor()->getMock();
$this->cloudIdManager = new CloudIdManager();
$this->contactsManager = $this->createMock(IContactsManager::class);
$this->cloudIdManager = new CloudIdManager($this->contactsManager);

$this->controller = new MountPublicLinkController(
'federatedfilesharing', $this->request,
Expand Down
59 changes: 56 additions & 3 deletions apps/federatedfilesharing/tests/FederatedShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\FederatedFileSharing\Notifications;
use OCA\FederatedFileSharing\TokenHandler;
use OCP\Contacts\IManager as IContactsManager;
use OCP\Federation\ICloudFederationProviderManager;
use OCP\Federation\ICloudIdManager;
use OCP\Files\File;
Expand Down Expand Up @@ -79,6 +80,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
protected $shareManager;
/** @var FederatedShareProvider */
protected $provider;
/** @var IContactsManager|\PHPUnit\Framework\MockObject\MockObject */
protected $contactsManager;

/** @var ICloudIdManager */
private $cloudIdManager;
Expand Down Expand Up @@ -107,7 +110,8 @@ protected function setUp(): void {
$this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
//$this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l);
$this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler')->disableOriginalConstructor()->getMock();
$this->cloudIdManager = new CloudIdManager();
$this->contactsManager = $this->createMock(IContactsManager::class);
$this->cloudIdManager = new CloudIdManager($this->contactsManager);
$this->gsConfig = $this->createMock(\OCP\GlobalScale\IConfig::class);

$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
Expand Down Expand Up @@ -141,6 +145,7 @@ protected function tearDown(): void {
public function testCreate() {
$share = $this->shareManager->newShare();

/** @var File|MockObject $node */
$node = $this->getMockBuilder(File::class)->getMock();
$node->method('getId')->willReturn(42);
$node->method('getName')->willReturn('myFile');
Expand Down Expand Up @@ -170,10 +175,15 @@ public function testCreate() {
'shareOwner@http://localhost/',
'sharedBy',
'sharedBy@http://localhost/'
)->willReturn(true);
)
->willReturn(true);

$this->rootFolder->expects($this->never())->method($this->anything());

$this->contactsManager->expects($this->any())
->method('search')
->willReturn([]);

$share = $this->provider->create($share);

$qb = $this->connection->getQueryBuilder();
Expand Down Expand Up @@ -250,6 +260,10 @@ public function testCreateCouldNotFindServer() {
->with('42')
->willReturn([$node]);

$this->contactsManager->expects($this->any())
->method('search')
->willReturn([]);

try {
$share = $this->provider->create($share);
$this->fail();
Expand Down Expand Up @@ -307,6 +321,10 @@ public function testCreateException() {
->with('42')
->willReturn([$node]);

$this->contactsManager->expects($this->any())
->method('search')
->willReturn([]);

try {
$share = $this->provider->create($share);
$this->fail();
Expand Down Expand Up @@ -344,6 +362,10 @@ public function testCreateShareWithSelf() {
->setPermissions(19)
->setNode($node);

$this->contactsManager->expects($this->any())
->method('search')
->willReturn([]);

$this->rootFolder->expects($this->never())->method($this->anything());

try {
Expand Down Expand Up @@ -403,6 +425,10 @@ public function testCreateAlreadyShared() {

$this->rootFolder->expects($this->never())->method($this->anything());

$this->contactsManager->expects($this->any())
->method('search')
->willReturn([]);

$this->provider->create($share);

try {
Expand Down Expand Up @@ -441,7 +467,6 @@ public function testUpdate($owner, $sharedBy) {
$node->method('getId')->willReturn(42);
$node->method('getName')->willReturn('myFile');


$this->addressHandler->expects($this->any())->method('splitUserRemote')
->willReturn(['user', 'server.com']);

Expand Down Expand Up @@ -477,6 +502,10 @@ public function testUpdate($owner, $sharedBy) {

$this->rootFolder->expects($this->never())->method($this->anything());

$this->contactsManager->expects($this->any())
->method('search')
->willReturn([]);

$share = $this->provider->create($share);

$share->setPermissions(1);
Expand Down Expand Up @@ -515,6 +544,10 @@ public function testGetSharedBy() {

$this->rootFolder->expects($this->never())->method($this->anything());

$this->contactsManager->expects($this->any())
->method('search')
->willReturn([]);

$share = $this->shareManager->newShare();
$share->setSharedWith('[email protected]')
->setSharedBy('sharedBy')
Expand Down Expand Up @@ -555,6 +588,10 @@ public function testGetSharedByWithNode() {
$this->addressHandler->method('generateRemoteURL')
->willReturn('remoteurl.com');

$this->contactsManager->expects($this->any())
->method('search')
->willReturn([]);

$share = $this->shareManager->newShare();
$share->setSharedWith('[email protected]')
->setSharedBy('sharedBy')
Expand Down Expand Up @@ -598,6 +635,10 @@ public function testGetSharedByWithReshares() {
$this->addressHandler->method('generateRemoteURL')
->willReturn('remoteurl.com');

$this->contactsManager->expects($this->any())
->method('search')
->willReturn([]);

$share = $this->shareManager->newShare();
$share->setSharedWith('[email protected]')
->setSharedBy('shareOwner')
Expand Down Expand Up @@ -644,6 +685,10 @@ public function testGetSharedByWithLimit() {
$this->addressHandler->method('generateRemoteURL')
->willReturn('remoteurl.com');

$this->contactsManager->expects($this->any())
->method('search')
->willReturn([]);

$share = $this->shareManager->newShare();
$share->setSharedWith('[email protected]')
->setSharedBy('sharedBy')
Expand Down Expand Up @@ -844,6 +889,10 @@ public function testGetSharesInFolder() {
$this->addressHandler->method('generateRemoteURL')
->willReturn('remoteurl.com');

$this->contactsManager->expects($this->any())
->method('search')
->willReturn([]);

$share1 = $this->shareManager->newShare();
$share1->setSharedWith('[email protected]')
->setSharedBy($u1->getUID())
Expand Down Expand Up @@ -891,6 +940,10 @@ public function testGetAccessList() {
->method('sendRemoteShare')
->willReturn(true);

$this->contactsManager->expects($this->any())
->method('search')
->willReturn([]);

$result = $this->provider->getAccessList([$file1], true);
$this->assertEquals(['remote' => []], $result);

Expand Down
12 changes: 11 additions & 1 deletion apps/files_sharing/tests/External/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

use OC\Federation\CloudIdManager;
use OCA\Files_Sharing\Tests\TestCase;
use OCP\Contacts\IManager;
use OCP\Federation\ICloudIdManager;

/**
Expand All @@ -39,6 +40,8 @@
* @package OCA\Files_Sharing\Tests\External
*/
class CacheTest extends TestCase {
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
protected $contactsManager;

/**
* @var \OC\Files\Storage\Storage
Expand All @@ -61,7 +64,9 @@ class CacheTest extends TestCase {
protected function setUp(): void {
parent::setUp();

$this->cloudIdManager = new CloudIdManager();
$this->contactsManager = $this->createMock(IManager::class);

$this->cloudIdManager = new CloudIdManager($this->contactsManager);
$this->remoteUser = $this->getUniqueID('remoteuser');

$this->storage = $this->getMockBuilder('\OCA\Files_Sharing\External\Storage')
Expand All @@ -71,6 +76,11 @@ protected function setUp(): void {
->expects($this->any())
->method('getId')
->willReturn('dummystorage::');

$this->contactsManager->expects($this->any())
->method('search')
->willReturn([]);

$this->cache = new \OCA\Files_Sharing\External\Cache(
$this->storage,
$this->cloudIdManager->getCloudId($this->remoteUser, 'http://example.com/owncloud')
Expand Down
8 changes: 7 additions & 1 deletion apps/files_sharing/tests/External/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ protected function setUp(): void {
$this->groupManager = $this->createMock(IGroupManager::class);
$this->userManager = $this->createMock(IUserManager::class);

$this->contactsManager = $this->createMock(IManager::class);
// needed for MountProvider() initialization
$this->contactsManager->expects($this->any())
->method('search')
->willReturn([]);

$this->manager = $this->getMockBuilder(Manager::class)
->setConstructorArgs(
[
Expand All @@ -113,7 +119,7 @@ protected function setUp(): void {

$this->testMountProvider = new MountProvider(\OC::$server->getDatabaseConnection(), function () {
return $this->manager;
}, new CloudIdManager());
}, new CloudIdManager($this->contactsManager));
}

private function setupMounts() {
Expand Down
10 changes: 9 additions & 1 deletion lib/private/Federation/CloudId.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class CloudId implements ICloudId {
private $user;
/** @var string */
private $remote;
/** @var string|null */
private $displayName;

/**
* CloudId constructor.
Expand All @@ -44,10 +46,11 @@ class CloudId implements ICloudId {
* @param string $user
* @param string $remote
*/
public function __construct(string $id, string $user, string $remote) {
public function __construct(string $id, string $user, string $remote, ?string $displayName = null) {
$this->id = $id;
$this->user = $user;
$this->remote = $remote;
$this->displayName = $displayName;
}

/**
Expand All @@ -60,6 +63,11 @@ public function getId(): string {
}

public function getDisplayId(): string {
if ($this->displayName) {
$atPos = strrpos($this->getId(), '@');
$atHost = substr($this->getId(), $atPos);
return $this->displayName . $atHost;
}
return str_replace('https://', '', str_replace('http://', '', $this->getId()));
}

Expand Down
Loading