2015-03-16 13:28:23 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2015 Lukas Reschke <lukas@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2016-05-19 09:46:58 +03:00
|
|
|
namespace Test\Http\Client;
|
2015-03-16 13:28:23 +03:00
|
|
|
|
|
|
|
use GuzzleHttp\Client as GuzzleClient;
|
2021-03-23 19:41:31 +03:00
|
|
|
use GuzzleHttp\HandlerStack;
|
|
|
|
use GuzzleHttp\Handler\CurlHandler;
|
2016-05-19 09:46:58 +03:00
|
|
|
use OC\Http\Client\Client;
|
|
|
|
use OC\Http\Client\ClientService;
|
2021-03-23 19:41:31 +03:00
|
|
|
use OC\Http\Client\DnsPinMiddleware;
|
|
|
|
use OC\Http\Client\LocalAddressChecker;
|
2016-09-07 21:05:51 +03:00
|
|
|
use OCP\ICertificateManager;
|
|
|
|
use OCP\IConfig;
|
2020-04-14 19:55:41 +03:00
|
|
|
use OCP\ILogger;
|
2015-03-16 13:28:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ClientServiceTest
|
|
|
|
*/
|
|
|
|
class ClientServiceTest extends \Test\TestCase {
|
2019-02-24 16:48:05 +03:00
|
|
|
public function testNewClient(): void {
|
|
|
|
/** @var IConfig $config */
|
2016-09-07 21:05:51 +03:00
|
|
|
$config = $this->createMock(IConfig::class);
|
2019-02-24 16:48:05 +03:00
|
|
|
/** @var ICertificateManager $certificateManager */
|
2016-09-07 21:05:51 +03:00
|
|
|
$certificateManager = $this->createMock(ICertificateManager::class);
|
2020-04-14 19:55:41 +03:00
|
|
|
$logger = $this->createMock(ILogger::class);
|
2021-03-23 19:41:31 +03:00
|
|
|
$dnsPinMiddleware = $this->createMock(DnsPinMiddleware::class);
|
|
|
|
$dnsPinMiddleware
|
|
|
|
->expects($this->atLeastOnce())
|
|
|
|
->method('addDnsPinning')
|
|
|
|
->willReturn(function () {
|
|
|
|
});
|
|
|
|
$localAddressChecker = $this->createMock(LocalAddressChecker::class);
|
|
|
|
|
|
|
|
$clientService = new ClientService(
|
|
|
|
$config,
|
|
|
|
$logger,
|
|
|
|
$certificateManager,
|
|
|
|
$dnsPinMiddleware,
|
|
|
|
$localAddressChecker
|
|
|
|
);
|
|
|
|
|
|
|
|
$handler = new CurlHandler();
|
|
|
|
$stack = HandlerStack::create($handler);
|
|
|
|
$stack->push($dnsPinMiddleware->addDnsPinning());
|
|
|
|
$guzzleClient = new GuzzleClient(['handler' => $stack]);
|
2015-03-16 13:28:23 +03:00
|
|
|
|
2019-02-24 16:48:05 +03:00
|
|
|
$this->assertEquals(
|
2021-03-23 19:41:31 +03:00
|
|
|
new Client(
|
|
|
|
$config,
|
|
|
|
$logger,
|
|
|
|
$certificateManager,
|
|
|
|
$guzzleClient,
|
|
|
|
$localAddressChecker
|
|
|
|
),
|
2019-02-24 16:48:05 +03:00
|
|
|
$clientService->newClient()
|
|
|
|
);
|
2015-03-16 13:28:23 +03:00
|
|
|
}
|
|
|
|
}
|