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
7 changes: 4 additions & 3 deletions lib/private/Http/Client/ClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
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;
Expand Down Expand Up @@ -65,8 +65,9 @@ public function __construct(IConfig $config,
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]);

return new Client(
Expand Down
43 changes: 42 additions & 1 deletion tests/lib/Http/Client/ClientServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
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;
Expand All @@ -25,6 +25,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);
Expand Down Expand Up @@ -57,4 +60,42 @@ public function testNewClient(): void {
$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 () {
});
$localAddressChecker = $this->createMock(LocalAddressChecker::class);

$clientService = new ClientService(
$config,
$certificateManager,
$dnsPinMiddleware,
$localAddressChecker
);

$handler = new CurlHandler();
$stack = HandlerStack::create($handler);
$guzzleClient = new GuzzleClient(['handler' => $stack]);

$this->assertEquals(
new Client(
$config,
$certificateManager,
$guzzleClient,
$localAddressChecker
),
$clientService->newClient()
);
}
}