Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix(federation): comply to `sharing.federation.allowSelfSignedCertifi…
…cates`

Signed-off-by: skjnldsv <[email protected]>
  • Loading branch information
skjnldsv committed Jan 9, 2025
commit f753d2f77381560017e59934efe25b70ad6fbb80
7 changes: 6 additions & 1 deletion apps/federatedfilesharing/tests/Settings/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ public function testGetForm($state): void {
->expects($this->once())
->method('isIncomingServer2serverGroupShareEnabled')
->willReturn($state);
$this->federatedShareProvider
->expects($this->once())
->method('isFederatedTrustedShareAutoAccept')
->willReturn($state);
$this->gsConfig->expects($this->once())->method('onlyInternalFederation')
->willReturn($state);

$this->initialState->expects($this->exactly(9))
$this->initialState->expects($this->exactly(10))
->method('provideInitialState')
->withConsecutive(
['internalOnly', $state],
Expand All @@ -106,6 +110,7 @@ public function testGetForm($state): void {
['incomingServer2serverGroupShareEnabled', $state],
['lookupServerEnabled', $state],
['lookupServerUploadEnabled', $state],
['federatedTrustedShareAutoAccept', $state]
);

$expected = new TemplateResponse('federatedfilesharing', 'settings-admin', [], '');
Expand Down
3 changes: 3 additions & 0 deletions apps/federation/lib/BackgroundJob/GetSharedSecret.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
use OCP\IConfig;
use OCP\IURLGenerator;
use OCP\OCS\IDiscoveryService;
use Psr\Log\LoggerInterface;
Expand All @@ -43,6 +44,7 @@ public function __construct(
private LoggerInterface $logger,
private IDiscoveryService $ocsDiscoveryService,
ITimeFactory $timeFactory,
private IConfig $config
) {
parent::__construct($timeFactory);
$this->httpClient = $httpClientService->newClient();
Expand Down Expand Up @@ -105,6 +107,7 @@ protected function run($argument) {
],
'timeout' => 3,
'connect_timeout' => 3,
'verify' => !$this->config->getSystemValue('sharing.federation.allowSelfSignedCertificates', false),
]
);

Expand Down
3 changes: 3 additions & 0 deletions apps/federation/lib/BackgroundJob/RequestSharedSecret.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCP\BackgroundJob\Job;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IURLGenerator;
use OCP\OCS\IDiscoveryService;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -47,6 +48,7 @@ public function __construct(
private IDiscoveryService $ocsDiscoveryService,
private LoggerInterface $logger,
ITimeFactory $timeFactory,
private IConfig $config
) {
parent::__construct($timeFactory);
$this->httpClient = $httpClientService->newClient();
Expand Down Expand Up @@ -116,6 +118,7 @@ protected function run($argument) {
],
'timeout' => 3,
'connect_timeout' => 3,
'verify' => !$this->config->getSystemValue('sharing.federation.allowSelfSignedCertificates', false),
]
);

