diff options
Diffstat (limited to 'tests/lib/Security')
-rw-r--r-- | tests/lib/Security/Bruteforce/Backend/MemoryCacheBackendTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Security/CertificateManagerTest.php | 9 | ||||
-rw-r--r-- | tests/lib/Security/CredentialsManagerTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Security/CryptoTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Security/HasherTest.php | 11 | ||||
-rw-r--r-- | tests/lib/Security/IdentityProof/ManagerTest.php | 28 | ||||
-rw-r--r-- | tests/lib/Security/Ip/BruteforceAllowListTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Security/Ip/RemoteAddressTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Security/Normalizer/IpAddressTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Security/RateLimiting/LimiterTest.php | 23 | ||||
-rw-r--r-- | tests/lib/Security/RemoteHostValidatorIntegrationTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Security/RemoteHostValidatorTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Security/SecureRandomTest.php | 6 | ||||
-rw-r--r-- | tests/lib/Security/TrustedDomainHelperTest.php | 2 |
15 files changed, 51 insertions, 50 deletions
diff --git a/tests/lib/Security/Bruteforce/Backend/MemoryCacheBackendTest.php b/tests/lib/Security/Bruteforce/Backend/MemoryCacheBackendTest.php index 82bffb74e01..ac679238617 100644 --- a/tests/lib/Security/Bruteforce/Backend/MemoryCacheBackendTest.php +++ b/tests/lib/Security/Bruteforce/Backend/MemoryCacheBackendTest.php @@ -36,7 +36,7 @@ class MemoryCacheBackendTest extends TestCase { $this->cacheFactory ->expects($this->once()) ->method('createDistributed') - ->with('OC\Security\Bruteforce\Backend\MemoryCacheBackend') + ->with(MemoryCacheBackend::class) ->willReturn($this->cache); $this->backend = new MemoryCacheBackend( @@ -55,7 +55,7 @@ class MemoryCacheBackendTest extends TestCase { $this->assertSame(0, $this->backend->getAttempts('10.10.10.10/32', 0)); } - public function dataGetAttempts(): array { + public static function dataGetAttempts(): array { return [ [0, null, null, 4], [100, null, null, 2], diff --git a/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php b/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php index f8386124626..fcc776ade8e 100644 --- a/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php +++ b/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php @@ -28,7 +28,7 @@ class SessionStorageTest extends \Test\TestCase { /** * @return array */ - public function getTokenDataProvider() { + public static function getTokenDataProvider(): array { return [ [ '', diff --git a/tests/lib/Security/CertificateManagerTest.php b/tests/lib/Security/CertificateManagerTest.php index 1c168228b6a..a0cb133ec3b 100644 --- a/tests/lib/Security/CertificateManagerTest.php +++ b/tests/lib/Security/CertificateManagerTest.php @@ -100,10 +100,7 @@ class CertificateManagerTest extends \Test\TestCase { $this->certificateManager->addCertificate('InvalidCertificate', 'invalidCertificate'); } - /** - * @return array - */ - public function dangerousFileProvider() { + public static function dangerousFileProvider(): array { return [ ['.htaccess'], ['../../foo.txt'], @@ -153,7 +150,7 @@ class CertificateManagerTest extends \Test\TestCase { /** @var CertificateManager | \PHPUnit\Framework\MockObject\MockObject $certificateManager */ $certificateManager = $this->getMockBuilder('OC\Security\CertificateManager') ->setConstructorArgs([$view, $config, $this->createMock(LoggerInterface::class), $this->random]) - ->setMethods(['getFilemtimeOfCaBundle', 'getCertificateBundle']) + ->onlyMethods(['getFilemtimeOfCaBundle', 'getCertificateBundle']) ->getMock(); $certificateManager->expects($this->any())->method('getFilemtimeOfCaBundle') @@ -181,7 +178,7 @@ class CertificateManagerTest extends \Test\TestCase { ); } - public function dataTestNeedRebundling() { + public static function dataTestNeedRebundling(): array { return [ //values: CaBundleMtime, targetBundleMtime, targetBundleExists, expected diff --git a/tests/lib/Security/CredentialsManagerTest.php b/tests/lib/Security/CredentialsManagerTest.php index ce60a2f62a2..d5e7a114667 100644 --- a/tests/lib/Security/CredentialsManagerTest.php +++ b/tests/lib/Security/CredentialsManagerTest.php @@ -50,7 +50,7 @@ class CredentialsManagerTest extends \Test\TestCase { $this->assertSame($secretsRev, $received); } - public function credentialsProvider(): array { + public static function credentialsProvider(): array { return [ [ 'alice', diff --git a/tests/lib/Security/CryptoTest.php b/tests/lib/Security/CryptoTest.php index 79140b34456..64042d0c5a9 100644 --- a/tests/lib/Security/CryptoTest.php +++ b/tests/lib/Security/CryptoTest.php @@ -13,7 +13,7 @@ namespace Test\Security; use OC\Security\Crypto; class CryptoTest extends \Test\TestCase { - public function defaultEncryptionProvider() { + public static function defaultEncryptionProvider(): array { return [ ['Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt.'], [''], diff --git a/tests/lib/Security/HasherTest.php b/tests/lib/Security/HasherTest.php index 41cad7f323f..11b63e8ec88 100644 --- a/tests/lib/Security/HasherTest.php +++ b/tests/lib/Security/HasherTest.php @@ -17,10 +17,7 @@ use OCP\IConfig; * Class HasherTest */ class HasherTest extends \Test\TestCase { - /** - * @return array - */ - public function versionHashProvider() { + public static function versionHashProvider(): array { return [ ['asf32äà$$a.|3', null], ['asf32äà$$a.|3|5', null], @@ -30,7 +27,7 @@ class HasherTest extends \Test\TestCase { ]; } - public function hashProviders70_71(): array { + public static function hashProviders70_71(): array { return [ // Valid SHA1 strings ['password', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', true], @@ -66,7 +63,7 @@ class HasherTest extends \Test\TestCase { ]; } - public function hashProviders72(): array { + public static function hashProviders72(): array { return [ // Valid ARGON2 hashes ['password', '2|$argon2i$v=19$m=1024,t=2,p=2$T3JGcEkxVFNOVktNSjZUcg$4/hyLtSejxNgAuzSFFV/HLM3qRQKBwEtKw61qPN4zWA', true], @@ -83,7 +80,7 @@ class HasherTest extends \Test\TestCase { ]; } - public function hashProviders73(): array { + public static function hashProviders73(): array { return [ // Valid ARGON2ID hashes ['password', '2|$argon2id$v=19$m=65536,t=4,p=1$TEtIMnhUczliQzI0Y01WeA$BpMUDrApy25iagIogUAnlc0rNTPJmGs8lOEeVHujJ9Q', true], diff --git a/tests/lib/Security/IdentityProof/ManagerTest.php b/tests/lib/Security/IdentityProof/ManagerTest.php index 722555efe01..445158e8a23 100644 --- a/tests/lib/Security/IdentityProof/ManagerTest.php +++ b/tests/lib/Security/IdentityProof/ManagerTest.php @@ -75,7 +75,9 @@ class ManagerTest extends TestCase { $this->crypto, $this->config, $this->logger - ])->setMethods($setMethods)->getMock(); + ]) + ->onlyMethods($setMethods) + ->getMock(); } } @@ -104,14 +106,10 @@ class ManagerTest extends TestCase { $folder ->expects($this->exactly(2)) ->method('getFile') - ->withConsecutive( - ['private'], - ['public'] - ) - ->willReturnOnConsecutiveCalls( - $privateFile, - $publicFile - ); + ->willReturnMap([ + ['private', $privateFile], + ['public', $publicFile], + ]); $this->appData ->expects($this->once()) ->method('getFolder') @@ -155,14 +153,10 @@ class ManagerTest extends TestCase { $folder ->expects($this->exactly(2)) ->method('newFile') - ->withConsecutive( - ['private'], - ['public'] - ) - ->willReturnOnConsecutiveCalls( - $privateFile, - $publicFile - ); + ->willReturnMap([ + ['private', null, $privateFile], + ['public', null, $publicFile], + ]); $this->appData ->expects($this->exactly(2)) ->method('getFolder') diff --git a/tests/lib/Security/Ip/BruteforceAllowListTest.php b/tests/lib/Security/Ip/BruteforceAllowListTest.php index f7ef9e3df72..efdb7c4034c 100644 --- a/tests/lib/Security/Ip/BruteforceAllowListTest.php +++ b/tests/lib/Security/Ip/BruteforceAllowListTest.php @@ -42,7 +42,7 @@ class BruteforceAllowListTest extends TestCase { ); } - public function dataIsBypassListed(): array { + public static function dataIsBypassListed(): array { return [ [ '10.10.10.10', diff --git a/tests/lib/Security/Ip/RemoteAddressTest.php b/tests/lib/Security/Ip/RemoteAddressTest.php index d1f621796fe..63c1b452294 100644 --- a/tests/lib/Security/Ip/RemoteAddressTest.php +++ b/tests/lib/Security/Ip/RemoteAddressTest.php @@ -44,7 +44,7 @@ class RemoteAddressTest extends \Test\TestCase { /** * @return array<string, mixed, bool> */ - public function dataProvider(): array { + public static function dataProvider(): array { return [ // No IP (ie. CLI) ['', ['192.168.1.2/24'], true], diff --git a/tests/lib/Security/Normalizer/IpAddressTest.php b/tests/lib/Security/Normalizer/IpAddressTest.php index 33a8b4d28f1..29067596c98 100644 --- a/tests/lib/Security/Normalizer/IpAddressTest.php +++ b/tests/lib/Security/Normalizer/IpAddressTest.php @@ -13,7 +13,7 @@ use OC\Security\Normalizer\IpAddress; use Test\TestCase; class IpAddressTest extends TestCase { - public function subnetDataProvider() { + public static function subnetDataProvider(): array { return [ [ '64.233.191.254', diff --git a/tests/lib/Security/RateLimiting/LimiterTest.php b/tests/lib/Security/RateLimiting/LimiterTest.php index 92600e22de8..6f430e85576 100644 --- a/tests/lib/Security/RateLimiting/LimiterTest.php +++ b/tests/lib/Security/RateLimiting/LimiterTest.php @@ -12,21 +12,26 @@ namespace Test\Security\RateLimiting; use OC\Security\RateLimiting\Backend\IBackend; use OC\Security\RateLimiting\Limiter; use OCP\IUser; +use OCP\Security\RateLimiting\ILimiter; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Test\TestCase; class LimiterTest extends TestCase { - /** @var IBackend|\PHPUnit\Framework\MockObject\MockObject */ - private $backend; - /** @var Limiter */ - private $limiter; + + private IBackend&MockObject $backend; + private ILimiter $limiter; + private LoggerInterface $logger; protected function setUp(): void { parent::setUp(); $this->backend = $this->createMock(IBackend::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->limiter = new Limiter( - $this->backend + $this->backend, + $this->logger, ); } @@ -43,6 +48,8 @@ class LimiterTest extends TestCase { '4664f0d9c88dcb7552be47b37bb52ce35977b2e60e1ac13757cf625f31f87050a41f3da064887fa87d49fd042e4c8eb20de8f10464877d3959677ab011b73a47' ) ->willReturn(101); + $this->logger->expects($this->once()) + ->method('info'); $this->limiter->registerAnonRequest('MyIdentifier', 100, 100, '127.0.0.1'); } @@ -64,6 +71,8 @@ class LimiterTest extends TestCase { '4664f0d9c88dcb7552be47b37bb52ce35977b2e60e1ac13757cf625f31f87050a41f3da064887fa87d49fd042e4c8eb20de8f10464877d3959677ab011b73a47', 100 ); + $this->logger->expects($this->never()) + ->method('info'); $this->limiter->registerAnonRequest('MyIdentifier', 100, 100, '127.0.0.1'); } @@ -87,6 +96,8 @@ class LimiterTest extends TestCase { 'ddb2ec50fa973fd49ecf3d816f677c8095143e944ad10485f30fb3dac85c13a346dace4dae2d0a15af91867320957bfd38a43d9eefbb74fe6919e15119b6d805' ) ->willReturn(101); + $this->logger->expects($this->once()) + ->method('info'); $this->limiter->registerUserRequest('MyIdentifier', 100, 100, $user); } @@ -115,6 +126,8 @@ class LimiterTest extends TestCase { 'ddb2ec50fa973fd49ecf3d816f677c8095143e944ad10485f30fb3dac85c13a346dace4dae2d0a15af91867320957bfd38a43d9eefbb74fe6919e15119b6d805', 100 ); + $this->logger->expects($this->never()) + ->method('info'); $this->limiter->registerUserRequest('MyIdentifier', 100, 100, $user); } diff --git a/tests/lib/Security/RemoteHostValidatorIntegrationTest.php b/tests/lib/Security/RemoteHostValidatorIntegrationTest.php index 6cddb8b4ce9..3d319e828ff 100644 --- a/tests/lib/Security/RemoteHostValidatorIntegrationTest.php +++ b/tests/lib/Security/RemoteHostValidatorIntegrationTest.php @@ -37,7 +37,7 @@ class RemoteHostValidatorIntegrationTest extends TestCase { ); } - public function localHostsData(): array { + public static function localHostsData(): array { return [ ['[::1]'], ['[::]'], @@ -101,7 +101,7 @@ class RemoteHostValidatorIntegrationTest extends TestCase { self::assertTrue($isValid); } - public function externalAddressesData():array { + public static function externalAddressesData():array { return [ ['8.8.8.8'], ['8.8.4.4'], diff --git a/tests/lib/Security/RemoteHostValidatorTest.php b/tests/lib/Security/RemoteHostValidatorTest.php index c698ebbc3c6..46c969d28c1 100644 --- a/tests/lib/Security/RemoteHostValidatorTest.php +++ b/tests/lib/Security/RemoteHostValidatorTest.php @@ -44,7 +44,7 @@ class RemoteHostValidatorTest extends TestCase { ); } - public function dataValid(): array { + public static function dataValid(): array { return [ ['nextcloud.com', true], ['com.one-.nextcloud-one.com', false], diff --git a/tests/lib/Security/SecureRandomTest.php b/tests/lib/Security/SecureRandomTest.php index 8000917579b..98eb0e45df3 100644 --- a/tests/lib/Security/SecureRandomTest.php +++ b/tests/lib/Security/SecureRandomTest.php @@ -13,7 +13,7 @@ namespace Test\Security; use OC\Security\SecureRandom; class SecureRandomTest extends \Test\TestCase { - public function stringGenerationProvider() { + public static function stringGenerationProvider(): array { return [ [1, 1], [128, 128], @@ -24,7 +24,7 @@ class SecureRandomTest extends \Test\TestCase { ]; } - public static function charCombinations() { + public static function charCombinations(): array { return [ ['CHAR_LOWER', '[a-z]'], ['CHAR_UPPER', '[A-Z]'], @@ -76,7 +76,7 @@ class SecureRandomTest extends \Test\TestCase { $this->assertSame(1, $matchesRegex); } - public static function invalidLengths() { + public static function invalidLengths(): array { return [ [0], [-1], diff --git a/tests/lib/Security/TrustedDomainHelperTest.php b/tests/lib/Security/TrustedDomainHelperTest.php index 656b7a77206..1b9ba20a906 100644 --- a/tests/lib/Security/TrustedDomainHelperTest.php +++ b/tests/lib/Security/TrustedDomainHelperTest.php @@ -63,7 +63,7 @@ class TrustedDomainHelperTest extends \Test\TestCase { /** * @return array */ - public function trustedDomainDataProvider() { + public static function trustedDomainDataProvider(): array { $trustedHostTestList = [ 'host.one.test', 'host.two.test', |