diff options
Diffstat (limited to 'tests/lib/Authentication')
9 files changed, 45 insertions, 41 deletions
diff --git a/tests/lib/Authentication/Listeners/UserDeletedTokenCleanupListenerTest.php b/tests/lib/Authentication/Listeners/UserDeletedTokenCleanupListenerTest.php index a7590cdd244..1861a5b2150 100644 --- a/tests/lib/Authentication/Listeners/UserDeletedTokenCleanupListenerTest.php +++ b/tests/lib/Authentication/Listeners/UserDeletedTokenCleanupListenerTest.php @@ -91,7 +91,7 @@ class UserDeletedTokenCleanupListenerTest extends TestCase { ]; $this->manager->expects($this->exactly(3)) ->method('invalidateTokenById') - ->willReturnCallback(function () use (&$calls) { + ->willReturnCallback(function () use (&$calls): void { $expected = array_shift($calls); $this->assertEquals($expected, func_get_args()); }); diff --git a/tests/lib/Authentication/LoginCredentials/StoreTest.php b/tests/lib/Authentication/LoginCredentials/StoreTest.php index 072ec2ab571..aca586b91ec 100644 --- a/tests/lib/Authentication/LoginCredentials/StoreTest.php +++ b/tests/lib/Authentication/LoginCredentials/StoreTest.php @@ -111,7 +111,7 @@ class StoreTest extends TestCase { public function testGetLoginCredentialsSessionNotAvailable(): void { $this->session->expects($this->once()) ->method('getId') - ->will($this->throwException(new SessionNotAvailableException())); + ->willThrowException(new SessionNotAvailableException()); $this->expectException(CredentialsUnavailableException::class); $this->store->getLoginCredentials(); @@ -124,7 +124,7 @@ class StoreTest extends TestCase { $this->tokenProvider->expects($this->once()) ->method('getToken') ->with('sess2233') - ->will($this->throwException(new InvalidTokenException())); + ->willThrowException(new InvalidTokenException()); $this->expectException(CredentialsUnavailableException::class); $this->store->getLoginCredentials(); @@ -141,7 +141,7 @@ class StoreTest extends TestCase { $this->tokenProvider->expects($this->once()) ->method('getToken') ->with('sess2233') - ->will($this->throwException(new InvalidTokenException())); + ->willThrowException(new InvalidTokenException()); $this->session->expects($this->once()) ->method('exists') ->with($this->equalTo('login_credentials')) @@ -181,7 +181,7 @@ class StoreTest extends TestCase { $this->tokenProvider->expects($this->once()) ->method('getToken') ->with('sess2233') - ->will($this->throwException(new InvalidTokenException())); + ->willThrowException(new InvalidTokenException()); $this->session->expects($this->once()) ->method('exists') ->with($this->equalTo('login_credentials')) @@ -222,7 +222,7 @@ class StoreTest extends TestCase { $this->tokenProvider->expects($this->once()) ->method('getToken') ->with('sess2233') - ->will($this->throwException(new InvalidTokenException())); + ->willThrowException(new InvalidTokenException()); $this->session->expects($this->once()) ->method('exists') ->with($this->equalTo('login_credentials')) @@ -248,7 +248,7 @@ class StoreTest extends TestCase { $this->tokenProvider->expects($this->once()) ->method('getToken') ->with('sess2233') - ->will($this->throwException(new PasswordlessTokenException())); + ->willThrowException(new PasswordlessTokenException()); $this->expectException(CredentialsUnavailableException::class); $this->store->getLoginCredentials(); @@ -276,7 +276,7 @@ class StoreTest extends TestCase { $this->tokenProvider->expects($this->once()) ->method('getToken') ->with('sess2233') - ->will($this->throwException(new PasswordlessTokenException())); + ->willThrowException(new PasswordlessTokenException()); $this->session->expects($this->once()) ->method('exists') diff --git a/tests/lib/Authentication/Token/ManagerTest.php b/tests/lib/Authentication/Token/ManagerTest.php index 0f95d1d2f2c..300517fab4a 100644 --- a/tests/lib/Authentication/Token/ManagerTest.php +++ b/tests/lib/Authentication/Token/ManagerTest.php @@ -382,7 +382,7 @@ class ManagerTest extends TestCase { $this->publicKeyTokenProvider ->expects($this->exactly(2)) ->method('invalidateTokenById') - ->willReturnCallback(function () use (&$calls) { + ->willReturnCallback(function () use (&$calls): void { $expected = array_shift($calls); $this->assertEquals($expected, func_get_args()); }); diff --git a/tests/lib/Authentication/Token/PublicKeyTokenMapperTest.php b/tests/lib/Authentication/Token/PublicKeyTokenMapperTest.php index 7cc4e77ecb2..d1585dadc26 100644 --- a/tests/lib/Authentication/Token/PublicKeyTokenMapperTest.php +++ b/tests/lib/Authentication/Token/PublicKeyTokenMapperTest.php @@ -8,13 +8,14 @@ declare(strict_types=1); namespace Test\Authentication\Token; -use OC; use OC\Authentication\Token\PublicKeyToken; use OC\Authentication\Token\PublicKeyTokenMapper; +use OCP\AppFramework\Db\DoesNotExistException; use OCP\Authentication\Token\IToken; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; use OCP\IUser; +use OCP\Server; use Test\TestCase; /** @@ -33,7 +34,7 @@ class PublicKeyTokenMapperTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->dbConnection = OC::$server->getDatabaseConnection(); + $this->dbConnection = Server::get(IDBConnection::class); $this->time = time(); $this->resetDatabase(); @@ -178,7 +179,7 @@ class PublicKeyTokenMapperTest extends TestCase { public function testGetInvalidToken(): void { - $this->expectException(\OCP\AppFramework\Db\DoesNotExistException::class); + $this->expectException(DoesNotExistException::class); $token = 'thisisaninvalidtokenthatisnotinthedatabase'; @@ -210,14 +211,14 @@ class PublicKeyTokenMapperTest extends TestCase { public function testGetTokenByIdNotFound(): void { - $this->expectException(\OCP\AppFramework\Db\DoesNotExistException::class); + $this->expectException(DoesNotExistException::class); $this->mapper->getTokenById(-1); } public function testGetInvalidTokenById(): void { - $this->expectException(\OCP\AppFramework\Db\DoesNotExistException::class); + $this->expectException(DoesNotExistException::class); $id = '42'; diff --git a/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php b/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php index dc6ec7c7f3e..c6c4ec4198f 100644 --- a/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php +++ b/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php @@ -23,6 +23,7 @@ use OCP\IConfig; use OCP\IDBConnection; use OCP\Security\ICrypto; use OCP\Security\IHasher; +use OCP\Server; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -53,8 +54,8 @@ class PublicKeyTokenProviderTest extends TestCase { parent::setUp(); $this->mapper = $this->createMock(PublicKeyTokenMapper::class); - $this->hasher = \OC::$server->get(IHasher::class); - $this->crypto = \OC::$server->getCrypto(); + $this->hasher = Server::get(IHasher::class); + $this->crypto = Server::get(ICrypto::class); $this->config = $this->createMock(IConfig::class); $this->config->method('getSystemValue') ->willReturnMap([ @@ -232,7 +233,7 @@ class PublicKeyTokenProviderTest extends TestCase { public function testGetPasswordPasswordLessToken(): void { - $this->expectException(\OC\Authentication\Exceptions\PasswordlessTokenException::class); + $this->expectException(PasswordlessTokenException::class); $token = 'token1234'; $tk = new PublicKeyToken(); @@ -243,7 +244,7 @@ class PublicKeyTokenProviderTest extends TestCase { public function testGetPasswordInvalidToken(): void { - $this->expectException(\OC\Authentication\Exceptions\InvalidTokenException::class); + $this->expectException(InvalidTokenException::class); $token = 'tokentokentokentokentoken'; $uid = 'user'; @@ -294,7 +295,7 @@ class PublicKeyTokenProviderTest extends TestCase { public function testSetPasswordInvalidToken(): void { - $this->expectException(\OC\Authentication\Exceptions\InvalidTokenException::class); + $this->expectException(InvalidTokenException::class); $token = $this->createMock(IToken::class); $tokenId = 'token123'; @@ -311,7 +312,7 @@ class PublicKeyTokenProviderTest extends TestCase { $this->mapper->expects($this->exactly(2)) ->method('invalidate') - ->willReturnCallback(function () use (&$calls) { + ->willReturnCallback(function () use (&$calls): void { $expected = array_shift($calls); $this->assertEquals($expected, func_get_args()); }); @@ -350,7 +351,7 @@ class PublicKeyTokenProviderTest extends TestCase { ]; $this->mapper->expects($this->exactly(4)) ->method('invalidateOld') - ->willReturnCallback(function () use (&$calls) { + ->willReturnCallback(function () use (&$calls): void { $expected = array_shift($calls); $this->assertEquals($expected, func_get_args()); }); @@ -469,7 +470,7 @@ class PublicKeyTokenProviderTest extends TestCase { ]; $this->mapper->expects($this->exactly(2)) ->method('getToken') - ->willReturnCallback(function (string $token) use (&$calls) { + ->willReturnCallback(function (string $token) use (&$calls): void { $expected = array_shift($calls); $this->assertEquals(hash('sha512', $expected), $token); throw new DoesNotExistException('nope'); diff --git a/tests/lib/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDaoTest.php b/tests/lib/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDaoTest.php index 7a1ea64ca9a..b59ef876ffd 100644 --- a/tests/lib/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDaoTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDaoTest.php @@ -9,9 +9,9 @@ declare(strict_types=1); namespace Test\Authentication\TwoFactorAuth\Db; -use OC; use OC\Authentication\TwoFactorAuth\Db\ProviderUserAssignmentDao; use OCP\IDBConnection; +use OCP\Server; use Test\TestCase; /** @@ -27,7 +27,7 @@ class ProviderUserAssignmentDaoTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->dbConn = OC::$server->getDatabaseConnection(); + $this->dbConn = Server::get(IDBConnection::class); $qb = $this->dbConn->getQueryBuilder(); $q = $qb->delete(ProviderUserAssignmentDao::TABLE_NAME); $q->execute(); diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php index 75691627ce7..c68d1de60c5 100644 --- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php @@ -8,8 +8,9 @@ namespace Test\Authentication\TwoFactorAuth; -use OC; +use OC\Authentication\Exceptions\InvalidTokenException; use OC\Authentication\Token\IProvider as TokenProvider; +use OC\Authentication\Token\IToken; use OC\Authentication\TwoFactorAuth\Manager; use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor; use OC\Authentication\TwoFactorAuth\ProviderLoader; @@ -363,7 +364,7 @@ class ManagerTest extends TestCase { ]; $this->session->expects($this->exactly(2)) ->method('remove') - ->willReturnCallback(function () use (&$calls) { + ->willReturnCallback(function () use (&$calls): void { $expected = array_shift($calls); $this->assertEquals($expected, func_get_args()); }); @@ -404,7 +405,7 @@ class ManagerTest extends TestCase { 'provider' => 'Fake 2FA', ])) ->willReturnSelf(); - $token = $this->createMock(OC\Authentication\Token\IToken::class); + $token = $this->createMock(IToken::class); $this->tokenProvider->method('getToken') ->with('mysessionid') ->willReturn($token); @@ -496,7 +497,7 @@ class ManagerTest extends TestCase { $this->session->method('getId') ->willReturn('mysessionid'); - $token = $this->createMock(OC\Authentication\Token\IToken::class); + $token = $this->createMock(IToken::class); $this->tokenProvider->method('getToken') ->with('mysessionid') ->willReturn($token); @@ -567,14 +568,14 @@ class ManagerTest extends TestCase { ]; $this->session->expects($this->exactly(2)) ->method('set') - ->willReturnCallback(function () use (&$calls) { + ->willReturnCallback(function () use (&$calls): void { $expected = array_shift($calls); $this->assertEquals($expected, func_get_args()); }); $this->session->method('getId') ->willReturn('mysessionid'); - $token = $this->createMock(OC\Authentication\Token\IToken::class); + $token = $this->createMock(IToken::class); $this->tokenProvider->method('getToken') ->with('mysessionid') ->willReturn($token); @@ -601,14 +602,14 @@ class ManagerTest extends TestCase { ]; $this->session->expects($this->exactly(2)) ->method('set') - ->willReturnCallback(function () use (&$calls) { + ->willReturnCallback(function () use (&$calls): void { $expected = array_shift($calls); $this->assertEquals($expected, func_get_args()); }); $this->session->method('getId') ->willReturn('mysessionid'); - $token = $this->createMock(OC\Authentication\Token\IToken::class); + $token = $this->createMock(IToken::class); $this->tokenProvider->method('getToken') ->with('mysessionid') ->willReturn($token); @@ -669,7 +670,7 @@ class ManagerTest extends TestCase { $this->session->method('getId') ->willReturn('mysessionid'); - $token = $this->createMock(OC\Authentication\Token\IToken::class); + $token = $this->createMock(IToken::class); $token->method('getId') ->willReturn(40); @@ -704,7 +705,7 @@ class ManagerTest extends TestCase { $this->tokenProvider->method('getToken') ->with('mysessionid') - ->willThrowException(new OC\Authentication\Exceptions\InvalidTokenException()); + ->willThrowException(new InvalidTokenException()); $this->config->method('getUserKeys')->willReturn([]); @@ -736,7 +737,7 @@ class ManagerTest extends TestCase { ]; $this->config->expects($this->exactly(3)) ->method('deleteUserValue') - ->willReturnCallback(function () use (&$deleteUserValueCalls) { + ->willReturnCallback(function () use (&$deleteUserValueCalls): void { $expected = array_shift($deleteUserValueCalls); $this->assertEquals($expected, func_get_args()); }); @@ -748,7 +749,7 @@ class ManagerTest extends TestCase { ]; $this->tokenProvider->expects($this->exactly(3)) ->method('invalidateTokenById') - ->willReturnCallback(function () use (&$invalidateCalls) { + ->willReturnCallback(function () use (&$invalidateCalls): void { $expected = array_shift($invalidateCalls); $this->assertEquals($expected, func_get_args()); }); @@ -770,7 +771,7 @@ class ManagerTest extends TestCase { ]; $this->config->expects($this->exactly(3)) ->method('deleteUserValue') - ->willReturnCallback(function () use (&$deleteUserValueCalls) { + ->willReturnCallback(function () use (&$deleteUserValueCalls): void { $expected = array_shift($deleteUserValueCalls); $this->assertEquals($expected, func_get_args()); }); @@ -782,7 +783,7 @@ class ManagerTest extends TestCase { ]; $this->tokenProvider->expects($this->exactly(3)) ->method('invalidateTokenById') - ->willReturnCallback(function ($user, $tokenId) use (&$invalidateCalls) { + ->willReturnCallback(function ($user, $tokenId) use (&$invalidateCalls): void { $expected = array_shift($invalidateCalls); $this->assertEquals($expected, func_get_args()); if ($tokenId === 43) { diff --git a/tests/lib/Authentication/TwoFactorAuth/ProviderManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ProviderManagerTest.php index 34248f11f21..6004e67603b 100644 --- a/tests/lib/Authentication/TwoFactorAuth/ProviderManagerTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/ProviderManagerTest.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace lib\Authentication\TwoFactorAuth; +use OC\Authentication\Exceptions\InvalidProviderException; use OC\Authentication\TwoFactorAuth\ProviderLoader; use OC\Authentication\TwoFactorAuth\ProviderManager; use OCP\Authentication\TwoFactorAuth\IActivatableByAdmin; @@ -43,7 +44,7 @@ class ProviderManagerTest extends TestCase { public function testTryEnableInvalidProvider(): void { - $this->expectException(\OC\Authentication\Exceptions\InvalidProviderException::class); + $this->expectException(InvalidProviderException::class); $user = $this->createMock(IUser::class); $this->providerManager->tryEnableProviderFor('none', $user); @@ -89,7 +90,7 @@ class ProviderManagerTest extends TestCase { public function testTryDisableInvalidProvider(): void { - $this->expectException(\OC\Authentication\Exceptions\InvalidProviderException::class); + $this->expectException(InvalidProviderException::class); $user = $this->createMock(IUser::class); $this->providerManager->tryDisableProviderFor('none', $user); diff --git a/tests/lib/Authentication/TwoFactorAuth/RegistryTest.php b/tests/lib/Authentication/TwoFactorAuth/RegistryTest.php index 252b57e7983..2018dc1a634 100644 --- a/tests/lib/Authentication/TwoFactorAuth/RegistryTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/RegistryTest.php @@ -126,7 +126,7 @@ class RegistryTest extends TestCase { ]; $this->dispatcher->expects($this->exactly(2)) ->method('dispatchTyped') - ->willReturnCallback(function () use (&$calls) { + ->willReturnCallback(function () use (&$calls): void { $expected = array_shift($calls); $this->assertEquals($expected, func_get_args()); }); |