diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2023-08-29 17:20:16 +0200 |
---|---|---|
committer | Daniel Kesselberg <mail@danielkesselberg.de> | 2023-08-29 18:03:54 +0200 |
commit | eab46bdfe678d0e5ac12a616e8fa2550e573bc0f (patch) | |
tree | eb712229f15dbcc9c67eedf39c42004a5dbd079d /tests | |
parent | 6f520f23046e74c07b1f7179abba1097af3e0c65 (diff) | |
download | nextcloud-server-eab46bdfe678d0e5ac12a616e8fa2550e573bc0f.tar.gz nextcloud-server-eab46bdfe678d0e5ac12a616e8fa2550e573bc0f.zip |
feat: add switch to disable dns pinning
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Http/Client/ClientServiceTest.php | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/tests/lib/Http/Client/ClientServiceTest.php b/tests/lib/Http/Client/ClientServiceTest.php index 40da0a2111c..3aae7ceae25 100644 --- a/tests/lib/Http/Client/ClientServiceTest.php +++ b/tests/lib/Http/Client/ClientServiceTest.php @@ -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 GuzzleHttp\Middleware; use OC\Http\Client\Client; use OC\Http\Client\ClientService; @@ -32,6 +32,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); @@ -74,4 +77,52 @@ class ClientServiceTest extends \Test\TestCase { $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() + ); + } } |