diff options
18 files changed, 128 insertions, 34 deletions
diff --git a/apps/dav/tests/unit/CalDAV/CalendarTest.php b/apps/dav/tests/unit/CalDAV/CalendarTest.php index e143820daeb..cfbc08d79dc 100644 --- a/apps/dav/tests/unit/CalDAV/CalendarTest.php +++ b/apps/dav/tests/unit/CalDAV/CalendarTest.php @@ -437,7 +437,8 @@ EOD; ->with('Busy') ->willReturn("Translated busy"); } else { - $l10n->expects($this->never()); + $l10n->expects($this->never()) + ->method('t'); } $c = new Calendar($backend, $calendarInfo, $l10n, $this->config); diff --git a/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php b/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php index 2fb97969655..87db11ddd69 100644 --- a/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php +++ b/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php @@ -34,6 +34,8 @@ use OCA\DAV\CalDAV\InvitationResponse\InvitationResponseServer; use OCA\DAV\Controller\InvitationResponseController; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\DB\IResult; +use OCP\DB\QueryBuilder\IExpressionBuilder; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; use OCP\IRequest; @@ -408,8 +410,8 @@ EOF; private function buildQueryExpects($token, $return, $time) { $queryBuilder = $this->createMock(IQueryBuilder::class); - $stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class); - $expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class); + $stmt = $this->createMock(IResult::class); + $expr = $this->createMock(IExpressionBuilder::class); $this->dbConnection->expects($this->once()) ->method('getQueryBuilder') diff --git a/apps/dav/tests/unit/Migration/RefreshWebcalJobRegistrarTest.php b/apps/dav/tests/unit/Migration/RefreshWebcalJobRegistrarTest.php index d857aa3d86b..87f7c79a770 100644 --- a/apps/dav/tests/unit/Migration/RefreshWebcalJobRegistrarTest.php +++ b/apps/dav/tests/unit/Migration/RefreshWebcalJobRegistrarTest.php @@ -29,6 +29,7 @@ namespace OCA\DAV\Tests\unit\DAV\Migration; use OCA\DAV\BackgroundJob\RefreshWebcalJob; use OCA\DAV\Migration\RefreshWebcalJobRegistrar; use OCP\BackgroundJob\IJobList; +use OCP\DB\IResult; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; use OCP\Migration\IOutput; @@ -62,7 +63,7 @@ class RefreshWebcalJobRegistrarTest extends TestCase { $output = $this->createMock(IOutput::class); $queryBuilder = $this->createMock(IQueryBuilder::class); - $statement = $this->createMock(\Doctrine\DBAL\Driver\Statement::class); + $statement = $this->createMock(IResult::class); $this->db->expects($this->once()) ->method('getQueryBuilder') diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index 1151d76c5e4..e795e7cfd92 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -257,7 +257,7 @@ class SMB extends Common implements INotifyStorage { // additionally, it's better to have false negatives here then false positives if ($acl->denies(ACL::MASK_READ) || $acl->denies(ACL::MASK_EXECUTE)) { $this->logger->debug('Hiding non readable entry ' . $file->getName()); - return false; + continue; } } diff --git a/apps/files_trashbin/tests/ExpirationTest.php b/apps/files_trashbin/tests/ExpirationTest.php index adef194f34f..d33c502f419 100644 --- a/apps/files_trashbin/tests/ExpirationTest.php +++ b/apps/files_trashbin/tests/ExpirationTest.php @@ -24,6 +24,8 @@ * */ +namespace OCA\Files_Trashbin\Tests; + use OCA\Files_Trashbin\Expiration; use OCP\AppFramework\Utility\ITimeFactory; use OCP\IConfig; @@ -118,16 +120,16 @@ class ExpirationTest extends \Test\TestCase { } - public function configData() { + public function timestampTestData(): array { return [ - [ 'disabled', null, null, null], - [ 'auto', Expiration::DEFAULT_RETENTION_OBLIGATION, Expiration::NO_OBLIGATION, true ], - [ 'auto,auto', Expiration::DEFAULT_RETENTION_OBLIGATION, Expiration::NO_OBLIGATION, true ], - [ 'auto, auto', Expiration::DEFAULT_RETENTION_OBLIGATION, Expiration::NO_OBLIGATION, true ], - [ 'auto, 3', Expiration::NO_OBLIGATION, 3, true ], - [ '5, auto', 5, Expiration::NO_OBLIGATION, true ], - [ '3, 5', 3, 5, false ], - [ '10, 3', 10, 10, false ], + [ 'disabled', false], + [ 'auto', false ], + [ 'auto,auto', false ], + [ 'auto, auto', false ], + [ 'auto, 3', self::FAKE_TIME_NOW - (3 * self::SECONDS_PER_DAY) ], + [ '5, auto', false ], + [ '3, 5', self::FAKE_TIME_NOW - (5 * self::SECONDS_PER_DAY) ], + [ '10, 3', self::FAKE_TIME_NOW - (10 * self::SECONDS_PER_DAY) ], ]; } diff --git a/apps/twofactor_backupcodes/appinfo/info.xml b/apps/twofactor_backupcodes/appinfo/info.xml index 0d50a66ea6a..513f7d0821a 100644 --- a/apps/twofactor_backupcodes/appinfo/info.xml +++ b/apps/twofactor_backupcodes/appinfo/info.xml @@ -5,7 +5,7 @@ <name>Two factor backup codes</name> <summary>A two-factor auth backup codes provider</summary> <description>A two-factor auth backup codes provider</description> - <version>1.10.0</version> + <version>1.10.1</version> <licence>agpl</licence> <author>Christoph Wurst</author> <namespace>TwoFactorBackupCodes</namespace> @@ -22,10 +22,6 @@ </post-migration> </repair-steps> - <two-factor-providers> - <provider>OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider</provider> - </two-factor-providers> - <activity> <providers> <provider>OCA\TwoFactorBackupCodes\Activity\Provider</provider> diff --git a/apps/twofactor_backupcodes/lib/AppInfo/Application.php b/apps/twofactor_backupcodes/lib/AppInfo/Application.php index 8751ccb8f6f..5dce6d3a8ee 100644 --- a/apps/twofactor_backupcodes/lib/AppInfo/Application.php +++ b/apps/twofactor_backupcodes/lib/AppInfo/Application.php @@ -36,6 +36,7 @@ use OCA\TwoFactorBackupCodes\Listener\ProviderEnabled; use OCA\TwoFactorBackupCodes\Listener\RegistryUpdater; use OCA\TwoFactorBackupCodes\Listener\UserDeleted; use OCA\TwoFactorBackupCodes\Notifications\Notifier; +use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; @@ -59,6 +60,9 @@ class Application extends App implements IBootstrap { $context->registerEventListener(IRegistry::EVENT_PROVIDER_ENABLED, ProviderEnabled::class); $context->registerEventListener(IRegistry::EVENT_PROVIDER_DISABLED, ProviderDisabled::class); $context->registerEventListener(UserDeletedEvent::class, UserDeleted::class); + + + $context->registerTwoFactorProvider(BackupCodesProvider::class); } public function boot(IBootContext $context): void { diff --git a/apps/twofactor_backupcodes/tests/Unit/Controller/SettingsControllerTest.php b/apps/twofactor_backupcodes/tests/Unit/Controller/SettingsControllerTest.php index db048a42749..e74f08043f7 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Controller/SettingsControllerTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Controller/SettingsControllerTest.php @@ -75,11 +75,11 @@ class SettingsControllerTest extends TestCase { $this->storage->expects($this->once()) ->method('getBackupCodesState') ->with($user) - ->willReturn('state'); + ->willReturn(['state']); $expected = [ 'codes' => $codes, - 'state' => 'state', + 'state' => ['state'], ]; $response = $this->controller->createCodes(); $this->assertInstanceOf(JSONResponse::class, $response); diff --git a/apps/twofactor_backupcodes/tests/Unit/Listener/ActivityPublisherTest.php b/apps/twofactor_backupcodes/tests/Unit/Listener/ActivityPublisherTest.php index 4a32faf0f67..4d93110514a 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Listener/ActivityPublisherTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Listener/ActivityPublisherTest.php @@ -89,8 +89,7 @@ class ActivityPublisherTest extends TestCase { ->with('fritz') ->willReturnSelf(); $this->activityManager->expects($this->once()) - ->method('publish') - ->willReturn($activityEvent); + ->method('publish'); $this->listener->handle($event); } diff --git a/apps/updatenotification/tests/Notification/BackgroundJobTest.php b/apps/updatenotification/tests/Notification/BackgroundJobTest.php index 09b1cb06d5a..1d94fba29ed 100644 --- a/apps/updatenotification/tests/Notification/BackgroundJobTest.php +++ b/apps/updatenotification/tests/Notification/BackgroundJobTest.php @@ -331,8 +331,7 @@ class BackgroundJobTest extends TestCase { \call_user_func_array([$mockedMethod, 'withConsecutive'], $userNotifications); $this->notificationManager->expects($this->exactly(\count($userNotifications))) - ->method('notify') - ->willReturn($notification); + ->method('notify'); } $this->notificationManager->expects($this->once()) diff --git a/apps/user_ldap/tests/Jobs/UpdateGroupsTest.php b/apps/user_ldap/tests/Jobs/UpdateGroupsTest.php index cb947c81a6f..63f60184a53 100644 --- a/apps/user_ldap/tests/Jobs/UpdateGroupsTest.php +++ b/apps/user_ldap/tests/Jobs/UpdateGroupsTest.php @@ -26,9 +26,9 @@ declare(strict_types=1); namespace OCA\user_ldap\tests\Jobs; -use Doctrine\DBAL\Driver\Statement; use OCA\User_LDAP\Group_Proxy; use OCA\User_LDAP\Jobs\UpdateGroups; +use OCP\DB\IResult; use OCP\DB\QueryBuilder\IExpressionBuilder; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\EventDispatcher\IEventDispatcher; @@ -124,7 +124,7 @@ class UpdateGroupsTest extends TestCase { ->method('expr') ->willReturn($this->createMock(IExpressionBuilder::class)); - $stmt = $this->createMock(Statement::class); + $stmt = $this->createMock(IResult::class); $stmt->expects($this->once()) ->method('fetchAll') ->willReturn($knownGroupsDB); diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php index 662296b8dd6..d056c088a9f 100644 --- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php +++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php @@ -92,7 +92,10 @@ class RegistrationContext { private $templateProviders = []; /** @var ServiceRegistration<INotifier>[] */ - private $notifierServices; + private $notifierServices = []; + + /** @var ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] */ + private $twoFactorProviders = []; /** @var ILogger */ private $logger; @@ -217,6 +220,13 @@ class RegistrationContext { $notifierClass ); } + + public function registerTwoFactorProvider(string $twoFactorProviderClass): void { + $this->context->registerTwoFactorProvider( + $this->appId, + $twoFactorProviderClass + ); + } }; } @@ -288,6 +298,10 @@ class RegistrationContext { $this->notifierServices[] = new ServiceRegistration($appId, $class); } + public function registerTwoFactorProvider(string $appId, string $class): void { + $this->twoFactorProviders[] = new ServiceRegistration($appId, $class); + } + /** * @param App[] $apps */ @@ -479,4 +493,11 @@ class RegistrationContext { public function getNotifierServices(): array { return $this->notifierServices; } + + /** + * @return ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] + */ + public function getTwoFactorProviders(): array { + return $this->twoFactorProviders; + } } diff --git a/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php b/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php index 40385d737ae..8dd19690242 100644 --- a/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php +++ b/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php @@ -40,8 +40,12 @@ class ProviderLoader { /** @var IAppManager */ private $appManager; - public function __construct(IAppManager $appManager) { + /** @var OC\AppFramework\Bootstrap\Coordinator */ + private $coordinator; + + public function __construct(IAppManager $appManager, OC\AppFramework\Bootstrap\Coordinator $coordinator) { $this->appManager = $appManager; + $this->coordinator = $coordinator; } /** @@ -72,6 +76,18 @@ class ProviderLoader { } } + $registeredProviders = $this->coordinator->getRegistrationContext()->getTwoFactorProviders(); + foreach ($registeredProviders as $provider) { + try { + $this->loadTwoFactorApp($provider->getAppId()); + $provider = OC::$server->query($provider->getService()); + $providers[$provider->getId()] = $provider; + } catch (QueryException $exc) { + // Provider class can not be resolved + throw new Exception('Could not load two-factor auth provider ' . $provider->getService()); + } + } + return $providers; } diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index ee64b45be64..44b6bfa2888 100644 --- a/lib/private/DB/MigrationService.php +++ b/lib/private/DB/MigrationService.php @@ -587,12 +587,12 @@ class MigrationService { throw new \InvalidArgumentException('Column name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.'); } - if ($thing->getNotnull() && $thing->getDefault() === '' + if ((!$sourceTable instanceof Table || !$sourceTable->hasColumn($thing->getName())) && $thing->getNotnull() && $thing->getDefault() === '' && $sourceTable instanceof Table && !$sourceTable->hasColumn($thing->getName())) { throw new \InvalidArgumentException('Column "' . $table->getName() . '"."' . $thing->getName() . '" is NotNull, but has empty string or null as default.'); } - if ($thing->getNotnull() && $thing->getType()->getName() === Types::BOOLEAN) { + if ((!$sourceTable instanceof Table || !$sourceTable->hasColumn($thing->getName())) && $thing->getNotnull() && $thing->getType()->getName() === Types::BOOLEAN) { throw new \InvalidArgumentException('Column "' . $table->getName() . '"."' . $thing->getName() . '" is type Bool and also NotNull, so it can not store "false".'); } } diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index 7b1eff47cd5..14b663d4e16 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -190,6 +190,9 @@ class Folder extends Node implements \OCP\Files\Folder { * @throws \OCP\Files\NotPermittedException */ public function newFile($path, $content = null) { + if (empty($path)) { + throw new NotPermittedException('Could not create as provided path is empty'); + } if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { $fullPath = $this->getFullPath($path); $nonExisting = new NonExistingFile($this->root, $this->view, $fullPath); diff --git a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php index 870df9663ea..4819d4e2119 100644 --- a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php +++ b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php @@ -30,6 +30,7 @@ declare(strict_types=1); namespace OCP\AppFramework\Bootstrap; use OCP\AppFramework\IAppContainer; +use OCP\Authentication\TwoFactorAuth\IProvider; use OCP\Capabilities\ICapability; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Template\ICustomTemplateProvider; @@ -219,4 +220,13 @@ interface IRegistrationContext { * @since 22.0.0 */ public function registerNotifierService(string $notifierClass): void; + + /** + * Register a two-factor provider + * + * @param string $twoFactorProviderClass + * @psalm-param class-string<IProvider> $twoFactorProviderClass + * @since 22.0.0 + */ + public function registerTwoFactorProvider(string $twoFactorProviderClass): void; } diff --git a/tests/lib/Authentication/TwoFactorAuth/ProviderLoaderTest.php b/tests/lib/Authentication/TwoFactorAuth/ProviderLoaderTest.php index 378376a41f9..1b813b5f36b 100644 --- a/tests/lib/Authentication/TwoFactorAuth/ProviderLoaderTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/ProviderLoaderTest.php @@ -26,9 +26,13 @@ declare(strict_types=1); namespace lib\Authentication\TwoFactorAuth; +use OC\AppFramework\Bootstrap\Coordinator; +use OC\AppFramework\Bootstrap\RegistrationContext; +use OC\AppFramework\Bootstrap\ServiceRegistration; use OC\Authentication\TwoFactorAuth\ProviderLoader; use OCP\App\IAppManager; use OCP\Authentication\TwoFactorAuth\IProvider; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class ProviderLoaderTest extends TestCase { @@ -39,6 +43,9 @@ class ProviderLoaderTest extends TestCase { /** @var \OCP\IUser|\PHPUnit\Framework\MockObject\MockObject */ private $user; + /** @var RegistrationContext|MockObject */ + private $registrationContext; + /** @var ProviderLoader */ private $loader; @@ -48,7 +55,12 @@ class ProviderLoaderTest extends TestCase { $this->appManager = $this->createMock(IAppManager::class); $this->user = $this->createMock(\OCP\IUser::class); - $this->loader = new ProviderLoader($this->appManager); + $this->registrationContext = $this->createMock(RegistrationContext::class); + $coordinator = $this->createMock(Coordinator::class); + $coordinator->method('getRegistrationContext') + ->willReturn($this->registrationContext); + + $this->loader = new ProviderLoader($this->appManager, $coordinator); } @@ -97,4 +109,29 @@ class ProviderLoaderTest extends TestCase { $this->assertArrayHasKey('test', $providers); $this->assertSame($provider, $providers['test']); } + + public function testGetProvidersBootstrap() { + $provider = $this->createMock(IProvider::class); + $provider->method('getId')->willReturn('test'); + + \OC::$server->registerService('\\OCA\\TwoFactorTest\\Provider', function () use ($provider) { + return $provider; + }); + + $this->appManager->expects($this->once()) + ->method('getEnabledAppsForUser') + ->with($this->user) + ->willReturn([]); + + $this->registrationContext->method('getTwoFactorProvider') + ->willReturn([ + new ServiceRegistration('twofactor_test', '\\OCA\\TwoFactorTest\\Provider') + ]); + + $providers = $this->loader->getProviders($this->user); + + $this->assertCount(1, $providers); + $this->assertArrayHasKey('test', $providers); + $this->assertSame($provider, $providers['test']); + } } diff --git a/tests/lib/Support/Subscription/RegistryTest.php b/tests/lib/Support/Subscription/RegistryTest.php index 95759e09547..5349b041d8b 100644 --- a/tests/lib/Support/Subscription/RegistryTest.php +++ b/tests/lib/Support/Subscription/RegistryTest.php @@ -23,6 +23,7 @@ namespace Test\Support\Subscription; use OC\Support\Subscription\Registry; +use OC\User\Database; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; @@ -31,6 +32,8 @@ use OCP\IUserManager; use OCP\Notification\IManager; use OCP\Support\Subscription\ISubscription; use OCP\Support\Subscription\ISupportedApps; +use OCP\User\Backend\ICountUsersBackend; +use OCP\UserInterface; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -212,8 +215,8 @@ class RegistryTest extends TestCase { ->method('getUsersForUserValue') ->with('core', 'enabled', 'false') ->willReturn(array_fill(0, $disabledUsers, '')); - /* @var UserInterface|\PHPUnit\Framework\MockObject\MockObject $dummyBackend */ - $dummyBackend = $this->createMock(UserInterface::class); + /* @var UserInterface|ICountUsersBackend|\PHPUnit\Framework\MockObject\MockObject $dummyBackend */ + $dummyBackend = $this->createMock(Database::class); $dummyBackend->expects($this->once()) ->method('implementsActions') ->willReturn(true); |