diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2019-11-27 15:27:18 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-11-27 15:27:18 +0100 |
commit | 3a7cf40aaa678bea1df143d2982d603b7a334eec (patch) | |
tree | 63c1e3ad7f7f401d14411a4d44c523632906afc9 /tests/lib/Security | |
parent | 0568b012672d650c6b5a49e72c4028dde5463c60 (diff) | |
download | nextcloud-server-3a7cf40aaa678bea1df143d2982d603b7a334eec.tar.gz nextcloud-server-3a7cf40aaa678bea1df143d2982d603b7a334eec.zip |
Mode to modern phpunit
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests/lib/Security')
16 files changed, 54 insertions, 52 deletions
diff --git a/tests/lib/Security/Bruteforce/CapabilitiesTest.php b/tests/lib/Security/Bruteforce/CapabilitiesTest.php index 001d9983617..60873236e44 100644 --- a/tests/lib/Security/Bruteforce/CapabilitiesTest.php +++ b/tests/lib/Security/Bruteforce/CapabilitiesTest.php @@ -36,7 +36,7 @@ class CapabilitiesTest extends TestCase { /** @var Throttler|\PHPUnit_Framework_MockObject_MockObject */ private $throttler; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->request = $this->createMock(IRequest::class); diff --git a/tests/lib/Security/Bruteforce/ThrottlerTest.php b/tests/lib/Security/Bruteforce/ThrottlerTest.php index 7fbcd763ce6..048540fb5a5 100644 --- a/tests/lib/Security/Bruteforce/ThrottlerTest.php +++ b/tests/lib/Security/Bruteforce/ThrottlerTest.php @@ -44,7 +44,7 @@ class ThrottlerTest extends TestCase { /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ private $config; - public function setUp(): void { + protected function setUp(): void { $this->dbConnection = $this->createMock(IDBConnection::class); $this->logger = $this->createMock(ILogger::class); $this->config = $this->createMock(IConfig::class); diff --git a/tests/lib/Security/CSP/ContentSecurityPolicyManagerTest.php b/tests/lib/Security/CSP/ContentSecurityPolicyManagerTest.php index e96111a06df..009613fbe32 100644 --- a/tests/lib/Security/CSP/ContentSecurityPolicyManagerTest.php +++ b/tests/lib/Security/CSP/ContentSecurityPolicyManagerTest.php @@ -37,7 +37,7 @@ class ContentSecurityPolicyManagerTest extends TestCase { /** @var ContentSecurityPolicyManager */ private $contentSecurityPolicyManager; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->dispatcher = \OC::$server->query(IEventDispatcher::class); $this->contentSecurityPolicyManager = new ContentSecurityPolicyManager($this->dispatcher); diff --git a/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php b/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php index cb2a8f0d931..346ace943d9 100644 --- a/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php +++ b/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php @@ -35,7 +35,7 @@ class ContentSecurityPolicyNonceManagerTest extends TestCase { /** @var ContentSecurityPolicyNonceManager */ private $nonceManager; - public function setUp(): void { + protected function setUp(): void { $this->csrfTokenManager = $this->createMock(CsrfTokenManager::class); $this->request = $this->createMock(Request::class); $this->nonceManager = new ContentSecurityPolicyNonceManager( diff --git a/tests/lib/Security/CSRF/CsrfTokenGeneratorTest.php b/tests/lib/Security/CSRF/CsrfTokenGeneratorTest.php index 314902fb725..5ab15c73bf2 100644 --- a/tests/lib/Security/CSRF/CsrfTokenGeneratorTest.php +++ b/tests/lib/Security/CSRF/CsrfTokenGeneratorTest.php @@ -27,7 +27,7 @@ class CsrfTokenGeneratorTest extends \Test\TestCase { /** @var \OC\Security\CSRF\CsrfTokenGenerator */ private $csrfTokenGenerator; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->random = $this->getMockBuilder('\OCP\Security\ISecureRandom') ->disableOriginalConstructor()->getMock(); diff --git a/tests/lib/Security/CSRF/CsrfTokenManagerTest.php b/tests/lib/Security/CSRF/CsrfTokenManagerTest.php index 0f9755c2251..29fbbfe3b26 100644 --- a/tests/lib/Security/CSRF/CsrfTokenManagerTest.php +++ b/tests/lib/Security/CSRF/CsrfTokenManagerTest.php @@ -29,7 +29,7 @@ class CsrfTokenManagerTest extends \Test\TestCase { /** @var \OC\Security\CSRF\TokenStorage\SessionStorage */ private $storageInterface; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->tokenGenerator = $this->getMockBuilder('\OC\Security\CSRF\CsrfTokenGenerator') ->disableOriginalConstructor()->getMock(); diff --git a/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php b/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php index 19b13f76d86..8d4a966efea 100644 --- a/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php +++ b/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php @@ -29,7 +29,7 @@ class SessionStorageTest extends \Test\TestCase { /** @var \OC\Security\CSRF\TokenStorage\SessionStorage */ private $sessionStorage; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->session = $this->getMockBuilder(ISession::class) ->disableOriginalConstructor()->getMock(); @@ -54,10 +54,11 @@ class SessionStorageTest extends \Test\TestCase { * @param string $token * @dataProvider getTokenDataProvider * - * @expectedException \Exception - * @expectedExceptionMessage Session does not contain a requesttoken */ public function testGetTokenWithEmptyToken($token) { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Session does not contain a requesttoken'); + $this->session ->expects($this->once()) ->method('get') diff --git a/tests/lib/Security/CertificateManagerTest.php b/tests/lib/Security/CertificateManagerTest.php index e7d15e65c52..136c3160413 100644 --- a/tests/lib/Security/CertificateManagerTest.php +++ b/tests/lib/Security/CertificateManagerTest.php @@ -93,11 +93,11 @@ class CertificateManagerTest extends \Test\TestCase { $this->assertEqualsArrays($certificateStore, $this->certificateManager->listCertificates()); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Certificate could not get parsed. - */ + function testAddInvalidCertificate() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Certificate could not get parsed.'); + $this->certificateManager->addCertificate('InvalidCertificate', 'invalidCertificate'); } @@ -113,12 +113,13 @@ class CertificateManagerTest extends \Test\TestCase { } /** - * @expectedException \Exception - * @expectedExceptionMessage Filename is not valid * @dataProvider dangerousFileProvider * @param string $filename */ function testAddDangerousFile($filename) { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Filename is not valid'); + $this->certificateManager->addCertificate(file_get_contents(__DIR__ . '/../../data/certificates/expiredCertificate.crt'), $filename); } diff --git a/tests/lib/Security/CertificateTest.php b/tests/lib/Security/CertificateTest.php index c9d6ea90bd6..986554cf967 100644 --- a/tests/lib/Security/CertificateTest.php +++ b/tests/lib/Security/CertificateTest.php @@ -43,20 +43,20 @@ class CertificateTest extends \Test\TestCase { $this->expiredCertificate = new Certificate($expiredCertificate, 'ExpiredCertificate'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Certificate could not get parsed. - */ + public function testBogusData() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Certificate could not get parsed.'); + $certificate = new Certificate('foo', 'bar'); $certificate->getIssueDate(); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Certificate could not get parsed. - */ + function testCertificateStartingWithFileReference() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Certificate could not get parsed.'); + new Certificate('file://'.__DIR__ . '/../../data/certificates/goodCertificate.crt', 'bar'); } diff --git a/tests/lib/Security/CryptoTest.php b/tests/lib/Security/CryptoTest.php index b0032a555fd..a2c8055750b 100644 --- a/tests/lib/Security/CryptoTest.php +++ b/tests/lib/Security/CryptoTest.php @@ -37,11 +37,11 @@ class CryptoTest extends \Test\TestCase { $this->assertEquals($stringToEncrypt, $this->crypto->decrypt($ciphertext)); } - /** - * @expectedException \Exception - * @expectedExceptionMessage HMAC does not match. - */ + function testWrongPassword() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('HMAC does not match.'); + $stringToEncrypt = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt.'; $ciphertext = $this->crypto->encrypt($stringToEncrypt); $this->crypto->decrypt($ciphertext, 'A wrong password!'); @@ -53,20 +53,20 @@ class CryptoTest extends \Test\TestCase { $this->assertEquals($stringToEncrypt, $this->crypto->decrypt($encryptedString, 'ThisIsAVeryS3cur3P4ssw0rd')); } - /** - * @expectedException \Exception - * @expectedExceptionMessage HMAC does not match. - */ + function testWrongIV() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('HMAC does not match.'); + $encryptedString = '560f5436ba864b9f12f7f7ca6d41c327554a6f2c0a160a03316b202af07c65163274993f3a46e7547c07ba89304f00594a2f3bd99f83859097c58049c39d0d4ade10e0de914ff0604961e7c849d0271ed6c0b23f984ba16e7d033e3305fb0910e7b6a2a65c988d17dbee71d8f953684d|d2kdFUspVjC0o0sr|1a5feacf87eaa6869a6abdfba9a296e7bbad45b6ad89f7dce67cdc98e2da5dc4379cc672cc655e52bbf19599bf59482fbea13a73937697fa656bf10f3fc4f1aa'; $this->crypto->decrypt($encryptedString, 'ThisIsAVeryS3cur3P4ssw0rd'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Authenticated ciphertext could not be decoded. - */ + function testWrongParameters() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Authenticated ciphertext could not be decoded.'); + $encryptedString = '1|2'; $this->crypto->decrypt($encryptedString, 'ThisIsAVeryS3cur3P4ssw0rd'); } diff --git a/tests/lib/Security/FeaturePolicy/FeaturePolicyManagerTest.php b/tests/lib/Security/FeaturePolicy/FeaturePolicyManagerTest.php index ec8ffbee77b..179bd6630ba 100644 --- a/tests/lib/Security/FeaturePolicy/FeaturePolicyManagerTest.php +++ b/tests/lib/Security/FeaturePolicy/FeaturePolicyManagerTest.php @@ -42,7 +42,7 @@ class FeaturePolicyManagerTest extends TestCase { /** @var FeaturePolicyManager */ private $manager; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->dispatcher = \OC::$server->query(IEventDispatcher::class); $this->manager = new FeaturePolicyManager($this->dispatcher); diff --git a/tests/lib/Security/IdentityProof/KeyTest.php b/tests/lib/Security/IdentityProof/KeyTest.php index 34493df9878..ae5f77f1609 100644 --- a/tests/lib/Security/IdentityProof/KeyTest.php +++ b/tests/lib/Security/IdentityProof/KeyTest.php @@ -30,7 +30,7 @@ class KeyTest extends TestCase { /** @var Key */ private $key; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->key = new Key('public', 'private'); diff --git a/tests/lib/Security/IdentityProof/ManagerTest.php b/tests/lib/Security/IdentityProof/ManagerTest.php index 9e58ac5c00f..aff6d3ed5c7 100644 --- a/tests/lib/Security/IdentityProof/ManagerTest.php +++ b/tests/lib/Security/IdentityProof/ManagerTest.php @@ -50,7 +50,7 @@ class ManagerTest extends TestCase { /** @var ILogger|MockObject */ private $logger; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); /** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */ @@ -219,10 +219,10 @@ class ManagerTest extends TestCase { } - /** - * @expectedException \RuntimeException - */ + public function testGetSystemKeyFailure() { + $this->expectException(\RuntimeException::class); + $manager = $this->getManager(['retrieveKey']); /** @var Key|\PHPUnit_Framework_MockObject_MockObject $key */ diff --git a/tests/lib/Security/IdentityProof/SignerTest.php b/tests/lib/Security/IdentityProof/SignerTest.php index 850ae08d4f0..884065e6a1a 100644 --- a/tests/lib/Security/IdentityProof/SignerTest.php +++ b/tests/lib/Security/IdentityProof/SignerTest.php @@ -89,7 +89,7 @@ gQIDAQAB /** @var Signer */ private $signer; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->key = new Key($this->public, $this->private); diff --git a/tests/lib/Security/RateLimiting/Backend/MemoryCacheTest.php b/tests/lib/Security/RateLimiting/Backend/MemoryCacheTest.php index d117f7d8c70..e4df424c2ca 100644 --- a/tests/lib/Security/RateLimiting/Backend/MemoryCacheTest.php +++ b/tests/lib/Security/RateLimiting/Backend/MemoryCacheTest.php @@ -37,7 +37,7 @@ class MemoryCacheTest extends TestCase { /** @var MemoryCache */ private $memoryCache; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->cacheFactory = $this->createMock(ICacheFactory::class); diff --git a/tests/lib/Security/RateLimiting/LimiterTest.php b/tests/lib/Security/RateLimiting/LimiterTest.php index 1e72f8e4960..20b35029050 100644 --- a/tests/lib/Security/RateLimiting/LimiterTest.php +++ b/tests/lib/Security/RateLimiting/LimiterTest.php @@ -38,7 +38,7 @@ class LimiterTest extends TestCase { /** @var Limiter */ private $limiter; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->timeFactory = $this->createMock(ITimeFactory::class); @@ -50,11 +50,11 @@ class LimiterTest extends TestCase { ); } - /** - * @expectedException \OC\Security\RateLimiting\Exception\RateLimitExceededException - * @expectedExceptionMessage Rate limit exceeded - */ + public function testRegisterAnonRequestExceeded() { + $this->expectException(\OC\Security\RateLimiting\Exception\RateLimitExceededException::class); + $this->expectExceptionMessage('Rate limit exceeded'); + $this->backend ->expects($this->once()) ->method('getAttempts') @@ -94,11 +94,11 @@ class LimiterTest extends TestCase { $this->limiter->registerAnonRequest('MyIdentifier', 100, 100, '127.0.0.1'); } - /** - * @expectedException \OC\Security\RateLimiting\Exception\RateLimitExceededException - * @expectedExceptionMessage Rate limit exceeded - */ + public function testRegisterUserRequestExceeded() { + $this->expectException(\OC\Security\RateLimiting\Exception\RateLimitExceededException::class); + $this->expectExceptionMessage('Rate limit exceeded'); + /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */ $user = $this->createMock(IUser::class); $user |