mirror of
https://github.com/nextcloud/server.git
synced 2026-06-08 16:26:59 -04:00
feat: add switch to disable dns pinning
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
This commit is contained in:
parent
4c95301f81
commit
652a8a8f7a
2 changed files with 46 additions and 3 deletions
|
|
@ -27,8 +27,8 @@ declare(strict_types=1);
|
|||
namespace OC\Http\Client;
|
||||
|
||||
use GuzzleHttp\Client as GuzzleClient;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Handler\CurlHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use OCP\Http\Client\IClient;
|
||||
use OCP\Http\Client\IClientService;
|
||||
use OCP\ICertificateManager;
|
||||
|
|
@ -65,7 +65,9 @@ class ClientService implements IClientService {
|
|||
public function newClient(): IClient {
|
||||
$handler = new CurlHandler();
|
||||
$stack = HandlerStack::create($handler);
|
||||
$stack->push($this->dnsPinMiddleware->addDnsPinning());
|
||||
if ($this->config->getSystemValueBool('dns_pinning', true)) {
|
||||
$stack->push($this->dnsPinMiddleware->addDnsPinning());
|
||||
}
|
||||
|
||||
$client = new GuzzleClient(['handler' => $stack]);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ declare(strict_types=1);
|
|||
namespace Test\Http\Client;
|
||||
|
||||
use GuzzleHttp\Client as GuzzleClient;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Handler\CurlHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use OC\Http\Client\Client;
|
||||
use OC\Http\Client\ClientService;
|
||||
use OC\Http\Client\DnsPinMiddleware;
|
||||
|
|
@ -28,6 +28,9 @@ class ClientServiceTest extends \Test\TestCase {
|
|||
public function testNewClient(): void {
|
||||
/** @var IConfig $config */
|
||||
$config = $this->createMock(IConfig::class);
|
||||
$config->method('getSystemValueBool')
|
||||
->with('dns_pinning', true)
|
||||
->willReturn(true);
|
||||
/** @var ICertificateManager $certificateManager */
|
||||
$certificateManager = $this->createMock(ICertificateManager::class);
|
||||
$dnsPinMiddleware = $this->createMock(DnsPinMiddleware::class);
|
||||
|
|
@ -50,6 +53,44 @@ class ClientServiceTest extends \Test\TestCase {
|
|||
$stack->push($dnsPinMiddleware->addDnsPinning());
|
||||
$guzzleClient = new GuzzleClient(['handler' => $stack]);
|
||||
|
||||
$this->assertEquals(
|
||||
new Client(
|
||||
$config,
|
||||
$certificateManager,
|
||||
$guzzleClient,
|
||||
$remoteHostValidator,
|
||||
),
|
||||
$clientService->newClient()
|
||||
);
|
||||
}
|
||||
|
||||
public function testDisableDnsPinning(): void {
|
||||
/** @var IConfig $config */
|
||||
$config = $this->createMock(IConfig::class);
|
||||
$config->method('getSystemValueBool')
|
||||
->with('dns_pinning', true)
|
||||
->willReturn(false);
|
||||
/** @var ICertificateManager $certificateManager */
|
||||
$certificateManager = $this->createMock(ICertificateManager::class);
|
||||
$dnsPinMiddleware = $this->createMock(DnsPinMiddleware::class);
|
||||
$dnsPinMiddleware
|
||||
->expects($this->never())
|
||||
->method('addDnsPinning')
|
||||
->willReturn(function () {
|
||||
});
|
||||
$remoteHostValidator = $this->createMock(IRemoteHostValidator::class);
|
||||
|
||||
$clientService = new ClientService(
|
||||
$config,
|
||||
$certificateManager,
|
||||
$dnsPinMiddleware,
|
||||
$remoteHostValidator,
|
||||
);
|
||||
|
||||
$handler = new CurlHandler();
|
||||
$stack = HandlerStack::create($handler);
|
||||
$guzzleClient = new GuzzleClient(['handler' => $stack]);
|
||||
|
||||
$this->assertEquals(
|
||||
new Client(
|
||||
$config,
|
||||
|
|
|
|||
Loading…
Reference in a new issue