|
|
|
@ -17,6 +17,7 @@ use OCP\Http\Client\LocalServerException;
|
|
|
|
use OCP\ICertificateManager;
|
|
|
|
use OCP\ICertificateManager;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\Security\IRemoteHostValidator;
|
|
|
|
use OCP\Security\IRemoteHostValidator;
|
|
|
|
|
|
|
|
use OCP\ServerVersion;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
use function parse_url;
|
|
|
|
use function parse_url;
|
|
|
|
@ -36,6 +37,7 @@ class ClientTest extends \Test\TestCase {
|
|
|
|
/** @var IRemoteHostValidator|MockObject */
|
|
|
|
/** @var IRemoteHostValidator|MockObject */
|
|
|
|
private IRemoteHostValidator $remoteHostValidator;
|
|
|
|
private IRemoteHostValidator $remoteHostValidator;
|
|
|
|
private LoggerInterface $logger;
|
|
|
|
private LoggerInterface $logger;
|
|
|
|
|
|
|
|
private ServerVersion $serverVersion;
|
|
|
|
/** @var array */
|
|
|
|
/** @var array */
|
|
|
|
private $defaultRequestOptions;
|
|
|
|
private $defaultRequestOptions;
|
|
|
|
|
|
|
|
|
|
|
|
@ -46,12 +48,15 @@ class ClientTest extends \Test\TestCase {
|
|
|
|
$this->certificateManager = $this->createMock(ICertificateManager::class);
|
|
|
|
$this->certificateManager = $this->createMock(ICertificateManager::class);
|
|
|
|
$this->remoteHostValidator = $this->createMock(IRemoteHostValidator::class);
|
|
|
|
$this->remoteHostValidator = $this->createMock(IRemoteHostValidator::class);
|
|
|
|
$this->logger = $this->createMock(LoggerInterface::class);
|
|
|
|
$this->logger = $this->createMock(LoggerInterface::class);
|
|
|
|
|
|
|
|
$this->serverVersion = $this->createMock(ServerVersion::class);
|
|
|
|
|
|
|
|
|
|
|
|
$this->client = new Client(
|
|
|
|
$this->client = new Client(
|
|
|
|
$this->config,
|
|
|
|
$this->config,
|
|
|
|
$this->certificateManager,
|
|
|
|
$this->certificateManager,
|
|
|
|
$this->guzzleClient,
|
|
|
|
$this->guzzleClient,
|
|
|
|
$this->remoteHostValidator,
|
|
|
|
$this->remoteHostValidator,
|
|
|
|
$this->logger,
|
|
|
|
$this->logger,
|
|
|
|
|
|
|
|
$this->serverVersion,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -276,6 +281,9 @@ class ClientTest extends \Test\TestCase {
|
|
|
|
->with()
|
|
|
|
->with()
|
|
|
|
->willReturn('/my/path.crt');
|
|
|
|
->willReturn('/my/path.crt');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->serverVersion->method('getVersionString')
|
|
|
|
|
|
|
|
->willReturn('123.45.6');
|
|
|
|
|
|
|
|
|
|
|
|
$this->defaultRequestOptions = [
|
|
|
|
$this->defaultRequestOptions = [
|
|
|
|
'verify' => '/my/path.crt',
|
|
|
|
'verify' => '/my/path.crt',
|
|
|
|
'proxy' => [
|
|
|
|
'proxy' => [
|
|
|
|
@ -283,7 +291,7 @@ class ClientTest extends \Test\TestCase {
|
|
|
|
'https' => 'foo'
|
|
|
|
'https' => 'foo'
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'headers' => [
|
|
|
|
'headers' => [
|
|
|
|
'User-Agent' => 'Nextcloud Server Crawler',
|
|
|
|
'User-Agent' => 'Nextcloud-Server-Crawler/123.45.6',
|
|
|
|
'Accept-Encoding' => 'gzip',
|
|
|
|
'Accept-Encoding' => 'gzip',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'timeout' => 30,
|
|
|
|
'timeout' => 30,
|
|
|
|
@ -466,10 +474,13 @@ class ClientTest extends \Test\TestCase {
|
|
|
|
->expects($this->never())
|
|
|
|
->expects($this->never())
|
|
|
|
->method('listCertificates');
|
|
|
|
->method('listCertificates');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->serverVersion->method('getVersionString')
|
|
|
|
|
|
|
|
->willReturn('123.45.6');
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
$this->assertEquals([
|
|
|
|
'verify' => \OC::$SERVERROOT . '/resources/config/ca-bundle.crt',
|
|
|
|
'verify' => \OC::$SERVERROOT . '/resources/config/ca-bundle.crt',
|
|
|
|
'headers' => [
|
|
|
|
'headers' => [
|
|
|
|
'User-Agent' => 'Nextcloud Server Crawler',
|
|
|
|
'User-Agent' => 'Nextcloud-Server-Crawler/123.45.6',
|
|
|
|
'Accept-Encoding' => 'gzip',
|
|
|
|
'Accept-Encoding' => 'gzip',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'timeout' => 30,
|
|
|
|
'timeout' => 30,
|
|
|
|
@ -513,6 +524,9 @@ class ClientTest extends \Test\TestCase {
|
|
|
|
->with()
|
|
|
|
->with()
|
|
|
|
->willReturn('/my/path.crt');
|
|
|
|
->willReturn('/my/path.crt');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->serverVersion->method('getVersionString')
|
|
|
|
|
|
|
|
->willReturn('123.45.6');
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
$this->assertEquals([
|
|
|
|
'verify' => '/my/path.crt',
|
|
|
|
'verify' => '/my/path.crt',
|
|
|
|
'proxy' => [
|
|
|
|
'proxy' => [
|
|
|
|
@ -520,7 +534,7 @@ class ClientTest extends \Test\TestCase {
|
|
|
|
'https' => 'foo'
|
|
|
|
'https' => 'foo'
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'headers' => [
|
|
|
|
'headers' => [
|
|
|
|
'User-Agent' => 'Nextcloud Server Crawler',
|
|
|
|
'User-Agent' => 'Nextcloud-Server-Crawler/123.45.6',
|
|
|
|
'Accept-Encoding' => 'gzip',
|
|
|
|
'Accept-Encoding' => 'gzip',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'timeout' => 30,
|
|
|
|
'timeout' => 30,
|
|
|
|
@ -564,6 +578,9 @@ class ClientTest extends \Test\TestCase {
|
|
|
|
->with()
|
|
|
|
->with()
|
|
|
|
->willReturn('/my/path.crt');
|
|
|
|
->willReturn('/my/path.crt');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->serverVersion->method('getVersionString')
|
|
|
|
|
|
|
|
->willReturn('123.45.6');
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
$this->assertEquals([
|
|
|
|
'verify' => '/my/path.crt',
|
|
|
|
'verify' => '/my/path.crt',
|
|
|
|
'proxy' => [
|
|
|
|
'proxy' => [
|
|
|
|
@ -572,7 +589,7 @@ class ClientTest extends \Test\TestCase {
|
|
|
|
'no' => ['bar']
|
|
|
|
'no' => ['bar']
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'headers' => [
|
|
|
|
'headers' => [
|
|
|
|
'User-Agent' => 'Nextcloud Server Crawler',
|
|
|
|
'User-Agent' => 'Nextcloud-Server-Crawler/123.45.6',
|
|
|
|
'Accept-Encoding' => 'gzip',
|
|
|
|
'Accept-Encoding' => 'gzip',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'timeout' => 30,
|
|
|
|
'timeout' => 30,
|
|
|
|
|