Expand Down
4 changes: 2 additions & 2 deletions apps/federation/lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function __construct(
*/
#[AuthorizedAdminSetting(settings: Admin::class)]
public function addServer(string $url): DataResponse {
$this->checkServer($url);
$id = $this->trustedServers->addServer($url);
$this->checkServer(trim($url));
$id = $this->trustedServers->addServer(trim($url));

return new DataResponse([
'url' => $url,
Expand Down
1 change: 1 addition & 0 deletions apps/federation/lib/TrustedServers.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function isNextcloudServer(string $url): bool {
[
'timeout' => 3,
'connect_timeout' => 3,
'verify' => !$this->config->getSystemValue('sharing.federation.allowSelfSignedCertificates', false),
]
);
if ($result->getStatusCode() === Http::STATUS_OK) {
Expand Down
13 changes: 11 additions & 2 deletions apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
use OCP\IConfig;
use OCP\IURLGenerator;
use OCP\OCS\IDiscoveryService;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -57,6 +58,9 @@ class GetSharedSecretTest extends TestCase {
/** @var \PHPUnit\Framework\MockObject\MockObject|ITimeFactory */
private $timeFactory;

/** @var \PHPUnit\Framework\MockObject\MockObject|IConfig */
private $config;

private GetSharedSecret $getSharedSecret;

protected function setUp(): void {
Expand All @@ -72,6 +76,7 @@ protected function setUp(): void {
$this->response = $this->getMockBuilder(IResponse::class)->getMock();
$this->discoverService = $this->getMockBuilder(IDiscoveryService::class)->getMock();
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->config = $this->createMock(IConfig::class);

$this->discoverService->expects($this->any())->method('discover')->willReturn([]);
$this->httpClientService->expects($this->any())->method('newClient')->willReturn($this->httpClient);
Expand All @@ -83,7 +88,8 @@ protected function setUp(): void {
$this->trustedServers,
$this->logger,
$this->discoverService,
$this->timeFactory
$this->timeFactory,
$this->config
);
}

Expand All @@ -104,7 +110,8 @@ public function testExecute(bool $isTrustedServer, bool $retainBackgroundJob): v
$this->trustedServers,
$this->logger,
$this->discoverService,
$this->timeFactory
$this->timeFactory,
$this->config,
]
)->setMethods(['parentStart'])->getMock();
$this->invokePrivate($getSharedSecret, 'argument', [['url' => 'url', 'token' => 'token']]);
Expand Down Expand Up @@ -176,6 +183,7 @@ public function testRun($statusCode): void {
],
'timeout' => 3,
'connect_timeout' => 3,
'verify' => true,
]
)->willReturn($this->response);

Expand Down Expand Up @@ -267,6 +275,7 @@ public function testRunConnectionError(): void {
],
'timeout' => 3,
'connect_timeout' => 3,
'verify' => true,
]
)->willThrowException($this->createMock(ConnectException::class));

Expand Down
13 changes: 11 additions & 2 deletions apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
use OCP\IConfig;
use OCP\IURLGenerator;
use OCP\OCS\IDiscoveryService;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down Expand Up @@ -50,6 +51,9 @@ class RequestSharedSecretTest extends TestCase {
/** @var MockObject|ITimeFactory */
private $timeFactory;

/** @var MockObject|IConfig */
private $config;

/** @var RequestSharedSecret */
private $requestSharedSecret;

Expand All @@ -66,6 +70,7 @@ protected function setUp(): void {
$this->discoveryService = $this->getMockBuilder(IDiscoveryService::class)->getMock();
$this->logger = $this->createMock(LoggerInterface::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->config = $this->createMock(IConfig::class);

$this->discoveryService->expects($this->any())->method('discover')->willReturn([]);
$this->httpClientService->expects($this->any())->method('newClient')->willReturn($this->httpClient);
Expand All @@ -77,7 +82,8 @@ protected function setUp(): void {
$this->trustedServers,
$this->discoveryService,
$this->logger,
$this->timeFactory
$this->timeFactory,
$this->config,
);
}

Expand All @@ -98,7 +104,8 @@ public function testStart($isTrustedServer, $retainBackgroundJob): void {
$this->trustedServers,
$this->discoveryService,
$this->logger,
$this->timeFactory
$this->timeFactory,
$this->config,
]
)->setMethods(['parentStart'])->getMock();
$this->invokePrivate($requestSharedSecret, 'argument', [['url' => 'url', 'token' => 'token']]);
Expand Down Expand Up @@ -170,6 +177,7 @@ public function testRun(int $statusCode, int $attempt = 0): void {
],
'timeout' => 3,
'connect_timeout' => 3,
'verify' => true,
]
)->willReturn($this->response);

Expand Down Expand Up @@ -255,6 +263,7 @@ public function testRunConnectionError(): void {
],
'timeout' => 3,
'connect_timeout' => 3,
'verify' => true,
]
)->willThrowException($this->createMock(ConnectException::class));

Expand Down
9 changes: 9 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,15 @@
*/
'transferIncomingShares' => false,

/**
* Federated Cloud Sharing
*/

/**
* Allow self-signed certificates for federated shares
*/
'sharing.federation.allowSelfSignedCertificates' => false,

/**
* Hashing
*/
Expand Down