2021-03-23 12:41:31 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
/**
|
2024-05-10 09:09:14 -04:00
|
|
|
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2021-03-23 12:41:31 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Test\Http\Client;
|
|
|
|
|
|
2021-03-30 15:50:11 -04:00
|
|
|
use OC\Http\Client\NegativeDnsCache;
|
2021-03-23 12:41:31 -04:00
|
|
|
use OCP\ICache;
|
|
|
|
|
use OCP\ICacheFactory;
|
|
|
|
|
|
|
|
|
|
class NegativeDnsCacheTest extends \Test\TestCase {
|
|
|
|
|
/** @var ICache */
|
|
|
|
|
private $cache;
|
|
|
|
|
/** @var ICacheFactory */
|
|
|
|
|
private $cacheFactory;
|
|
|
|
|
/** @var NegativeDnsCache */
|
|
|
|
|
private $negativeDnsCache;
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->cache = $this->createMock(ICache::class);
|
|
|
|
|
$this->cacheFactory = $this->createMock(ICacheFactory::class);
|
2021-03-30 15:50:11 -04:00
|
|
|
$this->cacheFactory
|
2021-03-23 12:41:31 -04:00
|
|
|
->method('createLocal')
|
|
|
|
|
->with('NegativeDnsCache')
|
|
|
|
|
->willReturn($this->cache);
|
|
|
|
|
|
|
|
|
|
$this->negativeDnsCache = new NegativeDnsCache($this->cacheFactory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSetNegativeCacheForDnsType() : void {
|
2021-03-30 15:50:11 -04:00
|
|
|
$this->cache
|
|
|
|
|
->expects($this->once())
|
|
|
|
|
->method('set')
|
|
|
|
|
->with('www.example.com-1', 'true', 3600);
|
|
|
|
|
|
2025-04-27 08:38:18 -04:00
|
|
|
$this->negativeDnsCache->setNegativeCacheForDnsType('www.example.com', DNS_A, 3600);
|
2021-03-23 12:41:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testIsNegativeCached() {
|
2021-03-30 15:50:11 -04:00
|
|
|
$this->cache
|
|
|
|
|
->expects($this->once())
|
|
|
|
|
->method('hasKey')
|
|
|
|
|
->with('www.example.com-1')
|
|
|
|
|
->willReturn(true);
|
2021-03-23 12:41:31 -04:00
|
|
|
|
2025-04-27 08:38:18 -04:00
|
|
|
$this->assertTrue($this->negativeDnsCache->isNegativeCached('www.example.com', DNS_A));
|
2021-03-23 12:41:31 -04:00
|
|
|
}
|
|
|
|
|
}
|