Page MenuHomePhorge

D5202.1775393933.diff
No OneTemporary

Authored By
Unknown
Size
66 KB
Referenced Files
None
Subscribers
None

D5202.1775393933.diff

diff --git a/src/app/Console/Commands/Imap/DeleteCommand.php b/src/app/Console/Commands/Imap/DeleteCommand.php
--- a/src/app/Console/Commands/Imap/DeleteCommand.php
+++ b/src/app/Console/Commands/Imap/DeleteCommand.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands\Imap;
-use App\Backends\IMAP;
use App\Console\Command;
+use App\Support\Facades\IMAP;
class DeleteCommand extends Command
{
diff --git a/src/app/Console/Commands/Imap/ListCommand.php b/src/app/Console/Commands/Imap/ListCommand.php
--- a/src/app/Console/Commands/Imap/ListCommand.php
+++ b/src/app/Console/Commands/Imap/ListCommand.php
@@ -28,7 +28,7 @@
public function handle()
{
$user = $this->argument('user');
- foreach (\App\Backends\IMAP::listMailboxes($user) as $mailbox) {
+ foreach (\App\Support\Facades\IMAP::listMailboxes($user) as $mailbox) {
$this->info("$mailbox");
}
}
diff --git a/src/app/Console/Commands/Imap/RenameCommand.php b/src/app/Console/Commands/Imap/RenameCommand.php
--- a/src/app/Console/Commands/Imap/RenameCommand.php
+++ b/src/app/Console/Commands/Imap/RenameCommand.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands\Imap;
-use App\Backends\IMAP;
use App\Console\Command;
+use App\Support\Facades\IMAP;
class RenameCommand extends Command
{
diff --git a/src/app/Console/Commands/ImapCleanupCommand.php b/src/app/Console/Commands/ImapCleanupCommand.php
--- a/src/app/Console/Commands/ImapCleanupCommand.php
+++ b/src/app/Console/Commands/ImapCleanupCommand.php
@@ -4,6 +4,7 @@
use App\Console\Command;
use App\Domain;
+use App\Support\Facades\IMAP;
class ImapCleanupCommand extends Command
{
@@ -34,7 +35,7 @@
if (!$domain) {
foreach (Domain::pluck('namespace')->all() as $domain) {
// TODO: Execute this in parallel/background?
- \App\Backends\IMAP::aclCleanupDomain($domain, $dry_run);
+ IMAP::aclCleanupDomain($domain, $dry_run);
}
return;
@@ -47,6 +48,6 @@
return 1;
}
- \App\Backends\IMAP::aclCleanupDomain($domain->namespace, $dry_run);
+ IMAP::aclCleanupDomain($domain->namespace, $dry_run);
}
}
diff --git a/src/app/Console/Commands/Status/Health.php b/src/app/Console/Commands/Status/Health.php
--- a/src/app/Console/Commands/Status/Health.php
+++ b/src/app/Console/Commands/Status/Health.php
@@ -6,12 +6,12 @@
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use App\Backends\DAV;
-use App\Backends\IMAP;
-use App\Backends\LDAP;
use App\Backends\OpenExchangeRates;
use App\Backends\Roundcube;
use App\Backends\Storage;
use App\Providers\Payment\Mollie;
+use App\Support\Facades\IMAP;
+use App\Support\Facades\LDAP;
//TODO stripe
//TODO firebase
@@ -180,7 +180,7 @@
$steps = $this->option('check');
if (empty($steps)) {
$steps = [
- 'DB', 'Redis', 'IMAP', 'Roundcube', 'Meet', 'DAV', 'Mollie', 'OpenExchangeRates'
+ 'DB', 'Redis', 'Roundcube', 'Meet', 'DAV', 'Mollie', 'OpenExchangeRates'
];
if (!empty($this->option('user'))) {
array_unshift($steps, 'Auth');
diff --git a/src/app/DataMigrator/Driver/IMAP.php b/src/app/DataMigrator/Driver/IMAP.php
--- a/src/app/DataMigrator/Driver/IMAP.php
+++ b/src/app/DataMigrator/Driver/IMAP.php
@@ -433,7 +433,7 @@
$this->imap = new \rcube_imap_generic();
if (\config('app.debug')) {
- $this->imap->setDebug(true, 'App\Backends\IMAP::logDebug');
+ $this->imap->setDebug(true, 'App\Support\Facades\IMAP::logDebug');
}
$this->imap->connect(
diff --git a/src/app/Jobs/Domain/CreateJob.php b/src/app/Jobs/Domain/CreateJob.php
--- a/src/app/Jobs/Domain/CreateJob.php
+++ b/src/app/Jobs/Domain/CreateJob.php
@@ -20,7 +20,7 @@
}
if (\config('app.with_ldap') && !$domain->isLdapReady()) {
- \App\Backends\LDAP::createDomain($domain);
+ \App\Support\Facades\LDAP::createDomain($domain);
$domain->status |= \App\Domain::STATUS_LDAP_READY;
$domain->save();
diff --git a/src/app/Jobs/Domain/DeleteJob.php b/src/app/Jobs/Domain/DeleteJob.php
--- a/src/app/Jobs/Domain/DeleteJob.php
+++ b/src/app/Jobs/Domain/DeleteJob.php
@@ -20,7 +20,7 @@
}
// sanity checks
- if (!$domain->trashed()) {
+ if ($domain->trashed()) {
$this->fail("Domain {$this->domainId} is not deleted.");
return;
}
@@ -31,7 +31,7 @@
}
if (\config('app.with_ldap') && $domain->isLdapReady()) {
- \App\Backends\LDAP::deleteDomain($domain);
+ \App\Support\Facades\LDAP::deleteDomain($domain);
$domain->status ^= \App\Domain::STATUS_LDAP_READY;
}
diff --git a/src/app/Jobs/Domain/UpdateJob.php b/src/app/Jobs/Domain/UpdateJob.php
--- a/src/app/Jobs/Domain/UpdateJob.php
+++ b/src/app/Jobs/Domain/UpdateJob.php
@@ -24,6 +24,6 @@
return;
}
- \App\Backends\LDAP::updateDomain($domain);
+ \App\Support\Facades\LDAP::updateDomain($domain);
}
}
diff --git a/src/app/Jobs/Group/CreateJob.php b/src/app/Jobs/Group/CreateJob.php
--- a/src/app/Jobs/Group/CreateJob.php
+++ b/src/app/Jobs/Group/CreateJob.php
@@ -20,7 +20,7 @@
}
if (\config('app.with_ldap') && !$group->isLdapReady()) {
- \App\Backends\LDAP::createGroup($group);
+ \App\Support\Facades\LDAP::createGroup($group);
$group->status |= \App\Group::STATUS_LDAP_READY;
}
diff --git a/src/app/Jobs/Group/DeleteJob.php b/src/app/Jobs/Group/DeleteJob.php
--- a/src/app/Jobs/Group/DeleteJob.php
+++ b/src/app/Jobs/Group/DeleteJob.php
@@ -31,13 +31,13 @@
}
if (\config('app.with_ldap') && $group->isLdapReady()) {
- \App\Backends\LDAP::deleteGroup($group);
+ \App\Support\Facades\LDAP::deleteGroup($group);
$group->status ^= \App\Group::STATUS_LDAP_READY;
}
/*
if (\config('app.with_imap') && $group->isImapReady()) {
- if (!\App\Backends\IMAP::deleteGroup($group)) {
+ if (!\App\Support\Facades\IMAP::deleteGroup($group)) {
throw new \Exception("Failed to delete group {$this->groupId} from IMAP.");
}
diff --git a/src/app/Jobs/Group/UpdateJob.php b/src/app/Jobs/Group/UpdateJob.php
--- a/src/app/Jobs/Group/UpdateJob.php
+++ b/src/app/Jobs/Group/UpdateJob.php
@@ -2,7 +2,7 @@
namespace App\Jobs\Group;
-use App\Backends\LDAP;
+use App\Support\Facades\LDAP;
use App\Jobs\GroupJob;
class UpdateJob extends GroupJob
diff --git a/src/app/Jobs/IMAP/AclCleanupJob.php b/src/app/Jobs/IMAP/AclCleanupJob.php
--- a/src/app/Jobs/IMAP/AclCleanupJob.php
+++ b/src/app/Jobs/IMAP/AclCleanupJob.php
@@ -57,6 +57,6 @@
*/
public function handle()
{
- \App\Backends\IMAP::aclCleanup($this->ident, $this->domain);
+ \App\Support\Facades\IMAP::aclCleanup($this->ident, $this->domain);
}
}
diff --git a/src/app/Jobs/Resource/CreateJob.php b/src/app/Jobs/Resource/CreateJob.php
--- a/src/app/Jobs/Resource/CreateJob.php
+++ b/src/app/Jobs/Resource/CreateJob.php
@@ -3,6 +3,8 @@
namespace App\Jobs\Resource;
use App\Jobs\ResourceJob;
+use App\Support\Facades\IMAP;
+use App\Support\Facades\LDAP;
class CreateJob extends ResourceJob
{
@@ -51,7 +53,7 @@
}
if ($withLdap && !$resource->isLdapReady()) {
- \App\Backends\LDAP::createResource($resource);
+ LDAP::createResource($resource);
$resource->status |= \App\Resource::STATUS_LDAP_READY;
$resource->save();
@@ -59,13 +61,13 @@
if (!$resource->isImapReady()) {
if (\config('app.with_imap')) {
- if (!\App\Backends\IMAP::createResource($resource)) {
+ if (!IMAP::createResource($resource)) {
throw new \Exception("Failed to create mailbox for resource {$this->resourceId}.");
}
} else {
$folder = $resource->getSetting('folder');
- if ($folder && !\App\Backends\IMAP::verifySharedFolder($folder)) {
+ if ($folder && !IMAP::verifySharedFolder($folder)) {
$this->release(15);
return;
}
diff --git a/src/app/Jobs/Resource/DeleteJob.php b/src/app/Jobs/Resource/DeleteJob.php
--- a/src/app/Jobs/Resource/DeleteJob.php
+++ b/src/app/Jobs/Resource/DeleteJob.php
@@ -31,7 +31,7 @@
}
if (\config('app.with_ldap') && $resource->isLdapReady()) {
- \App\Backends\LDAP::deleteResource($resource);
+ \App\Support\Facades\LDAP::deleteResource($resource);
$resource->status ^= \App\Resource::STATUS_LDAP_READY;
$resource->save();
@@ -39,7 +39,7 @@
if ($resource->isImapReady()) {
if (\config('app.with_imap')) {
- if (!\App\Backends\IMAP::deleteResource($resource)) {
+ if (!\App\Support\Facades\IMAP::deleteResource($resource)) {
throw new \Exception("Failed to delete mailbox for resource {$this->resourceId}.");
}
}
diff --git a/src/app/Jobs/Resource/UpdateJob.php b/src/app/Jobs/Resource/UpdateJob.php
--- a/src/app/Jobs/Resource/UpdateJob.php
+++ b/src/app/Jobs/Resource/UpdateJob.php
@@ -26,11 +26,11 @@
}
if (\config('app.with_ldap') && $resource->isLdapReady()) {
- \App\Backends\LDAP::updateResource($resource);
+ \App\Support\Facades\LDAP::updateResource($resource);
}
if (\config('app.with_imap') && $resource->isImapReady()) {
- if (!\App\Backends\IMAP::updateResource($resource, $this->properties)) {
+ if (!\App\Support\Facades\IMAP::updateResource($resource, $this->properties)) {
throw new \Exception("Failed to update mailbox for resource {$this->resourceId}.");
}
}
diff --git a/src/app/Jobs/Resource/VerifyJob.php b/src/app/Jobs/Resource/VerifyJob.php
--- a/src/app/Jobs/Resource/VerifyJob.php
+++ b/src/app/Jobs/Resource/VerifyJob.php
@@ -21,13 +21,12 @@
// the resource was already verified
if ($resource->isImapReady()) {
- $this->fail("Resource {$this->resourceId} is already verified.");
return;
}
$folder = $resource->getSetting('folder');
- if ($folder && \App\Backends\IMAP::verifySharedFolder($folder)) {
+ if ($folder && \App\Support\Facades\IMAP::verifySharedFolder($folder)) {
$resource->status |= \App\Resource::STATUS_IMAP_READY;
$resource->status |= \App\Resource::STATUS_ACTIVE;
$resource->save();
diff --git a/src/app/Jobs/SharedFolder/CreateJob.php b/src/app/Jobs/SharedFolder/CreateJob.php
--- a/src/app/Jobs/SharedFolder/CreateJob.php
+++ b/src/app/Jobs/SharedFolder/CreateJob.php
@@ -3,6 +3,8 @@
namespace App\Jobs\SharedFolder;
use App\Jobs\SharedFolderJob;
+use App\Support\Facades\IMAP;
+use App\Support\Facades\LDAP;
class CreateJob extends SharedFolderJob
{
@@ -51,7 +53,7 @@
}
if ($withLdap && !$folder->isLdapReady()) {
- \App\Backends\LDAP::createSharedFolder($folder);
+ LDAP::createSharedFolder($folder);
$folder->status |= \App\SharedFolder::STATUS_LDAP_READY;
$folder->save();
@@ -59,13 +61,13 @@
if (!$folder->isImapReady()) {
if (\config('app.with_imap')) {
- if (!\App\Backends\IMAP::createSharedFolder($folder)) {
+ if (!IMAP::createSharedFolder($folder)) {
throw new \Exception("Failed to create mailbox for shared folder {$this->folderId}.");
}
} else {
$folderName = $folder->getSetting('folder');
- if ($folderName && !\App\Backends\IMAP::verifySharedFolder($folderName)) {
+ if ($folderName && !IMAP::verifySharedFolder($folderName)) {
$this->release(15);
return;
}
diff --git a/src/app/Jobs/SharedFolder/DeleteJob.php b/src/app/Jobs/SharedFolder/DeleteJob.php
--- a/src/app/Jobs/SharedFolder/DeleteJob.php
+++ b/src/app/Jobs/SharedFolder/DeleteJob.php
@@ -31,7 +31,7 @@
}
if (\config('app.with_ldap') && $folder->isLdapReady()) {
- \App\Backends\LDAP::deleteSharedFolder($folder);
+ \App\Support\Facades\LDAP::deleteSharedFolder($folder);
$folder->status ^= \App\SharedFolder::STATUS_LDAP_READY;
// Already save in case of exception below
@@ -40,7 +40,7 @@
if ($folder->isImapReady()) {
if (\config('app.with_imap')) {
- if (!\App\Backends\IMAP::deleteSharedFolder($folder)) {
+ if (!\App\Support\Facades\IMAP::deleteSharedFolder($folder)) {
throw new \Exception("Failed to delete mailbox for shared folder {$this->folderId}.");
}
}
diff --git a/src/app/Jobs/SharedFolder/UpdateJob.php b/src/app/Jobs/SharedFolder/UpdateJob.php
--- a/src/app/Jobs/SharedFolder/UpdateJob.php
+++ b/src/app/Jobs/SharedFolder/UpdateJob.php
@@ -26,11 +26,11 @@
}
if (\config('app.with_ldap') && $folder->isLdapReady()) {
- \App\Backends\LDAP::updateSharedFolder($folder);
+ \App\Support\Facades\LDAP::updateSharedFolder($folder);
}
if (\config('app.with_imap') && $folder->isImapReady()) {
- if (!\App\Backends\IMAP::updateSharedFolder($folder, $this->properties)) {
+ if (!\App\Support\Facades\IMAP::updateSharedFolder($folder, $this->properties)) {
throw new \Exception("Failed to update mailbox for shared folder {$this->folderId}.");
}
}
diff --git a/src/app/Jobs/SharedFolder/VerifyJob.php b/src/app/Jobs/SharedFolder/VerifyJob.php
--- a/src/app/Jobs/SharedFolder/VerifyJob.php
+++ b/src/app/Jobs/SharedFolder/VerifyJob.php
@@ -21,13 +21,12 @@
// the user has a mailbox (or is marked as such)
if ($folder->isImapReady()) {
- $this->fail("Shared folder {$this->folderId} is already verified.");
return;
}
$folderName = $folder->getSetting('folder');
- if (\App\Backends\IMAP::verifySharedFolder($folderName)) {
+ if (\App\Support\Facades\IMAP::verifySharedFolder($folderName)) {
$folder->status |= \App\SharedFolder::STATUS_IMAP_READY;
$folder->status |= \App\SharedFolder::STATUS_ACTIVE;
$folder->save();
diff --git a/src/app/Jobs/User/CreateJob.php b/src/app/Jobs/User/CreateJob.php
--- a/src/app/Jobs/User/CreateJob.php
+++ b/src/app/Jobs/User/CreateJob.php
@@ -3,6 +3,8 @@
namespace App\Jobs\User;
use App\Jobs\UserJob;
+use App\Support\Facades\IMAP;
+use App\Support\Facades\LDAP;
/**
* Create the \App\User in LDAP.
@@ -89,7 +91,7 @@
}
if ($withLdap && !$user->isLdapReady()) {
- \App\Backends\LDAP::createUser($user);
+ LDAP::createUser($user);
$user->status |= \App\User::STATUS_LDAP_READY;
$user->save();
@@ -97,11 +99,11 @@
if (!$user->isImapReady()) {
if (\config('app.with_imap')) {
- if (!\App\Backends\IMAP::createUser($user)) {
+ if (!IMAP::createUser($user)) {
throw new \Exception("Failed to create mailbox for user {$this->userId}.");
}
} else {
- if (!\App\Backends\IMAP::verifyAccount($user->email)) {
+ if (!IMAP::verifyAccount($user->email)) {
$this->release(15);
return;
}
diff --git a/src/app/Jobs/User/DeleteJob.php b/src/app/Jobs/User/DeleteJob.php
--- a/src/app/Jobs/User/DeleteJob.php
+++ b/src/app/Jobs/User/DeleteJob.php
@@ -38,7 +38,7 @@
}
if (\config('app.with_ldap') && $user->isLdapReady()) {
- \App\Backends\LDAP::deleteUser($user);
+ \App\Support\Facades\LDAP::deleteUser($user);
$user->status ^= \App\User::STATUS_LDAP_READY;
$user->save();
@@ -46,7 +46,7 @@
if ($user->isImapReady()) {
if (\config('app.with_imap')) {
- if (!\App\Backends\IMAP::deleteUser($user)) {
+ if (!\App\Support\Facades\IMAP::deleteUser($user)) {
throw new \Exception("Failed to delete mailbox for user {$this->userId}.");
}
}
diff --git a/src/app/Jobs/User/ResyncJob.php b/src/app/Jobs/User/ResyncJob.php
--- a/src/app/Jobs/User/ResyncJob.php
+++ b/src/app/Jobs/User/ResyncJob.php
@@ -2,10 +2,10 @@
namespace App\Jobs\User;
-use App\Backends\IMAP;
-use App\Backends\LDAP;
use App\Domain;
use App\Jobs\UserJob;
+use App\Support\Facades\IMAP;
+use App\Support\Facades\LDAP;
use App\User;
class ResyncJob extends UserJob
diff --git a/src/app/Jobs/User/UpdateJob.php b/src/app/Jobs/User/UpdateJob.php
--- a/src/app/Jobs/User/UpdateJob.php
+++ b/src/app/Jobs/User/UpdateJob.php
@@ -39,11 +39,11 @@
}
if (\config('app.with_ldap') && $user->isLdapReady()) {
- \App\Backends\LDAP::updateUser($user);
+ \App\Support\Facades\LDAP::updateUser($user);
}
if (\config('app.with_imap') && $user->isImapReady()) {
- if (!\App\Backends\IMAP::updateUser($user)) {
+ if (!\App\Support\Facades\IMAP::updateUser($user)) {
throw new \Exception("Failed to update mailbox for user {$this->userId}.");
}
}
diff --git a/src/app/Jobs/User/VerifyJob.php b/src/app/Jobs/User/VerifyJob.php
--- a/src/app/Jobs/User/VerifyJob.php
+++ b/src/app/Jobs/User/VerifyJob.php
@@ -34,11 +34,10 @@
// the user has a mailbox (or is marked as such)
if ($user->isImapReady()) {
- $this->fail("User {$this->userId} is already verified.");
return;
}
- if (\App\Backends\IMAP::verifyAccount($user->email)) {
+ if (\App\Support\Facades\IMAP::verifyAccount($user->email)) {
$user->status |= \App\User::STATUS_IMAP_READY;
$user->status |= \App\User::STATUS_ACTIVE;
$user->save();
diff --git a/src/app/Providers/AppServiceProvider.php b/src/app/Providers/AppServiceProvider.php
--- a/src/app/Providers/AppServiceProvider.php
+++ b/src/app/Providers/AppServiceProvider.php
@@ -18,6 +18,13 @@
{
// This must be here, not in PassportServiceProvider
Passport::ignoreRoutes();
+
+ $this->app->bind('imap', function () {
+ return new \App\Backends\IMAP();
+ });
+ $this->app->bind('ldap', function () {
+ return new \App\Backends\LDAP();
+ });
}
/**
diff --git a/src/app/Support/Facades/IMAP.php b/src/app/Support/Facades/IMAP.php
new file mode 100644
--- /dev/null
+++ b/src/app/Support/Facades/IMAP.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Support\Facades;
+
+use Illuminate\Support\Facades\Facade;
+
+class IMAP extends Facade
+{
+ /**
+ * Get the registered name of the component.
+ */
+ protected static function getFacadeAccessor(): string
+ {
+ return 'imap';
+ }
+}
diff --git a/src/app/Support/Facades/LDAP.php b/src/app/Support/Facades/LDAP.php
new file mode 100644
--- /dev/null
+++ b/src/app/Support/Facades/LDAP.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Support\Facades;
+
+use Illuminate\Support\Facades\Facade;
+
+class LDAP extends Facade
+{
+ /**
+ * Get the registered name of the component.
+ */
+ protected static function getFacadeAccessor(): string
+ {
+ return 'ldap';
+ }
+}
diff --git a/src/tests/Feature/Backends/DAVTest.php b/src/tests/Feature/Backends/DAVTest.php
--- a/src/tests/Feature/Backends/DAVTest.php
+++ b/src/tests/Feature/Backends/DAVTest.php
@@ -29,7 +29,7 @@
public function tearDown(): void
{
if ($this->user) {
- $this->deleteTestUser($this->user->email);
+ $this->deleteTestUser($this->user->email, true);
}
parent::tearDown();
diff --git a/src/tests/Feature/Backends/IMAPTest.php b/src/tests/Feature/Backends/IMAPTest.php
--- a/src/tests/Feature/Backends/IMAPTest.php
+++ b/src/tests/Feature/Backends/IMAPTest.php
@@ -38,16 +38,16 @@
}
if ($this->user) {
- $this->deleteTestUser($this->user->email);
+ $this->deleteTestUser($this->user->email, true);
}
if ($this->group) {
- $this->deleteTestGroup($this->group->email);
+ $this->deleteTestGroup($this->group->email, true);
}
if ($this->resource) {
- $this->deleteTestResource($this->resource->email);
+ $this->deleteTestResource($this->resource->email, true);
}
if ($this->folder) {
- $this->deleteTestSharedFolder($this->folder->email);
+ $this->deleteTestSharedFolder($this->folder->email, true);
}
parent::tearDown();
diff --git a/src/tests/Feature/Backends/LDAPTest.php b/src/tests/Feature/Backends/LDAPTest.php
--- a/src/tests/Feature/Backends/LDAPTest.php
+++ b/src/tests/Feature/Backends/LDAPTest.php
@@ -31,11 +31,11 @@
'services.ldap.hosts' => \config('services.ldap.hosts'),
];
- $this->deleteTestUser('user-ldap-test@' . \config('app.domain'));
- $this->deleteTestDomain('testldap.com');
- $this->deleteTestGroup('group@kolab.org');
- $this->deleteTestResource('test-resource@kolab.org');
- $this->deleteTestSharedFolder('test-folder@kolab.org');
+ $this->deleteTestUser('user-ldap-test@' . \config('app.domain'), true);
+ $this->deleteTestDomain('testldap.com', true);
+ $this->deleteTestGroup('group@kolab.org', true);
+ $this->deleteTestResource('test-resource@kolab.org', true);
+ $this->deleteTestSharedFolder('test-folder@kolab.org', true);
// TODO: Remove group members
}
@@ -46,11 +46,11 @@
{
\config($this->ldap_config);
- $this->deleteTestUser('user-ldap-test@' . \config('app.domain'));
- $this->deleteTestDomain('testldap.com');
- $this->deleteTestGroup('group@kolab.org');
- $this->deleteTestResource('test-resource@kolab.org');
- $this->deleteTestSharedFolder('test-folder@kolab.org');
+ $this->deleteTestUser('user-ldap-test@' . \config('app.domain'), true);
+ $this->deleteTestDomain('testldap.com', true);
+ $this->deleteTestGroup('group@kolab.org', true);
+ $this->deleteTestResource('test-resource@kolab.org', true);
+ $this->deleteTestSharedFolder('test-folder@kolab.org', true);
// TODO: Remove group members
parent::tearDown();
diff --git a/src/tests/Feature/Console/Status/HealthTest.php b/src/tests/Feature/Console/Status/HealthTest.php
--- a/src/tests/Feature/Console/Status/HealthTest.php
+++ b/src/tests/Feature/Console/Status/HealthTest.php
@@ -3,19 +3,25 @@
namespace Tests\Feature\Console\Status;
use Tests\TestCase;
+use App\Support\Facades\IMAP;
+use App\Support\Facades\LDAP;
class HealthTest extends TestCase
{
/**
* Test the command
*
- * @group ldap
- * @group imap
* @group meet
* @group mollie
*/
public function testHandle(): void
{
+ \config(['app.with_ldap' => true]);
+ \config(['app.with_imap' => true]);
+
+ IMAP::shouldReceive('healthcheck')->once()->andReturn(true);
+ LDAP::shouldReceive('healthcheck')->once()->andReturn(true);
+
$code = \Artisan::call("status:health");
$output = trim(\Artisan::output());
diff --git a/src/tests/Feature/Controller/GroupsTest.php b/src/tests/Feature/Controller/GroupsTest.php
--- a/src/tests/Feature/Controller/GroupsTest.php
+++ b/src/tests/Feature/Controller/GroupsTest.php
@@ -296,8 +296,6 @@
/**
* Test fetching group status (GET /api/v4/groups/<group-id>/status)
* and forcing setup process update (?refresh=1)
- *
- * @group ldap
*/
public function testStatus(): void
{
@@ -387,8 +385,6 @@
/**
* Test GroupsController::statusInfo()
- *
- * @group ldap
*/
public function testStatusInfo(): void
{
diff --git a/src/tests/Feature/Controller/ResourcesTest.php b/src/tests/Feature/Controller/ResourcesTest.php
--- a/src/tests/Feature/Controller/ResourcesTest.php
+++ b/src/tests/Feature/Controller/ResourcesTest.php
@@ -294,8 +294,6 @@
/**
* Test fetching a resource status (GET /api/v4/resources/<resource>/status)
* and forcing setup process update (?refresh=1)
- *
- * @group ldap
*/
public function testStatus(): void
{
@@ -408,8 +406,6 @@
/**
* Test ResourcesController::statusInfo()
- *
- * @group ldap
*/
public function testStatusInfo(): void
{
diff --git a/src/tests/Feature/Controller/SharedFoldersTest.php b/src/tests/Feature/Controller/SharedFoldersTest.php
--- a/src/tests/Feature/Controller/SharedFoldersTest.php
+++ b/src/tests/Feature/Controller/SharedFoldersTest.php
@@ -301,8 +301,6 @@
/**
* Test fetching a shared folder status (GET /api/v4/shared-folders/<folder>/status)
* and forcing setup process update (?refresh=1)
- *
- * @group ldap
*/
public function testStatus(): void
{
diff --git a/src/tests/Feature/Controller/UsersTest.php b/src/tests/Feature/Controller/UsersTest.php
--- a/src/tests/Feature/Controller/UsersTest.php
+++ b/src/tests/Feature/Controller/UsersTest.php
@@ -471,9 +471,6 @@
/**
* Test fetching user status (GET /api/v4/users/<user-id>/status)
* and forcing setup process update (?refresh=1)
- *
- * @group imap
- * @group dns
*/
public function testStatus(): void
{
diff --git a/src/tests/Feature/Jobs/Domain/CreateTest.php b/src/tests/Feature/Jobs/Domain/CreateTest.php
--- a/src/tests/Feature/Jobs/Domain/CreateTest.php
+++ b/src/tests/Feature/Jobs/Domain/CreateTest.php
@@ -3,6 +3,7 @@
namespace Tests\Feature\Jobs\Domain;
use App\Domain;
+use App\Support\Facades\LDAP;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -27,8 +28,6 @@
/**
* Test job handle
- *
- * @group ldap
*/
public function testHandle(): void
{
@@ -40,21 +39,22 @@
]
);
+ \config(['app.with_ldap' => true]);
+
$this->assertFalse($domain->isLdapReady());
// Fake the queue, assert that no jobs were pushed...
Queue::fake();
Queue::assertNothingPushed();
+ LDAP::shouldReceive('createDomain')->once()->with($domain)->andReturn(true);
+
$job = new \App\Jobs\Domain\CreateJob($domain->id);
$job->handle();
- if (\config('app.with_ldap')) {
- $this->assertTrue($domain->fresh()->isLdapReady());
- }
+ $this->assertTrue($domain->fresh()->isLdapReady());
Queue::assertPushed(\App\Jobs\Domain\VerifyJob::class, 1);
-
Queue::assertPushed(
\App\Jobs\Domain\VerifyJob::class,
function ($job) use ($domain) {
diff --git a/src/tests/Feature/Jobs/Domain/DeleteTest.php b/src/tests/Feature/Jobs/Domain/DeleteTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Jobs/Domain/DeleteTest.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Tests\Feature\Jobs\Domain;
+
+use App\Domain;
+use App\Support\Facades\LDAP;
+use Tests\TestCase;
+
+class DeleteTest extends TestCase
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+
+ $this->deleteTestDomain('domain-create-test.com');
+ }
+
+ public function tearDown(): void
+ {
+ $this->deleteTestDomain('domain-create-test.com');
+
+ parent::tearDown();
+ }
+
+ /**
+ * Test job handle
+ */
+ public function testHandle(): void
+ {
+ $domain = $this->getTestDomain(
+ 'domain-create-test.com',
+ [
+ 'status' => Domain::STATUS_NEW | Domain::STATUS_LDAP_READY,
+ 'type' => Domain::TYPE_EXTERNAL,
+ ]
+ );
+
+ \config(['app.with_ldap' => true]);
+
+ $this->assertTrue($domain->isLdapReady());
+ $this->assertFalse($domain->isDeleted());
+
+ LDAP::shouldReceive('deleteDomain')->once()->with($domain)->andReturn(true);
+
+ $job = new \App\Jobs\Domain\DeleteJob($domain->id);
+ $job->handle();
+
+ $domain->refresh();
+ $this->assertFalse($domain->isLdapReady());
+ $this->assertTrue($domain->isDeleted());
+
+ // TODO: More cases
+ $this->markTestIncomplete();
+ }
+}
diff --git a/src/tests/Feature/Jobs/Domain/UpdateTest.php b/src/tests/Feature/Jobs/Domain/UpdateTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Jobs/Domain/UpdateTest.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Tests\Feature\Jobs\Domain;
+
+use App\Domain;
+use App\Support\Facades\LDAP;
+use Tests\TestCase;
+
+class UpdateTest extends TestCase
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+
+ $this->deleteTestDomain('domain-create-test.com');
+ }
+
+ public function tearDown(): void
+ {
+ $this->deleteTestDomain('domain-create-test.com');
+
+ parent::tearDown();
+ }
+
+ /**
+ * Test job handle
+ */
+ public function testHandle(): void
+ {
+ $domain = $this->getTestDomain(
+ 'domain-create-test.com',
+ [
+ 'status' => Domain::STATUS_NEW | Domain::STATUS_LDAP_READY,
+ 'type' => Domain::TYPE_EXTERNAL,
+ ]
+ );
+
+ \config(['app.with_ldap' => true]);
+
+ $this->assertTrue($domain->isLdapReady());
+
+ LDAP::shouldReceive('updateDomain')->once()->with($domain)->andReturn(true);
+
+ $job = new \App\Jobs\Domain\UpdateJob($domain->id);
+ $job->handle();
+
+ // TODO: More cases
+ $this->markTestIncomplete();
+ }
+}
diff --git a/src/tests/Feature/Jobs/Group/CreateTest.php b/src/tests/Feature/Jobs/Group/CreateTest.php
--- a/src/tests/Feature/Jobs/Group/CreateTest.php
+++ b/src/tests/Feature/Jobs/Group/CreateTest.php
@@ -3,6 +3,7 @@
namespace Tests\Feature\Jobs\Group;
use App\Group;
+use App\Support\Facades\LDAP;
use Tests\TestCase;
class CreateTest extends TestCase
@@ -26,8 +27,6 @@
/**
* Test job handle
- *
- * @group ldap
*/
public function testHandle(): void
{
@@ -35,16 +34,18 @@
$this->assertFalse($group->isLdapReady());
- $job = new \App\Jobs\Group\CreateJob($group->id);
+ \config(['app.with_ldap' => true]);
+
+ LDAP::shouldReceive('createGroup')->once()->with($group)->andReturn(true);
+
+ $job = (new \App\Jobs\Group\CreateJob($group->id))->withFakeQueueInteractions();
$job->handle();
+ $job->assertNotFailed();
$group->refresh();
- if (!\config('app.with_ldap')) {
- $this->assertTrue($group->isActive());
- } else {
- $this->assertTrue($group->isLdapReady());
- }
+ $this->assertTrue($group->isActive());
+ $this->assertTrue($group->isLdapReady());
// Test non-existing group ID
$job = (new \App\Jobs\Group\CreateJob(123))->withFakeQueueInteractions();
diff --git a/src/tests/Feature/Jobs/Group/DeleteTest.php b/src/tests/Feature/Jobs/Group/DeleteTest.php
--- a/src/tests/Feature/Jobs/Group/DeleteTest.php
+++ b/src/tests/Feature/Jobs/Group/DeleteTest.php
@@ -3,6 +3,7 @@
namespace Tests\Feature\Jobs\Group;
use App\Group;
+use App\Support\Facades\LDAP;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -27,27 +28,18 @@
/**
* Test job handle
- *
- * @group ldap
*/
public function testHandle(): void
{
$group = $this->getTestGroup('group@kolab.org', [
'members' => [],
- 'status' => Group::STATUS_NEW
+ 'status' => Group::STATUS_NEW | Group::STATUS_LDAP_READY
]);
- // create to domain first
- $job = new \App\Jobs\Group\CreateJob($group->id);
- $job->handle();
-
- $group->refresh();
+ \config(['app.with_ldap' => true]);
- if (\config('app.with_ldap')) {
- $this->assertTrue($group->isLdapReady());
- } else {
- $this->assertFalse($group->isLdapReady());
- }
+ $this->assertTrue($group->isLdapReady());
+ $this->assertFalse($group->isDeleted());
// Test group that is not deleted yet
$job = (new \App\Jobs\Group\DeleteJob($group->id))->withFakeQueueInteractions();
@@ -57,10 +49,13 @@
$group->deleted_at = \now();
$group->saveQuietly();
+ // Deleted group (expect success)
Queue::fake();
+ LDAP::shouldReceive('deleteGroup')->once()->with($group)->andReturn(true);
- $job = new \App\Jobs\Group\DeleteJob($group->id);
+ $job = (new \App\Jobs\Group\DeleteJob($group->id))->withFakeQueueInteractions();
$job->handle();
+ $job->assertNotFailed();
$group->refresh();
diff --git a/src/tests/Feature/Jobs/Group/UpdateTest.php b/src/tests/Feature/Jobs/Group/UpdateTest.php
--- a/src/tests/Feature/Jobs/Group/UpdateTest.php
+++ b/src/tests/Feature/Jobs/Group/UpdateTest.php
@@ -2,8 +2,8 @@
namespace Tests\Feature\Jobs\Group;
-use App\Backends\LDAP;
use App\Group;
+use App\Support\Facades\LDAP;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -28,8 +28,6 @@
/**
* Test job handle
- *
- * @group ldap
*/
public function testHandle(): void
{
@@ -43,47 +41,48 @@
// Create the group
$group = $this->getTestGroup('group@kolab.org', ['members' => []]);
- if (!\config('app.with_ldap')) {
- $job = (new \App\Jobs\Group\UpdateJob($group->id))->withFakeQueueInteractions();
- $job->handle();
- $job->assertDeleted();
- $this->markTestSkipped();
- }
+ \config(['app.with_ldap' => true]);
- // Create the group in LDAP
- LDAP::createGroup($group);
+ // Group not LDAP_READY
+ $job = (new \App\Jobs\Group\UpdateJob($group->id))->withFakeQueueInteractions();
+ $job->handle();
+ $job->assertDeleted();
- // Test if group properties (members) actually changed in LDAP
- $group->members = ['test1@gmail.com'];
+ // Group is LDAP_READY
$group->status |= Group::STATUS_LDAP_READY;
$group->save();
- $job = new \App\Jobs\Group\UpdateJob($group->id);
- $job->handle();
-
- $ldapGroup = LDAP::getGroup($group->email);
- $root_dn = \config('services.ldap.hosted.root_dn');
+ LDAP::shouldReceive('connect');
+ LDAP::shouldReceive('getGroup')->once()->with($group->email)->andReturn(['test' => 'test']);
+ LDAP::shouldReceive('updateGroup')->once()->with($group)->andReturn(true);
+ LDAP::shouldReceive('disconnect');
- $this->assertSame('uid=test1@gmail.com,ou=People,ou=kolab.org,' . $root_dn, $ldapGroup['uniquemember']);
+ $job = (new \App\Jobs\Group\UpdateJob($group->id))->withFakeQueueInteractions();
+ $job->handle();
+ $job->assertNotFailed();
// Test that suspended group is removed from LDAP
$group->suspend();
- $job = new \App\Jobs\Group\UpdateJob($group->id);
- $job->handle();
+ LDAP::shouldReceive('connect');
+ LDAP::shouldReceive('getGroup')->once()->with($group->email)->andReturn(['test' => 'test']);
+ LDAP::shouldReceive('deleteGroup')->once()->with($group)->andReturn(true);
+ LDAP::shouldReceive('disconnect');
- $this->assertNull(LDAP::getGroup($group->email));
+ $job = (new \App\Jobs\Group\UpdateJob($group->id))->withFakeQueueInteractions();
+ $job->handle();
+ $job->assertNotFailed();
// Test that unsuspended group is added back to LDAP
$group->unsuspend();
- $job = new \App\Jobs\Group\UpdateJob($group->id);
- $job->handle();
+ LDAP::shouldReceive('connect');
+ LDAP::shouldReceive('getGroup')->once()->with($group->email)->andReturn(null);
+ LDAP::shouldReceive('createGroup')->once()->with($group)->andReturn(true);
+ LDAP::shouldReceive('disconnect');
- /** @var array */
- $ldapGroup = LDAP::getGroup($group->email);
- $this->assertNotNull($ldapGroup);
- $this->assertSame($group->email, $ldapGroup['mail']);
- $this->assertSame('uid=test1@gmail.com,ou=People,ou=kolab.org,' . $root_dn, $ldapGroup['uniquemember']);
+ $job = (new \App\Jobs\Group\UpdateJob($group->id))->withFakeQueueInteractions();
+ $job->handle();
+ $job->assertNotFailed();
}
}
diff --git a/src/tests/Feature/Jobs/Resource/CreateTest.php b/src/tests/Feature/Jobs/Resource/CreateTest.php
--- a/src/tests/Feature/Jobs/Resource/CreateTest.php
+++ b/src/tests/Feature/Jobs/Resource/CreateTest.php
@@ -3,6 +3,8 @@
namespace Tests\Feature\Jobs\Resource;
use App\Resource;
+use App\Support\Facades\IMAP;
+use App\Support\Facades\LDAP;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -27,9 +29,6 @@
/**
* Test job handle
- *
- * @group ldap
- * @group imap
*/
public function testHandle(): void
{
@@ -49,17 +48,26 @@
$this->assertFalse($resource->isImapReady());
$this->assertFalse($resource->isActive());
+ // TODO: Make the test working with various with_imap/with_ldap combinations
+ \config(['app.with_imap' => true]);
+ \config(['app.with_ldap' => true]);
+
// Test resource creation
+ IMAP::shouldReceive('createResource')->once()->with($resource)->andReturn(true);
+ LDAP::shouldReceive('createResource')->once()->with($resource)->andReturn(true);
+
$job = (new \App\Jobs\Resource\CreateJob($resource->id))->withFakeQueueInteractions();
$job->handle();
$job->assertNotFailed();
$resource->refresh();
- $this->assertSame(\config('app.with_ldap'), $resource->isLdapReady());
+ $this->assertTrue($resource->isLdapReady());
$this->assertTrue($resource->isImapReady());
$this->assertTrue($resource->isActive());
+ // TODO: Test case when IMAP or LDAP method fails
+
// Test job failures
$resource->status |= Resource::STATUS_DELETED;
$resource->save();
diff --git a/src/tests/Feature/Jobs/Resource/DeleteTest.php b/src/tests/Feature/Jobs/Resource/DeleteTest.php
--- a/src/tests/Feature/Jobs/Resource/DeleteTest.php
+++ b/src/tests/Feature/Jobs/Resource/DeleteTest.php
@@ -3,6 +3,8 @@
namespace Tests\Feature\Jobs\Resource;
use App\Resource;
+use App\Support\Facades\IMAP;
+use App\Support\Facades\LDAP;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -27,9 +29,6 @@
/**
* Test job handle
- *
- * @group ldap
- * @group imap
*/
public function testHandle(): void
{
@@ -41,16 +40,10 @@
$job->assertFailedWith("Resource 123 could not be found in the database.");
$resource = $this->getTestResource('resource-test@' . \config('app.domain'), [
- 'status' => Resource::STATUS_NEW
+ 'status' => Resource::STATUS_NEW | Resource::STATUS_IMAP_READY | Resource::STATUS_LDAP_READY,
]);
- // create the resource first
- $job = new \App\Jobs\Resource\CreateJob($resource->id);
- $job->handle();
-
- $resource->refresh();
-
- $this->assertSame(\config('app.with_ldap'), $resource->isLdapReady());
+ $this->assertTrue($resource->isLdapReady());
$this->assertTrue($resource->isImapReady());
$this->assertFalse($resource->isDeleted());
@@ -63,7 +56,14 @@
$resource->saveQuietly();
Queue::fake();
+ // TODO: Make the test working with various with_imap/with_ldap combinations
+ \config(['app.with_imap' => true]);
+ \config(['app.with_ldap' => true]);
+
// Test successful deletion
+ IMAP::shouldReceive('deleteResource')->once()->with($resource)->andReturn(true);
+ LDAP::shouldReceive('deleteResource')->once()->with($resource)->andReturn(true);
+
$job = new \App\Jobs\Resource\DeleteJob($resource->id);
$job->handle();
diff --git a/src/tests/Feature/Jobs/Resource/UpdateTest.php b/src/tests/Feature/Jobs/Resource/UpdateTest.php
--- a/src/tests/Feature/Jobs/Resource/UpdateTest.php
+++ b/src/tests/Feature/Jobs/Resource/UpdateTest.php
@@ -2,8 +2,9 @@
namespace Tests\Feature\Jobs\Resource;
-use App\Backends\LDAP;
use App\Resource;
+use App\Support\Facades\IMAP;
+use App\Support\Facades\LDAP;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -31,9 +32,6 @@
/**
* Test job handle
- *
- * @group ldap
- * @group imap
*/
public function testHandle(): void
{
@@ -46,26 +44,21 @@
$resource = $this->getTestResource(
'resource-test@' . \config('app.domain'),
- ['status' => Resource::STATUS_NEW]
+ ['status' => Resource::STATUS_NEW | Resource::STATUS_LDAP_READY | Resource::STATUS_IMAP_READY]
);
- // Create the resource in LDAP
- $job = new \App\Jobs\Resource\CreateJob($resource->id);
- $job->handle();
-
// Run the update with some new config
$resource->setConfig(['invitation_policy' => 'accept']);
- $job = new \App\Jobs\Resource\UpdateJob($resource->id);
- $job->handle();
+ // TODO: Make the test working with various with_imap/with_ldap combinations
+ \config(['app.with_imap' => true]);
+ \config(['app.with_ldap' => true]);
- if (\config('app.with_ldap')) {
- $ldap_resource = LDAP::getResource($resource->email);
+ IMAP::shouldReceive('updateResource')->once()->with($resource, [])->andReturn(true);
+ LDAP::shouldReceive('updateResource')->once()->with($resource)->andReturn(true);
- $this->assertSame('ACT_ACCEPT', $ldap_resource['kolabinvitationpolicy']);
- }
-
- // TODO: Assert IMAP change worked
+ $job = new \App\Jobs\Resource\UpdateJob($resource->id);
+ $job->handle();
// Test that the job is being deleted if the resource is not ldap ready or is deleted
$resource->refresh();
diff --git a/src/tests/Feature/Jobs/Resource/VerifyTest.php b/src/tests/Feature/Jobs/Resource/VerifyTest.php
--- a/src/tests/Feature/Jobs/Resource/VerifyTest.php
+++ b/src/tests/Feature/Jobs/Resource/VerifyTest.php
@@ -3,6 +3,7 @@
namespace Tests\Feature\Jobs\Resource;
use App\Resource;
+use App\Support\Facades\IMAP;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -34,8 +35,6 @@
/**
* Test job handle
- *
- * @group imap
*/
public function testHandle(): void
{
@@ -46,7 +45,6 @@
$job->handle();
$job->assertFailedWith("Resource 123 could not be found in the database.");
- // Test existing resource
$resource = $this->getTestResource('resource-test1@kolab.org');
if ($resource->isImapReady()) {
@@ -56,18 +54,24 @@
$this->assertFalse($resource->isImapReady());
- for ($i = 0; $i < 10; $i++) {
- $job = new \App\Jobs\Resource\VerifyJob($resource->id);
- $job->handle();
+ // Test existing resource (successful verification)
+ IMAP::shouldReceive('verifySharedFolder')->once()->with($resource->getSetting('folder'))->andReturn(true);
- if ($resource->fresh()->isImapReady()) {
- $this->assertTrue(true);
- return;
- }
+ $job = new \App\Jobs\Resource\VerifyJob($resource->id);
+ $job->handle();
- sleep(1);
- }
+ $resource->refresh();
+ $this->assertTrue($resource->isImapReady());
+
+ // Test existing resource (unsuccessful verification)
+ $resource->status ^= Resource::STATUS_IMAP_READY;
+ $resource->save();
+
+ IMAP::shouldReceive('verifySharedFolder')->once()->with($resource->getSetting('folder'))->andReturn(false);
+
+ $job = new \App\Jobs\Resource\VerifyJob($resource->id);
+ $job->handle();
- $this->assertTrue(false, "Unable to verify the shared folder is set up in time");
+ $this->assertFalse($resource->fresh()->isImapReady());
}
}
diff --git a/src/tests/Feature/Jobs/SharedFolder/CreateTest.php b/src/tests/Feature/Jobs/SharedFolder/CreateTest.php
--- a/src/tests/Feature/Jobs/SharedFolder/CreateTest.php
+++ b/src/tests/Feature/Jobs/SharedFolder/CreateTest.php
@@ -3,6 +3,8 @@
namespace Tests\Feature\Jobs\SharedFolder;
use App\SharedFolder;
+use App\Support\Facades\LDAP;
+use App\Support\Facades\IMAP;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -27,9 +29,6 @@
/**
* Test job handle
- *
- * @group ldap
- * @group imap
*/
public function testHandle(): void
{
@@ -49,23 +48,21 @@
$this->assertFalse($folder->isImapReady());
$this->assertFalse($folder->isActive());
+ \config(['app.with_imap' => true]);
+ \config(['app.with_ldap' => true]);
+
// Test shared folder creation
+ IMAP::shouldReceive('createSharedFolder')->once()->with($folder)->andReturn(true);
+ LDAP::shouldReceive('createSharedFolder')->once()->with($folder)->andReturn(true);
+
$job = (new \App\Jobs\SharedFolder\CreateJob($folder->id))->withFakeQueueInteractions();
$job->handle();
$job->assertNotFailed();
$folder->refresh();
- if (\config('app.with_ldap')) {
- $this->assertTrue($folder->isLdapReady());
- } else {
- $this->assertFalse($folder->isLdapReady());
- }
- if (\config('app.with_imap')) {
- $this->assertTrue($folder->isImapReady());
- } else {
- $this->assertFalse($folder->isImapReady());
- }
+ $this->assertTrue($folder->isLdapReady());
+ $this->assertTrue($folder->isImapReady());
$this->assertTrue($folder->isActive());
// Test job failures
diff --git a/src/tests/Feature/Jobs/SharedFolder/DeleteTest.php b/src/tests/Feature/Jobs/SharedFolder/DeleteTest.php
--- a/src/tests/Feature/Jobs/SharedFolder/DeleteTest.php
+++ b/src/tests/Feature/Jobs/SharedFolder/DeleteTest.php
@@ -3,6 +3,8 @@
namespace Tests\Feature\Jobs\SharedFolder;
use App\SharedFolder;
+use App\Support\Facades\IMAP;
+use App\Support\Facades\LDAP;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -27,9 +29,6 @@
/**
* Test job handle
- *
- * @group ldap
- * @group imap
*/
public function testHandle(): void
{
@@ -41,22 +40,12 @@
$job->assertFailedWith("Shared folder 123 could not be found in the database.");
$folder = $this->getTestSharedFolder('folder-test@' . \config('app.domain'), [
- 'status' => SharedFolder::STATUS_NEW
+ 'status' => SharedFolder::STATUS_NEW | SharedFolder::STATUS_IMAP_READY | SharedFolder::STATUS_LDAP_READY
]);
- // Force with_imap=true, otherwise the folder creation job may fail
// TODO: Make the test working with various with_imap/with_ldap combinations
\config(['app.with_imap' => true]);
-
- // create the shared folder first
- $job = new \App\Jobs\SharedFolder\CreateJob($folder->id);
- $job->handle();
-
- $folder->refresh();
-
- $this->assertSame(\config('app.with_ldap'), $folder->isLdapReady());
- $this->assertTrue($folder->isImapReady());
- $this->assertFalse($folder->isDeleted());
+ \config(['app.with_ldap' => true]);
// Test deleting not deleted folder
$job = (new \App\Jobs\SharedFolder\DeleteJob($folder->id))->withFakeQueueInteractions();
@@ -68,6 +57,9 @@
Queue::fake();
// Test successful deletion
+ IMAP::shouldReceive('deleteSharedFolder')->once()->with($folder)->andReturn(true);
+ LDAP::shouldReceive('deleteSharedFolder')->once()->with($folder)->andReturn(true);
+
$job = new \App\Jobs\SharedFolder\DeleteJob($folder->id);
$job->handle();
diff --git a/src/tests/Feature/Jobs/SharedFolder/UpdateTest.php b/src/tests/Feature/Jobs/SharedFolder/UpdateTest.php
--- a/src/tests/Feature/Jobs/SharedFolder/UpdateTest.php
+++ b/src/tests/Feature/Jobs/SharedFolder/UpdateTest.php
@@ -2,8 +2,9 @@
namespace Tests\Feature\Jobs\SharedFolder;
-use App\Backends\LDAP;
use App\SharedFolder;
+use App\Support\Facades\IMAP;
+use App\Support\Facades\LDAP;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -31,9 +32,6 @@
/**
* Test job handle
- *
- * @group ldap
- * @group imap
*/
public function testHandle(): void
{
@@ -46,29 +44,21 @@
$folder = $this->getTestSharedFolder(
'folder-test@' . \config('app.domain'),
- ['status' => SharedFolder::STATUS_NEW]
+ ['status' => SharedFolder::STATUS_NEW | SharedFolder::STATUS_IMAP_READY | SharedFolder::STATUS_LDAP_READY]
);
- // Force with_imap=true, otherwise the folder creation job may fail
// TODO: Make the test working with various with_imap=false
\config(['app.with_imap' => true]);
-
- // Create the folder in LDAP/IMAP
- $job = new \App\Jobs\SharedFolder\CreateJob($folder->id);
- $job->handle();
-
- $folder->refresh();
-
- $this->assertSame(\config('app.with_ldap'), $folder->isLdapReady());
- $this->assertTrue($folder->isImapReady());
+ \config(['app.with_ldap' => true]);
// Run the update job
+ IMAP::shouldReceive('updateSharedFolder')->once()->with($folder, [])->andReturn(true);
+ LDAP::shouldReceive('updateSharedFolder')->once()->with($folder)->andReturn(true);
+
$job = (new \App\Jobs\SharedFolder\UpdateJob($folder->id))->withFakeQueueInteractions();
$job->handle();
$job->assertNotFailed();
- // TODO: Assert that it worked on both LDAP and IMAP side
-
// Test handling deleted folder
$folder->status |= SharedFolder::STATUS_DELETED;
$folder->save();
diff --git a/src/tests/Feature/Jobs/SharedFolder/VerifyTest.php b/src/tests/Feature/Jobs/SharedFolder/VerifyTest.php
--- a/src/tests/Feature/Jobs/SharedFolder/VerifyTest.php
+++ b/src/tests/Feature/Jobs/SharedFolder/VerifyTest.php
@@ -3,6 +3,7 @@
namespace Tests\Feature\Jobs\SharedFolder;
use App\SharedFolder;
+use App\Support\Facades\IMAP;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -34,8 +35,6 @@
/**
* Test job handle
- *
- * @group imap
*/
public function testHandle(): void
{
@@ -56,18 +55,25 @@
$this->assertFalse($folder->isImapReady());
- for ($i = 0; $i < 10; $i++) {
- $job = new \App\Jobs\SharedFolder\VerifyJob($folder->id);
- $job->handle();
+ // Test successful verification
+ IMAP::shouldReceive('verifySharedFolder')->once()->with($folder->getSetting('folder'))->andReturn(true);
- if ($folder->fresh()->isImapReady()) {
- $this->assertTrue(true);
- return;
- }
+ $job = new \App\Jobs\SharedFolder\VerifyJob($folder->id);
+ $job->handle();
- sleep(1);
- }
+ $folder->refresh();
+ $this->assertTrue($folder->isImapReady());
+
+ $folder->status ^= SharedFolder::STATUS_IMAP_READY;
+ $folder->save();
- $this->assertTrue(false, "Unable to verify the shared folder is set up in time");
+ // Test unsuccessful verification
+ IMAP::shouldReceive('verifySharedFolder')->once()->with($folder->getSetting('folder'))->andReturn(false);
+
+ $job = new \App\Jobs\SharedFolder\VerifyJob($folder->id);
+ $job->handle();
+
+ $folder->refresh();
+ $this->assertFalse($folder->isImapReady());
}
}
diff --git a/src/tests/Feature/Jobs/User/CreateTest.php b/src/tests/Feature/Jobs/User/CreateTest.php
--- a/src/tests/Feature/Jobs/User/CreateTest.php
+++ b/src/tests/Feature/Jobs/User/CreateTest.php
@@ -2,6 +2,8 @@
namespace Tests\Feature\Jobs\User;
+use App\Support\Facades\IMAP;
+use App\Support\Facades\LDAP;
use App\User;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -27,9 +29,6 @@
/**
* Test job handle
- *
- * @group ldap
- * @group imap
*/
public function testHandle(): void
{
@@ -41,26 +40,25 @@
$domain->save();
// TODO: Make the test working with various with_imap/with_ldap combinations
+ \config(['app.with_ldap' => true]);
+ \config(['app.with_imap' => true]);
+
$this->assertFalse($user->isLdapReady());
$this->assertFalse($user->isImapReady());
$this->assertFalse($user->isActive());
+ // Test successful creation
+ IMAP::shouldReceive('createUser')->once()->with($user)->andReturn(true);
+ LDAP::shouldReceive('createUser')->once()->with($user)->andReturn(true);
+
$job = (new \App\Jobs\User\CreateJob($user->id))->withFakeQueueInteractions();
$job->handle();
$job->assertNotFailed();
$user->refresh();
- if (\config('app.with_ldap')) {
- $this->assertTrue($user->isLdapReady());
- } else {
- $this->assertFalse($user->isLdapReady());
- }
- if (\config('app.with_imap')) {
- $this->assertTrue($user->isImapReady());
- } else {
- $this->assertFalse($user->isImapReady());
- }
+ $this->assertTrue($user->isLdapReady());
+ $this->assertTrue($user->isImapReady());
$this->assertTrue($user->isActive());
// Test job failure (user deleted)
diff --git a/src/tests/Feature/Jobs/User/DeleteTest.php b/src/tests/Feature/Jobs/User/DeleteTest.php
--- a/src/tests/Feature/Jobs/User/DeleteTest.php
+++ b/src/tests/Feature/Jobs/User/DeleteTest.php
@@ -3,6 +3,8 @@
namespace Tests\Feature\Jobs\User;
use App\Backends\Roundcube;
+use App\Support\Facades\IMAP;
+use App\Support\Facades\LDAP;
use App\User;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -32,8 +34,6 @@
/**
* Test job handle
*
- * @group ldap
- * @group imap
* @group roundcube
*/
public function testHandle(): void
@@ -42,19 +42,19 @@
$rcdb = Roundcube::dbh();
- $user = $this->getTestUser('new-job-user@' . \config('app.domain'));
+ $user = $this->getTestUser('new-job-user@' . \config('app.domain'), [
+ 'status' => User::STATUS_ACTIVE | User::STATUS_IMAP_READY | User::STATUS_LDAP_READY,
+ ]);
$rcuser = Roundcube::userId($user->email);
- $job = new \App\Jobs\User\CreateJob($user->id);
- $job->handle();
-
- $user->refresh();
-
- $this->assertSame(\config('app.with_ldap'), $user->isLdapReady());
- $this->assertSame(\config('app.with_imap'), $user->isImapReady());
+ $this->assertTrue($user->isLdapReady());
+ $this->assertTrue($user->isImapReady());
$this->assertFalse($user->isDeleted());
$this->assertNotNull($rcdb->table('users')->where('username', $user->email)->first());
+ \config(['app.with_ldap' => true]);
+ \config(['app.with_imap' => true]);
+
// Test job failure (user not yet deleted)
$job = (new \App\Jobs\User\DeleteJob($user->id))->withFakeQueueInteractions();
$job->handle();
@@ -78,9 +78,8 @@
Queue::fake();
- // Note: This user might have been already deleted in the same tests run,
- // in the same second. If that's the case IMAP DELETE will fail. So, let's wait a second.
- sleep(1);
+ IMAP::shouldReceive('deleteUser')->once()->with($user)->andReturn(true);
+ LDAP::shouldReceive('deleteUser')->once()->with($user)->andReturn(true);
$job = (new \App\Jobs\User\DeleteJob($user->id))->withFakeQueueInteractions();
$job->handle();
diff --git a/src/tests/Feature/Jobs/User/ResyncTest.php b/src/tests/Feature/Jobs/User/ResyncTest.php
--- a/src/tests/Feature/Jobs/User/ResyncTest.php
+++ b/src/tests/Feature/Jobs/User/ResyncTest.php
@@ -2,9 +2,9 @@
namespace Tests\Feature\Jobs\User;
-use App\Backends\IMAP;
-use App\Backends\LDAP;
use App\Domain;
+use App\Support\Facades\IMAP;
+use App\Support\Facades\LDAP;
use App\User;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -35,9 +35,6 @@
/**
* Test the job execution
- *
- * @group ldap
- * @group imap
*/
public function testHandle(): void
{
@@ -50,34 +47,37 @@
'status' => User::STATUS_LDAP_READY | User::STATUS_IMAP_READY | User::STATUS_ACTIVE,
]);
- if (\config('app.with_ldap')) {
- $this->assertTrue(empty(LDAP::getDomain($domain->namespace)));
- $this->assertTrue(empty(LDAP::getUser($user->email)));
- }
+ \config(['app.with_ldap' => true]);
+ \config(['app.with_imap' => true]);
+
+ $this->assertTrue($user->isLdapReady());
+ $this->assertTrue($user->isImapReady());
+ $this->assertTrue($domain->isLdapReady());
Queue::fake();
// Test a user (and custom domain) that both aren't in ldap (despite their status)
+ LDAP::shouldReceive('getDomain')->once()->with($domain->namespace)->andReturn(false);
+ LDAP::shouldReceive('getUser')->once()->with($user->email)->andReturn(false);
+ IMAP::shouldReceive('verifyAccount')->once()->with($user->email)->andReturn(false);
+
$job = new \App\Jobs\User\ResyncJob($user->id);
$job->handle();
$user->refresh();
$domain->refresh();
- if (\config('app.with_ldap')) {
- $this->assertFalse($user->isLdapReady());
- $this->assertFalse($domain->isLdapReady());
-
- Queue::assertPushed(\App\Jobs\Domain\CreateJob::class, 1);
- Queue::assertPushed(
- \App\Jobs\Domain\CreateJob::class,
- function ($job) use ($domain) {
- return $domain->id == TestCase::getObjectProperty($job, 'domainId');
- }
- );
- }
-
+ $this->assertFalse($user->isLdapReady());
$this->assertFalse($user->isImapReady());
+ $this->assertFalse($domain->isLdapReady());
+
+ Queue::assertPushed(\App\Jobs\Domain\CreateJob::class, 1);
+ Queue::assertPushed(
+ \App\Jobs\Domain\CreateJob::class,
+ function ($job) use ($domain) {
+ return $domain->id == TestCase::getObjectProperty($job, 'domainId');
+ }
+ );
Queue::assertPushed(\App\Jobs\User\CreateJob::class, 1);
Queue::assertPushed(
diff --git a/src/tests/Feature/Jobs/User/UpdateTest.php b/src/tests/Feature/Jobs/User/UpdateTest.php
--- a/src/tests/Feature/Jobs/User/UpdateTest.php
+++ b/src/tests/Feature/Jobs/User/UpdateTest.php
@@ -2,8 +2,10 @@
namespace Tests\Feature\Jobs\User;
-use App\Backends\LDAP;
use App\Jobs\User\UpdateJob;
+use App\User;
+use App\Support\Facades\IMAP;
+use App\Support\Facades\LDAP;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -31,65 +33,26 @@
/**
* Test job handle
- *
- * @group ldap
- * @group imap
*/
public function testHandle(): void
{
// Ignore any jobs created here (e.g. on setAliases() use)
Queue::fake();
- $user = $this->getTestUser('new-job-user@' . \config('app.domain'));
+ $user = $this->getTestUser('new-job-user@' . \config('app.domain'), [
+ 'status' => User::STATUS_ACTIVE | User::STATUS_IMAP_READY | User::STATUS_LDAP_READY,
+ ]);
- \App\Jobs\User\CreateJob::dispatchSync($user->id);
+ \config(['app.with_ldap' => true]);
+ \config(['app.with_imap' => true]);
- // Test setting two aliases
- $aliases = [
- 'new-job-user1@' . \config('app.domain'),
- 'new-job-user2@' . \config('app.domain'),
- ];
-
- $user->setAliases($aliases);
-
- $job = new UpdateJob($user->id);
- $job->handle();
-
- if (\config('app.with_ldap')) {
- $ldap_user = LDAP::getUser('new-job-user@' . \config('app.domain'));
-
- $this->assertSame($aliases, $ldap_user['alias']);
- }
-
- // Test updating aliases list
- $aliases = [
- 'new-job-user1@' . \config('app.domain'),
- ];
-
- $user->setAliases($aliases);
+ IMAP::shouldReceive('updateUser')->once()->with($user)->andReturn(true);
+ LDAP::shouldReceive('updateUser')->once()->with($user)->andReturn(true);
+ // Test normal update
$job = new UpdateJob($user->id);
$job->handle();
- if (\config('app.with_ldap')) {
- $ldap_user = LDAP::getUser('new-job-user@' . \config('app.domain'));
-
- $this->assertSame($aliases, (array) $ldap_user['alias']);
- }
-
- // Test unsetting aliases list
- $aliases = [];
- $user->setAliases($aliases);
-
- $job = new UpdateJob($user->id);
- $job->handle();
-
- if (\config('app.with_ldap')) {
- $ldap_user = LDAP::getUser('new-job-user@' . \config('app.domain'));
-
- $this->assertTrue(empty($ldap_user['alias']));
- }
-
// Test deleted user
$user->delete();
$job = (new UpdateJob($user->id))->withFakeQueueInteractions();
diff --git a/src/tests/Feature/Jobs/User/VerifyTest.php b/src/tests/Feature/Jobs/User/VerifyTest.php
--- a/src/tests/Feature/Jobs/User/VerifyTest.php
+++ b/src/tests/Feature/Jobs/User/VerifyTest.php
@@ -2,6 +2,7 @@
namespace Tests\Feature\Jobs\User;
+use App\Support\Facades\IMAP;
use App\User;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -34,8 +35,6 @@
/**
* Test job handle
- *
- * @group imap
*/
public function testHandle(): void
{
@@ -46,7 +45,7 @@
$job->handle();
$job->assertFailedWith("User 123 could not be found in the database.");
- // Test existing user
+ // Test existing user (verification successful)
$user = $this->getTestUser('ned@kolab.org');
if ($user->isImapReady()) {
@@ -56,18 +55,23 @@
$this->assertFalse($user->isImapReady());
- for ($i = 0; $i < 10; $i++) {
- $job = new \App\Jobs\User\VerifyJob($user->id);
- $job->handle();
+ IMAP::shouldReceive('verifyAccount')->once()->with($user->email)->andReturn(true);
- if ($user->fresh()->isImapReady()) {
- $this->assertTrue(true);
- return;
- }
+ $job = new \App\Jobs\User\VerifyJob($user->id);
+ $job->handle();
- sleep(1);
- }
+ $user->refresh();
+ $this->assertTrue($user->isImapReady());
+
+ // Test existing user (verification not-successful)
+ $user->status ^= User::STATUS_IMAP_READY;
+ $user->save();
+
+ IMAP::shouldReceive('verifyAccount')->once()->with($user->email)->andReturn(false);
+
+ $job = new \App\Jobs\User\VerifyJob($user->id);
+ $job->handle();
- $this->assertTrue(false, "Unable to verify the IMAP account is set up in time");
+ $this->assertFalse($user->fresh()->isImapReady());
}
}
diff --git a/src/tests/ModelMatcher.php b/src/tests/ModelMatcher.php
new file mode 100644
--- /dev/null
+++ b/src/tests/ModelMatcher.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace Tests;
+
+use Mockery\Matcher\MatcherAbstract;
+
+class ModelMatcher extends MatcherAbstract
+{
+ public function match(&$actual)
+ {
+ return $this->_expected->is($actual);
+ }
+
+ public function __toString()
+ {
+ return '<Model>';
+ }
+}
diff --git a/src/tests/TestCase.php b/src/tests/TestCase.php
--- a/src/tests/TestCase.php
+++ b/src/tests/TestCase.php
@@ -22,6 +22,11 @@
// Disable throttling
$this->withoutMiddleware(ThrottleRequests::class);
+
+ \Mockery::getConfiguration()->setDefaultMatcher(
+ class: \Illuminate\Database\Eloquent\Model::class,
+ matcherClass: \Tests\ModelMatcher::class,
+ );
}
/**
diff --git a/src/tests/TestCaseTrait.php b/src/tests/TestCaseTrait.php
--- a/src/tests/TestCaseTrait.php
+++ b/src/tests/TestCaseTrait.php
@@ -299,7 +299,7 @@
*
* @coversNothing
*/
- protected function deleteTestDomain($name)
+ protected function deleteTestDomain($name, $backends = false)
{
Queue::fake();
@@ -309,8 +309,9 @@
return;
}
- $job = new \App\Jobs\Domain\DeleteJob($domain->id);
- $job->handle();
+ if ($backends && \config('app.with_ldap')) {
+ LDAP::deleteDomain($domain);
+ }
$domain->forceDelete();
}
@@ -320,7 +321,7 @@
*
* @coversNothing
*/
- protected function deleteTestGroup($email)
+ protected function deleteTestGroup($email, $backends = false)
{
Queue::fake();
@@ -330,7 +331,7 @@
return;
}
- if (\config('app.with_ldap')) {
+ if ($backends && \config('app.with_ldap')) {
LDAP::deleteGroup($group);
}
@@ -342,7 +343,7 @@
*
* @coversNothing
*/
- protected function deleteTestResource($email)
+ protected function deleteTestResource($email, $backends = false)
{
Queue::fake();
@@ -352,7 +353,7 @@
return;
}
- if (\config('app.with_ldap')) {
+ if ($backends && \config('app.with_ldap')) {
LDAP::deleteResource($resource);
}
@@ -382,7 +383,7 @@
*
* @coversNothing
*/
- protected function deleteTestSharedFolder($email)
+ protected function deleteTestSharedFolder($email, $backends = false)
{
Queue::fake();
@@ -392,7 +393,7 @@
return;
}
- if (\config('app.with_ldap')) {
+ if ($backends && \config('app.with_ldap')) {
LDAP::deleteSharedFolder($folder);
}
@@ -404,7 +405,7 @@
*
* @coversNothing
*/
- protected function deleteTestUser($email)
+ protected function deleteTestUser($email, $backends = false)
{
Queue::fake();
@@ -414,10 +415,10 @@
return;
}
- if (\config('app.with_imap')) {
+ if ($backends && \config('app.with_imap')) {
IMAP::deleteUser($user);
}
- if (\config('app.with_ldap')) {
+ if ($backends && \config('app.with_ldap')) {
LDAP::deleteUser($user);
}

File Metadata

Mime Type
text/plain
Expires
Sun, Apr 5, 12:58 PM (16 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18831459
Default Alt Text
D5202.1775393933.diff (66 KB)

Event Timeline