From 298f7c4704b83f602839c1ac21931992500823dd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 10 Jul 2020 15:58:21 +0200 Subject: [PATCH] Objects are always passed by reference Signed-off-by: Joas Schilling --- lib/Db/RegistrationMapper.php | 6 +++--- lib/Service/RegistrationService.php | 14 +++++--------- .../Controller/RegisterControllerTest.php | 3 --- .../Service/RegistrationServiceTest.php | 5 ----- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/lib/Db/RegistrationMapper.php b/lib/Db/RegistrationMapper.php index 6f8fcb9..c2be0e6 100644 --- a/lib/Db/RegistrationMapper.php +++ b/lib/Db/RegistrationMapper.php @@ -84,7 +84,7 @@ class RegistrationMapper extends Mapper { /** * @param Registration $registration */ - public function generateNewToken(Registration &$registration) { + public function generateNewToken(Registration $registration) { $token = $this->random->generate(10, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS); $registration->setToken($token); } @@ -92,8 +92,8 @@ class RegistrationMapper extends Mapper { /** * @param Registration $registration */ - public function generateClientSecret(Registration &$registration) { - $token = $this->random->generate(32, "abcdefgijkmnopqrstwxyzABCDEFGHJKLMNPQRSTWXYZ23456789"); + public function generateClientSecret(Registration $registration) { + $token = $this->random->generate(32, 'abcdefgijkmnopqrstwxyzABCDEFGHJKLMNPQRSTWXYZ23456789'); //FIXME eqivalent to ISecureRandom::CHAR_HUMAN_READABLE introduced in https://github.com/nextcloud/server/commit/f2a2b34e4639e88f8d948a388a51f010212b42a3 but not supported in ownCloud yet. We'll just use the string for now then switch to constants when supported. $registration->setClientSecret($token); } diff --git a/lib/Service/RegistrationService.php b/lib/Service/RegistrationService.php index 592801b..e29c2ee 100644 --- a/lib/Service/RegistrationService.php +++ b/lib/Service/RegistrationService.php @@ -36,7 +36,6 @@ use OCA\Registration\Db\RegistrationMapper; use OCP\AppFramework\Db\DoesNotExistException; use \OCP\AppFramework\Http\TemplateResponse; use \OCP\AppFramework\Http\RedirectResponse; -use \OCP\Defaults; use OCP\ILogger; use OCP\IRequest; use OCP\ISession; @@ -68,8 +67,6 @@ class RegistrationService { private $config; /** @var IGroupManager */ private $groupManager; - /** @var \OCP\Defaults */ - private $defaults; /** @var ISecureRandom */ private $random; /** @var IUserSession */ @@ -86,7 +83,7 @@ class RegistrationService { private $crypto; public function __construct($appName, MailService $mailService, IL10N $l10n, IURLGenerator $urlGenerator, - RegistrationMapper $registrationMapper, IUserManager $userManager, IConfig $config, IGroupManager $groupManager, Defaults $defaults, + RegistrationMapper $registrationMapper, IUserManager $userManager, IConfig $config, IGroupManager $groupManager, ISecureRandom $random, IUserSession $us, IRequest $request, ILogger $logger, ISession $session, IProvider $tokenProvider, ICrypto $crypto) { $this->appName = $appName; $this->mailService = $mailService; @@ -96,7 +93,6 @@ class RegistrationService { $this->userManager = $userManager; $this->config = $config; $this->groupManager = $groupManager; - $this->defaults = $defaults; $this->random = $random; $this->usersession = $us; $this->request = $request; @@ -109,7 +105,7 @@ class RegistrationService { /** * @param Registration $registration */ - public function confirmEmail(Registration &$registration) { + public function confirmEmail(Registration $registration) { $registration->setEmailConfirmed(true); $this->registrationMapper->update($registration); } @@ -117,7 +113,7 @@ class RegistrationService { /** * @param Registration $registration */ - public function generateNewToken(Registration &$registration) { + public function generateNewToken(Registration $registration) { $this->registrationMapper->generateNewToken($registration); $this->registrationMapper->update($registration); } @@ -255,9 +251,9 @@ class RegistrationService { * @param string $username * @param string $password * @return \OCP\IUser - * @throws RegistrationException|\InvalidTokenException + * @throws RegistrationException|InvalidTokenException */ - public function createAccount(Registration &$registration, $username = null, $password = null) { + public function createAccount(Registration $registration, $username = null, $password = null) { if ($password === null && $registration->getPassword() === null) { $generatedPassword = $this->generateRandomDeviceToken(); $registration->setPassword($this->crypto->encrypt($generatedPassword)); diff --git a/tests/Integration/Controller/RegisterControllerTest.php b/tests/Integration/Controller/RegisterControllerTest.php index 2690e75..bde08b5 100644 --- a/tests/Integration/Controller/RegisterControllerTest.php +++ b/tests/Integration/Controller/RegisterControllerTest.php @@ -6,7 +6,6 @@ use OCA\Registration\Controller\RegisterController; use OCA\Registration\Db\RegistrationMapper; use OCA\Registration\Service\MailService; use OCA\Registration\Service\RegistrationService; -use OCP\Defaults; use OCP\IConfig; use OCP\IGroupManager; use OCP\IL10N; @@ -73,7 +72,6 @@ class RegisterControllerTest extends TestCase { $this->userManager = \OC::$server->getUserManager(); $this->config = $this->createMock(IConfig::class); $this->groupManager = \OC::$server->getGroupManager(); - $this->defaults = $this->createMock(Defaults::class); $this->random = \OC::$server->getSecureRandom(); $this->usersession = $this->createMock(IUserSession::class); $this->request = $this->createMock(IRequest::class); @@ -96,7 +94,6 @@ class RegisterControllerTest extends TestCase { $this->userManager, $this->config, $this->groupManager, - $this->defaults, $this->random, $this->usersession, $this->request, diff --git a/tests/Integration/Service/RegistrationServiceTest.php b/tests/Integration/Service/RegistrationServiceTest.php index e1f8c7f..0ab0aaa 100644 --- a/tests/Integration/Service/RegistrationServiceTest.php +++ b/tests/Integration/Service/RegistrationServiceTest.php @@ -7,7 +7,6 @@ use OCA\Registration\Db\RegistrationMapper; use OCA\Registration\Service\MailService; use OCA\Registration\Service\RegistrationException; use OCA\Registration\Service\RegistrationService; -use OCP\Defaults; use OCP\IConfig; use OCP\IGroupManager; use OCP\IL10N; @@ -47,8 +46,6 @@ class RegistrationServiceTest extends TestCase { private $config; /** @var IGroupManager */ private $groupManager; - /** @var \OCP\Defaults */ - private $defaults; /** @var ISecureRandom */ private $random; /** @var IUserSession */ @@ -73,7 +70,6 @@ class RegistrationServiceTest extends TestCase { $this->userManager = \OC::$server->getUserManager(); $this->config = $this->createMock(IConfig::class); $this->groupManager = \OC::$server->getGroupManager(); - $this->defaults = $this->createMock(Defaults::class); $this->random = \OC::$server->getSecureRandom(); $this->usersession = $this->createMock(IUserSession::class); $this->request = $this->createMock(IRequest::class); @@ -96,7 +92,6 @@ class RegistrationServiceTest extends TestCase { $this->userManager, $this->config, $this->groupManager, - $this->defaults, $this->random, $this->usersession, $this->request,