namespace OC\Http\Client;
use GuzzleHttp\Client as GuzzleClient;
-use GuzzleHttp\HandlerStack;
use GuzzleHttp\Handler\CurlHandler;
+use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use OCP\Diagnostics\IEventLogger;
use OCP\Http\Client\IClient;
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());
+ }
$stack->push(Middleware::tap(function (RequestInterface $request) {
$this->eventLogger->start('http:request', $request->getMethod() . " request to " . $request->getRequestTarget());
}, function () {
namespace Test\Http\Client;
use GuzzleHttp\Client as GuzzleClient;
-use GuzzleHttp\HandlerStack;
use GuzzleHttp\Handler\CurlHandler;
+use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use OC\Http\Client\Client;
use OC\Http\Client\ClientService;
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);
$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);
+ $eventLogger = $this->createMock(IEventLogger::class);
+ $logger = $this->createMock(LoggerInterface::class);
+
+ $clientService = new ClientService(
+ $config,
+ $certificateManager,
+ $dnsPinMiddleware,
+ $remoteHostValidator,
+ $eventLogger,
+ $logger,
+ );
+
+ $handler = new CurlHandler();
+ $stack = HandlerStack::create($handler);
+ $stack->push(Middleware::tap(function (RequestInterface $request) use ($eventLogger) {
+ $eventLogger->start('http:request', $request->getMethod() . " request to " . $request->getRequestTarget());
+ }, function () use ($eventLogger) {
+ $eventLogger->end('http:request');
+ }), 'event logger');
+ $guzzleClient = new GuzzleClient(['handler' => $stack]);
+
+ $this->assertEquals(
+ new Client(
+ $config,
+ $certificateManager,
+ $guzzleClient,
+ $remoteHostValidator,
+ $logger,
+ ),
+ $clientService->newClient()
+ );
+ }
}