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
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public function shareReceived(ICloudFederationShare $share): string {
}

$rawProtocol = $share->getProtocol();
if (!isset($rawProtocol[ICalendarFederationProtocol::PROP_VERSION])) {
throw new ProviderCouldNotAddShareException(
'No protocol version',
'',
Http::STATUS_BAD_REQUEST,
);
}
switch ($rawProtocol[ICalendarFederationProtocol::PROP_VERSION]) {
case CalendarFederationProtocolV1::VERSION:
try {
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/lib/CalDAV/Federation/FederationSharingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public function __construct(
*/
private function decodeRemoteUserPrincipal(string $principal): ?string {
// Expected format: principals/remote-users/abcdef123
[$prefix, $collection, $encodedId] = explode('/', $principal);
if ($prefix !== 'principals' || $collection !== 'remote-users') {
if (!str_starts_with($principal, 'principals/remote-users/')) {
return null;
}
$encodedId = substr($principal, strlen('principals/remote-users/'));

$decodedId = base64_decode($encodedId);
if (!is_string($decodedId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function testShareReceivedWithoutProtocolVersion(): void {
->method('add');

$this->expectException(ProviderCouldNotAddShareException::class);
$this->expectExceptionMessage('Unknown protocol version');
$this->expectExceptionMessage('No protocol version');
$this->expectExceptionCode(400);
$this->assertEquals(10, $this->calendarFederationProvider->shareReceived($share));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class UserEventsListenerTest extends TestCase {
private ExampleContactService&MockObject $exampleContactService;
private ExampleEventService&MockObject $exampleEventService;
private LoggerInterface&MockObject $logger;
private IJobList&MockObject $jobList;

private UserEventsListener $userEventsListener;

Expand Down
37 changes: 19 additions & 18 deletions apps/dav/tests/unit/Upload/UploadAutoMkcolPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,29 @@
use Test\TestCase;

class UploadAutoMkcolPluginTest extends TestCase {

private Tree&MockObject $tree;
private RequestInterface&MockObject $request;
private ResponseInterface&MockObject $response;

private UploadAutoMkcolPlugin $plugin;

protected function setUp(): void {
parent::setUp();

$server = $this->createMock(Server::class);
$this->tree = $this->createMock(Tree::class);

$server->tree = $this->tree;
$this->plugin = new UploadAutoMkcolPlugin();

$this->request = $this->createMock(RequestInterface::class);
$this->response = $this->createMock(ResponseInterface::class);
$server->httpRequest = $this->request;
$server->httpResponse = $this->response;

$this->plugin->initialize($server);
}

public static function dataMissingHeaderShouldReturnTrue(): Generator {
yield 'missing X-NC-WebDAV-Auto-Mkcol header' => [null];
yield 'empty X-NC-WebDAV-Auto-Mkcol header' => [''];
Expand Down Expand Up @@ -113,21 +131,4 @@ public function testBeforeMethodShouldSucceed(): void {
$return = $this->plugin->beforeMethod($this->request, $this->response);
self::assertTrue($return);
}

protected function setUp(): void {
parent::setUp();

$server = $this->createMock(Server::class);
$this->tree = $this->createMock(Tree::class);

$server->tree = $this->tree;
$this->plugin = new UploadAutoMkcolPlugin();

$this->request = $this->createMock(RequestInterface::class);
$this->response = $this->createMock(ResponseInterface::class);
$server->httpRequest = $this->request;
$server->httpResponse = $this->response;

$this->plugin->initialize($server);
}
}
6 changes: 6 additions & 0 deletions apps/files/tests/Controller/ViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ public function testTwoFactorAuthEnabled(): void {
}
});

$this->config
->method('getUserValue')
->willReturnMap([
[$this->user->getUID(), 'files', 'files_sorting_configs', '{}', '{}'],
]);

$this->viewController->index('', '', null);
}
}
8 changes: 3 additions & 5 deletions apps/files_external/tests/Storage/Amazons3MultiPartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
* @package OCA\Files_External\Tests\Storage
*/
class Amazons3MultiPartTest extends \Test\Files\Storage\Storage {
private $config;
use ConfigurableStorageTrait;
/** @var AmazonS3 */
protected $instance;

protected function setUp(): void {
parent::setUp();

$this->config = include('files_external/tests/config.amazons3.php');
if (!is_array($this->config) || !$this->config['run']) {
$this->markTestSkipped('AmazonS3 backend not configured');
}
$this->loadConfig('files_external/tests/config.amazons3.php');

$this->instance = new AmazonS3($this->config + [
'putSizeLimit' => 1,
'copySizeLimit' => 1,
Expand Down
7 changes: 2 additions & 5 deletions apps/files_external/tests/Storage/Amazons3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@
* @package OCA\Files_External\Tests\Storage
*/
class Amazons3Test extends \Test\Files\Storage\Storage {
protected $config;
use ConfigurableStorageTrait;
/** @var AmazonS3 */
protected $instance;

protected function setUp(): void {
parent::setUp();

$this->config = include('files_external/tests/config.amazons3.php');
if (!is_array($this->config) || !$this->config['run']) {
$this->markTestSkipped('AmazonS3 backend not configured');
}
$this->loadConfig('files_external/tests/config.amazons3.php');
$this->instance = new AmazonS3($this->config);
}

Expand Down
30 changes: 30 additions & 0 deletions apps/files_external/tests/Storage/ConfigurableStorageTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Files_External\Tests\Storage;

trait ConfigurableStorageTrait {
protected ?array $config = null;

protected function loadConfig(string $path): bool {
$this->config = null;
if (file_exists($path)) {
$this->config = include($path);
}
if (!$this->shouldRunConfig($this->config)) {
$this->markTestSkipped(__CLASS__ . ' Backend not configured');
return false;
}
return true;
}

protected function shouldRunConfig(mixed $config): bool {
return is_array($config) && ($config['run'] ?? false);
}
}
8 changes: 3 additions & 5 deletions apps/files_external/tests/Storage/FtpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
* @package OCA\Files_External\Tests\Storage
*/
class FtpTest extends \Test\Files\Storage\Storage {
private $config;
use ConfigurableStorageTrait;

protected function setUp(): void {
parent::setUp();

$id = $this->getUniqueID();
$this->config = include('files_external/tests/config.ftp.php');
if (! is_array($this->config) or ! $this->config['run']) {
$this->markTestSkipped('FTP backend not configured');
}
$this->loadConfig('files_external/tests/config.ftp.php');

$rootInstance = new FTP($this->config);
$rootInstance->mkdir($id);

Expand Down
11 changes: 6 additions & 5 deletions apps/files_external/tests/Storage/OwncloudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@
* @package OCA\Files_External\Tests\Storage
*/
class OwncloudTest extends \Test\Files\Storage\Storage {
private $config;
use ConfigurableStorageTrait;

protected function setUp(): void {
parent::setUp();

$id = $this->getUniqueID();
$this->config = include('files_external/tests/config.php');
if (! is_array($this->config) or ! isset($this->config['owncloud']) or ! $this->config['owncloud']['run']) {
$this->markTestSkipped('Nextcloud backend not configured');
}
$this->loadConfig('files_external/tests/config.php');
$this->config['owncloud']['root'] .= '/' . $id; //make sure we have an new empty folder to work in
$this->instance = new OwnCloud($this->config['owncloud']);
$this->instance->mkdir('/');
}

protected function shouldRunConfig(mixed $config): bool {
return is_array($config) && ($config['owncloud']['run'] ?? false);
}

protected function tearDown(): void {
if ($this->instance) {
$this->instance->rmdir('/');
Expand Down
11 changes: 6 additions & 5 deletions apps/files_external/tests/Storage/SFTP_KeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@
* @package OCA\Files_External\Tests\Storage
*/
class SFTP_KeyTest extends \Test\Files\Storage\Storage {
private $config;
use ConfigurableStorageTrait;

protected function setUp(): void {
parent::setUp();

$id = $this->getUniqueID();
$this->config = include('files_external/tests/config.php');
if (! is_array($this->config) or ! isset($this->config['sftp_key']) or ! $this->config['sftp_key']['run']) {
$this->markTestSkipped('SFTP with key backend not configured');
}
$this->loadConfig('files_external/tests/config.php');
// Make sure we have an new empty folder to work in
$this->config['sftp_key']['root'] .= '/' . $id;
$this->instance = new SFTP_Key($this->config['sftp_key']);
$this->instance->mkdir('/');
}

protected function shouldRunConfig(mixed $config): bool {
return is_array($config) && ($config['sftp_key']['run'] ?? false);
}

protected function tearDown(): void {
if ($this->instance) {
$this->instance->rmdir('/');
Expand Down
8 changes: 2 additions & 6 deletions apps/files_external/tests/Storage/SftpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@
* @package OCA\Files_External\Tests\Storage
*/
class SftpTest extends \Test\Files\Storage\Storage {
use ConfigurableStorageTrait;
/**
* @var SFTP instance
*/
protected $instance;

private $config;

protected function setUp(): void {
parent::setUp();

$id = $this->getUniqueID();
$this->config = include('files_external/tests/config.sftp.php');
if (!is_array($this->config) or !$this->config['run']) {
$this->markTestSkipped('SFTP backend not configured');
}
$this->loadConfig('files_external/tests/config.sftp.php');
$this->config['root'] .= '/' . $id; //make sure we have an new empty folder to work in
$this->instance = new SFTP($this->config);
$this->instance->mkdir('/');
Expand Down
14 changes: 6 additions & 8 deletions apps/files_external/tests/Storage/SmbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @package OCA\Files_External\Tests\Storage
*/
class SmbTest extends \Test\Files\Storage\Storage {
use ConfigurableStorageTrait;
/**
* @var SMB instance
*/
Expand All @@ -31,15 +32,12 @@ protected function setUp(): void {
parent::setUp();

$id = $this->getUniqueID();
$config = include('files_external/tests/config.smb.php');
if (!is_array($config) or !$config['run']) {
$this->markTestSkipped('Samba backend not configured');
$this->loadConfig('files_external/tests/config.smb.php');
if (substr($this->config['root'], -1, 1) != '/') {
$this->config['root'] .= '/';
}
if (substr($config['root'], -1, 1) != '/') {
$config['root'] .= '/';
}
$config['root'] .= $id; //make sure we have an new empty folder to work in
$this->instance = new SMB($config);
$this->config['root'] .= $id; //make sure we have an new empty folder to work in
$this->instance = new SMB($this->config);
$this->instance->mkdir('/');
}

Expand Down
7 changes: 2 additions & 5 deletions apps/files_external/tests/Storage/SwiftTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @package OCA\Files_External\Tests\Storage
*/
class SwiftTest extends \Test\Files\Storage\Storage {
private $config;
use ConfigurableStorageTrait;

/**
* @var Swift instance
Expand All @@ -29,10 +29,7 @@ class SwiftTest extends \Test\Files\Storage\Storage {
protected function setUp(): void {
parent::setUp();

$this->config = include('files_external/tests/config.swift.php');
if (!is_array($this->config) or !$this->config['run']) {
$this->markTestSkipped('OpenStack Object Storage backend not configured');
}
$this->loadConfig('files_external/tests/config.swift.php');
$this->instance = new Swift($this->config);
}

Expand Down
15 changes: 7 additions & 8 deletions apps/files_external/tests/Storage/WebdavTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@
* @package OCA\Files_External\Tests\Storage
*/
class WebdavTest extends \Test\Files\Storage\Storage {
use ConfigurableStorageTrait;

protected function setUp(): void {
parent::setUp();

$id = $this->getUniqueID();
$config = include('files_external/tests/config.webdav.php');
if (!is_array($config) or !$config['run']) {
$this->markTestSkipped('WebDAV backend not configured');
}
if (isset($config['wait'])) {
$this->waitDelay = $config['wait'];
$this->loadConfig('files_external/tests/config.webdav.php');
if (isset($this->config['wait'])) {
$this->waitDelay = $this->config['wait'];
}
$config['root'] .= '/' . $id; //make sure we have an new empty folder to work in
$this->instance = new DAV($config);
$this->config['root'] .= '/' . $id; //make sure we have an new empty folder to work in
$this->instance = new DAV($this->config);
$this->instance->mkdir('/');
}

Expand Down
Loading
Loading