Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117799277
D5208.1775266200.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
26 KB
Referenced Files
None
Subscribers
None
D5208.1775266200.diff
View Options
diff --git a/src/app/Auth/SecondFactor.php b/src/app/Auth/SecondFactor.php
--- a/src/app/Auth/SecondFactor.php
+++ b/src/app/Auth/SecondFactor.php
@@ -2,6 +2,7 @@
namespace App\Auth;
+use App\Support\Facades\Roundcube;
use Illuminate\Support\Facades\Auth;
use Kolab2FA\Driver\Base as DriverBase;
use Kolab2FA\Storage\Base as StorageBase;
@@ -170,7 +171,7 @@
]
];
- self::dbh()->table('users')->updateOrInsert(
+ Roundcube::dbh()->table('users')->updateOrInsert(
['username' => $email, 'mail_host' => '127.0.0.1'],
['preferences' => serialize($config)]
);
@@ -282,7 +283,7 @@
*/
protected function getPrefs()
{
- $user = $this->dbh()->table('users')
+ $user = Roundcube::dbh()->table('users')
->select('preferences')
->where('username', strtolower($this->user->email))
->first();
@@ -305,18 +306,10 @@
$prefs = array_merge($old_prefs, $prefs);
$prefs = array_filter($prefs, fn($v) => !is_null($v));
- $this->dbh()->table('users')
+ Roundcube::dbh()->table('users')
->where('username', strtolower($this->user->email))
->update(['preferences' => serialize($prefs)]);
return true;
}
-
- /**
- * Init connection to the Roundcube database
- */
- public static function dbh()
- {
- return \App\Backends\Roundcube::dbh();
- }
}
diff --git a/src/app/Backends/PGP.php b/src/app/Backends/PGP.php
--- a/src/app/Backends/PGP.php
+++ b/src/app/Backends/PGP.php
@@ -83,7 +83,7 @@
}
/**
- * Deleta a keypair from DNS and Enigma keyring.
+ * Delete a keypair from DNS and Enigma keyring.
*
* @param \App\User $user User object
* @param string $email Email address of the key
@@ -98,6 +98,7 @@
// Remove the whole Enigma keyring (if it's a delete user account)
if ($user->email === $email) {
self::homedirCleanup($user);
+ $user->aliases()->pluck('alias')->each(fn ($alias) => self::keyUnregister($alias));
} else {
// TODO: remove only the alias key from Enigma keyring
}
diff --git a/src/app/Backends/Roundcube.php b/src/app/Backends/Roundcube.php
--- a/src/app/Backends/Roundcube.php
+++ b/src/app/Backends/Roundcube.php
@@ -208,6 +208,18 @@
$db->table(self::USERS_TABLE)->where('username', \strtolower($email))->delete();
}
+ /**
+ * Check if we can connect to the Roundcube
+ *
+ * @return bool True on success
+ */
+ public static function healthcheck(): bool
+ {
+ // TODO: Make some query? Access the webmail URL?
+ self::dbh();
+ return true;
+ }
+
/**
* Find the Roundcube user identifier for the specified user.
*
diff --git a/src/app/Console/Commands/Fs/ExpungeCommand.php b/src/app/Console/Commands/Fs/ExpungeCommand.php
--- a/src/app/Console/Commands/Fs/ExpungeCommand.php
+++ b/src/app/Console/Commands/Fs/ExpungeCommand.php
@@ -2,10 +2,10 @@
namespace App\Console\Commands\Fs;
-use App\Backends\Storage;
use App\Console\Command;
use App\Fs\Chunk;
use App\Fs\Item;
+use App\Support\Facades\Storage;
class ExpungeCommand extends Command
{
@@ -47,7 +47,7 @@
// We remove orphaned chunks after upload ttl (while marked as deleted some chunks may still be
// in the process of uploading a file).
$chunks = Chunk::withTrashed()
- ->where('deleted_at', '<', now()->subSeconds(Storage::UPLOAD_TTL))
+ ->where('deleted_at', '<', now()->subSeconds(\App\Backends\Storage::UPLOAD_TTL))
->orderBy('deleted_at')
->cursor();
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\OpenExchangeRates;
-use App\Backends\Roundcube;
-use App\Backends\Storage;
use App\Providers\Payment\Mollie;
use App\Support\Facades\IMAP;
use App\Support\Facades\LDAP;
+use App\Support\Facades\OpenExchangeRates;
+use App\Support\Facades\Roundcube;
+use App\Support\Facades\Storage;
//TODO stripe
//TODO firebase
@@ -115,8 +115,7 @@
private function checkRoundcube()
{
try {
- //TODO maybe run a select?
- Roundcube::dbh();
+ Roundcube::healthcheck();
return true;
} catch (\Exception $exception) {
$this->line($exception);
diff --git a/src/app/DataMigrator/Driver/Kolab/Files.php b/src/app/DataMigrator/Driver/Kolab/Files.php
--- a/src/app/DataMigrator/Driver/Kolab/Files.php
+++ b/src/app/DataMigrator/Driver/Kolab/Files.php
@@ -2,12 +2,12 @@
namespace App\DataMigrator\Driver\Kolab;
-use App\Backends\Storage;
use App\DataMigrator\Account;
use App\DataMigrator\Engine;
use App\DataMigrator\Interface\Folder;
use App\DataMigrator\Interface\Item;
use App\Fs\Item as FsItem;
+use App\Support\Facades\Storage;
use Illuminate\Support\Facades\DB;
/**
diff --git a/src/app/Http/Controllers/API/V4/FsController.php b/src/app/Http/Controllers/API/V4/FsController.php
--- a/src/app/Http/Controllers/API/V4/FsController.php
+++ b/src/app/Http/Controllers/API/V4/FsController.php
@@ -2,11 +2,11 @@
namespace App\Http\Controllers\API\V4;
-use App\Backends\Storage;
use App\Fs\Item;
use App\Fs\Property;
use App\Http\Controllers\RelationController;
use App\Rules\FileName;
+use App\Support\Facades\Storage;
use App\User;
use App\Utils;
use Illuminate\Http\Request;
diff --git a/src/app/Jobs/PGP/KeyCreateJob.php b/src/app/Jobs/PGP/KeyCreateJob.php
--- a/src/app/Jobs/PGP/KeyCreateJob.php
+++ b/src/app/Jobs/PGP/KeyCreateJob.php
@@ -64,6 +64,6 @@
return;
}
- \App\Backends\PGP::keypairCreate($user, $this->userEmail);
+ \App\Support\Facades\PGP::keypairCreate($user, $this->userEmail);
}
}
diff --git a/src/app/Jobs/PGP/KeyDeleteJob.php b/src/app/Jobs/PGP/KeyDeleteJob.php
--- a/src/app/Jobs/PGP/KeyDeleteJob.php
+++ b/src/app/Jobs/PGP/KeyDeleteJob.php
@@ -38,6 +38,6 @@
return;
}
- \App\Backends\PGP::keyDelete($user, $this->userEmail);
+ \App\Support\Facades\PGP::keyDelete($user, $this->userEmail);
}
}
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
@@ -55,7 +55,7 @@
}
if (\config('database.connections.roundcube')) {
- \App\Backends\Roundcube::deleteUser($user->email);
+ \App\Support\Facades\Roundcube::deleteUser($user->email);
}
$user->status |= \App\User::STATUS_DELETED;
diff --git a/src/app/Policy/Mailfilter/Modules/ItipModule.php b/src/app/Policy/Mailfilter/Modules/ItipModule.php
--- a/src/app/Policy/Mailfilter/Modules/ItipModule.php
+++ b/src/app/Policy/Mailfilter/Modules/ItipModule.php
@@ -72,7 +72,7 @@
/**
* Get the main event/task from the VCALENDAR object
*/
- protected static function extractMainComponent(COmponent $vobject): ?Component
+ protected static function extractMainComponent(Component $vobject): ?Component
{
foreach ($vobject->getComponents() as $component) {
if ($component->name == 'VEVENT' || $component->name == 'VTODO') {
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
@@ -25,6 +25,18 @@
$this->app->bind('ldap', function () {
return new \App\Backends\LDAP();
});
+ $this->app->bind('roundcube', function () {
+ return new \App\Backends\Roundcube();
+ });
+ $this->app->bind('pgp', function () {
+ return new \App\Backends\PGP();
+ });
+ $this->app->bind('filestorage', function () {
+ return new \App\Backends\Storage();
+ });
+ $this->app->bind('openexchangerates', function () {
+ return new \App\Backends\OpenExchangeRates();
+ });
}
/**
diff --git a/src/app/Support/Facades/OpenExchangeRates.php b/src/app/Support/Facades/OpenExchangeRates.php
new file mode 100644
--- /dev/null
+++ b/src/app/Support/Facades/OpenExchangeRates.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Support\Facades;
+
+use Illuminate\Support\Facades\Facade;
+
+class OpenExchangeRates extends Facade
+{
+ /**
+ * Get the registered name of the component.
+ */
+ protected static function getFacadeAccessor(): string
+ {
+ return 'openexchangerates';
+ }
+}
diff --git a/src/app/Support/Facades/PGP.php b/src/app/Support/Facades/PGP.php
new file mode 100644
--- /dev/null
+++ b/src/app/Support/Facades/PGP.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Support\Facades;
+
+use Illuminate\Support\Facades\Facade;
+
+class PGP extends Facade
+{
+ /**
+ * Get the registered name of the component.
+ */
+ protected static function getFacadeAccessor(): string
+ {
+ return 'pgp';
+ }
+}
diff --git a/src/app/Support/Facades/Roundcube.php b/src/app/Support/Facades/Roundcube.php
new file mode 100644
--- /dev/null
+++ b/src/app/Support/Facades/Roundcube.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Support\Facades;
+
+use Illuminate\Support\Facades\Facade;
+
+class Roundcube extends Facade
+{
+ /**
+ * Get the registered name of the component.
+ */
+ protected static function getFacadeAccessor(): string
+ {
+ return 'roundcube';
+ }
+}
diff --git a/src/app/Support/Facades/Storage.php b/src/app/Support/Facades/Storage.php
new file mode 100644
--- /dev/null
+++ b/src/app/Support/Facades/Storage.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Support\Facades;
+
+use Illuminate\Support\Facades\Facade;
+
+class Storage extends Facade
+{
+ /**
+ * Get the registered name of the component.
+ */
+ protected static function getFacadeAccessor(): string
+ {
+ return 'filestorage';
+ }
+}
diff --git a/src/tests/Feature/Jobs/PGP/KeyCreateTest.php b/src/tests/Feature/Backends/PGPTest.php
copy from src/tests/Feature/Jobs/PGP/KeyCreateTest.php
copy to src/tests/Feature/Backends/PGPTest.php
--- a/src/tests/Feature/Jobs/PGP/KeyCreateTest.php
+++ b/src/tests/Feature/Backends/PGPTest.php
@@ -1,15 +1,14 @@
<?php
-namespace Tests\Feature\Jobs\PGP;
+namespace Tests\Feature\Backends;
use App\Backends\PGP;
use App\Backends\Roundcube;
-use App\User;
use App\UserAlias;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
-class KeyCreateTest extends TestCase
+class PGPTest extends TestCase
{
/**
* {@inheritDoc}
@@ -19,7 +18,7 @@
parent::setUp();
$user = $this->getTestUser('john@kolab.org');
- UserAlias::where('alias', 'test-alias@kolab.org')->delete();
+ $user->aliases()->where('alias', 'test-alias@kolab.org')->delete();
PGP::homedirCleanup($user);
\App\PowerDNS\Domain::where('name', '_woat.kolab.org')->delete();
}
@@ -30,7 +29,7 @@
public function tearDown(): void
{
$user = $this->getTestUser('john@kolab.org');
- UserAlias::where('alias', 'test-alias@kolab.org')->delete();
+ $user->aliases()->where('alias', 'test-alias@kolab.org')->delete();
PGP::homedirCleanup($user);
\App\PowerDNS\Domain::where('name', '_woat.kolab.org')->delete();
@@ -38,16 +37,21 @@
}
/**
- * Test job handle
+ * Test key pair, listing and deletion creation.
*
* @group pgp
+ * @group roundcube
*/
- public function testHandle(): void
+ public function testKeyCreateListDelete(): void
{
+ Queue::fake();
+
$user = $this->getTestUser('john@kolab.org');
- $job = new \App\Jobs\PGP\KeyCreateJob($user->id, $user->email);
- $job->handle();
+ $this->assertCount(0, PGP::listKeys($user));
+
+ // Create a key pair
+ PGP::keypairCreate($user, $user->email);
// Assert the Enigma storage has been initialized and contains the key
$files = Roundcube::enigmaList($user->email);
@@ -56,7 +60,6 @@
// Assert the created keypair parameters
$keys = PGP::listKeys($user);
-
$this->assertCount(1, $keys);
$userIds = $keys[0]->getUserIds();
@@ -101,14 +104,11 @@
);
// Test an alias
- Queue::fake();
- UserAlias::create(['user_id' => $user->id, 'alias' => 'test-alias@kolab.org']);
- $job = new \App\Jobs\PGP\KeyCreateJob($user->id, 'test-alias@kolab.org');
- $job->handle();
+ $alias = $user->aliases()->create(['alias' => 'test-alias@kolab.org']);
+ PGP::keypairCreate($user, $alias->alias);
// Assert the created keypair parameters
$keys = PGP::listKeys($user);
-
$this->assertCount(2, $keys);
$userIds = $keys[1]->getUserIds();
@@ -137,5 +137,11 @@
$this->assertSame(false, $key->isRevoked());
$this->assertSame(2, $dns_domain->records()->where('type', 'TXT')->count());
+
+ // Delete the key
+ PGP::keyDelete($user, $user->email);
+
+ $this->assertSame(0, $dns_domain->records()->where('type', 'TXT')->count());
+ $this->assertCount(0, PGP::listKeys($user));
}
}
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
@@ -5,6 +5,8 @@
use Tests\TestCase;
use App\Support\Facades\IMAP;
use App\Support\Facades\LDAP;
+use App\Support\Facades\Roundcube;
+use App\Support\Facades\Storage;
class HealthTest extends TestCase
{
@@ -21,6 +23,8 @@
IMAP::shouldReceive('healthcheck')->once()->andReturn(true);
LDAP::shouldReceive('healthcheck')->once()->andReturn(true);
+ Roundcube::shouldReceive('healthcheck')->once()->andReturn(true);
+ Storage::shouldReceive('healthcheck')->once()->andReturn(true);
$code = \Artisan::call("status:health");
$output = trim(\Artisan::output());
diff --git a/src/tests/Feature/Controller/FsTest.php b/src/tests/Feature/Controller/FsTest.php
--- a/src/tests/Feature/Controller/FsTest.php
+++ b/src/tests/Feature/Controller/FsTest.php
@@ -2,9 +2,9 @@
namespace Tests\Feature\Controller;
-use App\Backends\Storage;
use App\Fs\Item;
use App\Fs\Property;
+use App\Support\Facades\Storage;
use App\User;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage as LaravelStorage;
diff --git a/src/tests/Feature/Controller/HealthTest.php b/src/tests/Feature/Controller/HealthTest.php
--- a/src/tests/Feature/Controller/HealthTest.php
+++ b/src/tests/Feature/Controller/HealthTest.php
@@ -4,9 +4,6 @@
use Tests\TestCase;
-/**
- * @group files
- */
class HealthTest extends TestCase
{
/**
diff --git a/src/tests/Feature/Controller/MetricsTest.php b/src/tests/Feature/Controller/MetricsTest.php
--- a/src/tests/Feature/Controller/MetricsTest.php
+++ b/src/tests/Feature/Controller/MetricsTest.php
@@ -4,9 +4,6 @@
use Tests\TestCase;
-/**
- * @group files
- */
class MetricsTest extends TestCase
{
/**
diff --git a/src/tests/Feature/DataMigrator/KolabTest.php b/src/tests/Feature/DataMigrator/KolabTest.php
--- a/src/tests/Feature/DataMigrator/KolabTest.php
+++ b/src/tests/Feature/DataMigrator/KolabTest.php
@@ -2,7 +2,6 @@
namespace Tests\Feature\DataMigrator;
-use App\Backends\Storage;
use App\DataMigrator\Account;
use App\DataMigrator\Driver\Kolab;
use App\DataMigrator\Driver\Kolab\Tags as KolabTags;
@@ -10,6 +9,7 @@
use App\DataMigrator\Interface\Folder;
use App\DataMigrator\Queue as MigratorQueue;
use App\Fs\Item as FsItem;
+use App\Support\Facades\Storage;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage as LaravelStorage;
use Tests\BackendsTrait;
@@ -19,6 +19,7 @@
* @group slow
* @group dav
* @group imap
+ * @group files
*/
class KolabTest extends TestCase
{
diff --git a/src/tests/Feature/Jobs/PGP/KeyCreateTest.php b/src/tests/Feature/Jobs/PGP/KeyCreateTest.php
--- a/src/tests/Feature/Jobs/PGP/KeyCreateTest.php
+++ b/src/tests/Feature/Jobs/PGP/KeyCreateTest.php
@@ -2,9 +2,7 @@
namespace Tests\Feature\Jobs\PGP;
-use App\Backends\PGP;
-use App\Backends\Roundcube;
-use App\User;
+use App\Support\Facades\PGP;
use App\UserAlias;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -18,10 +16,7 @@
{
parent::setUp();
- $user = $this->getTestUser('john@kolab.org');
UserAlias::where('alias', 'test-alias@kolab.org')->delete();
- PGP::homedirCleanup($user);
- \App\PowerDNS\Domain::where('name', '_woat.kolab.org')->delete();
}
/**
@@ -29,113 +24,33 @@
*/
public function tearDown(): void
{
- $user = $this->getTestUser('john@kolab.org');
UserAlias::where('alias', 'test-alias@kolab.org')->delete();
- PGP::homedirCleanup($user);
- \App\PowerDNS\Domain::where('name', '_woat.kolab.org')->delete();
parent::tearDown();
}
/**
* Test job handle
- *
- * @group pgp
*/
public function testHandle(): void
{
- $user = $this->getTestUser('john@kolab.org');
-
- $job = new \App\Jobs\PGP\KeyCreateJob($user->id, $user->email);
- $job->handle();
-
- // Assert the Enigma storage has been initialized and contains the key
- $files = Roundcube::enigmaList($user->email);
- // TODO: More detailed asserts on the filestore content, but it's specific to GPG version
- $this->assertTrue(count($files) > 1);
-
- // Assert the created keypair parameters
- $keys = PGP::listKeys($user);
-
- $this->assertCount(1, $keys);
-
- $userIds = $keys[0]->getUserIds();
- $this->assertCount(1, $userIds);
- $this->assertSame($user->email, $userIds[0]->getEmail());
- $this->assertSame('', $userIds[0]->getName());
- $this->assertSame('', $userIds[0]->getComment());
- $this->assertSame(true, $userIds[0]->isValid());
- $this->assertSame(false, $userIds[0]->isRevoked());
-
- $key = $keys[0]->getPrimaryKey();
- $this->assertSame(\Crypt_GPG_SubKey::ALGORITHM_RSA, $key->getAlgorithm());
- $this->assertSame(0, $key->getExpirationDate());
- $this->assertSame((int) \config('pgp.length'), $key->getLength());
- $this->assertSame(true, $key->hasPrivate());
- $this->assertSame(true, $key->canSign());
- $this->assertSame(false, $key->canEncrypt());
- $this->assertSame(false, $key->isRevoked());
-
- $key = $keys[0]->getSubKeys()[1];
- $this->assertSame(\Crypt_GPG_SubKey::ALGORITHM_RSA, $key->getAlgorithm());
- $this->assertSame(0, $key->getExpirationDate());
- $this->assertSame((int) \config('pgp.length'), $key->getLength());
- $this->assertSame(false, $key->canSign());
- $this->assertSame(true, $key->canEncrypt());
- $this->assertSame(false, $key->isRevoked());
-
- // Assert the public key in DNS
- $dns_domain = \App\PowerDNS\Domain::where('name', '_woat.kolab.org')->first();
- $this->assertNotNull($dns_domain);
- $dns_record = $dns_domain->records()->where('type', 'TXT')->first();
- $this->assertNotNull($dns_record);
- $this->assertSame('TXT', $dns_record->type);
- $this->assertSame(sha1('john') . '._woat.kolab.org', $dns_record->name);
- $this->assertMatchesRegularExpression(
- '/^v=woat1,public_key='
- . '-----BEGIN PGP PUBLIC KEY BLOCK-----'
- . '[a-zA-Z0-9\n\/+=]+'
- . '-----END PGP PUBLIC KEY BLOCK-----'
- . '$/',
- $dns_record->content
- );
-
- // Test an alias
Queue::fake();
- UserAlias::create(['user_id' => $user->id, 'alias' => 'test-alias@kolab.org']);
- $job = new \App\Jobs\PGP\KeyCreateJob($user->id, 'test-alias@kolab.org');
- $job->handle();
- // Assert the created keypair parameters
- $keys = PGP::listKeys($user);
-
- $this->assertCount(2, $keys);
+ $user = $this->getTestUser('john@kolab.org');
- $userIds = $keys[1]->getUserIds();
- $this->assertCount(1, $userIds);
- $this->assertSame('test-alias@kolab.org', $userIds[0]->getEmail());
- $this->assertSame('', $userIds[0]->getName());
- $this->assertSame('', $userIds[0]->getComment());
- $this->assertSame(true, $userIds[0]->isValid());
- $this->assertSame(false, $userIds[0]->isRevoked());
+ // Test without an alias
+ PGP::shouldReceive('keypairCreate')->once()->with($user, $user->email);
- $key = $keys[1]->getPrimaryKey();
- $this->assertSame(\Crypt_GPG_SubKey::ALGORITHM_RSA, $key->getAlgorithm());
- $this->assertSame(0, $key->getExpirationDate());
- $this->assertSame((int) \config('pgp.length'), $key->getLength());
- $this->assertSame(true, $key->hasPrivate());
- $this->assertSame(true, $key->canSign());
- $this->assertSame(false, $key->canEncrypt());
- $this->assertSame(false, $key->isRevoked());
+ $job = (new \App\Jobs\PGP\KeyCreateJob($user->id, $user->email))->withFakeQueueInteractions();
+ $job->handle();
+ $job->assertNotFailed();
- $key = $keys[1]->getSubKeys()[1];
- $this->assertSame(\Crypt_GPG_SubKey::ALGORITHM_RSA, $key->getAlgorithm());
- $this->assertSame(0, $key->getExpirationDate());
- $this->assertSame((int) \config('pgp.length'), $key->getLength());
- $this->assertSame(false, $key->canSign());
- $this->assertSame(true, $key->canEncrypt());
- $this->assertSame(false, $key->isRevoked());
+ // Test with an alias
+ $alias = UserAlias::create(['user_id' => $user->id, 'alias' => 'test-alias@kolab.org']);
+ PGP::shouldReceive('keypairCreate')->once()->with($user, $alias->alias);
- $this->assertSame(2, $dns_domain->records()->where('type', 'TXT')->count());
+ $job = (new \App\Jobs\PGP\KeyCreateJob($user->id, 'test-alias@kolab.org'))->withFakeQueueInteractions();
+ $job->handle();
+ $job->assertNotFailed();
}
}
diff --git a/src/tests/Feature/Jobs/PGP/KeyDeleteTest.php b/src/tests/Feature/Jobs/PGP/KeyDeleteTest.php
--- a/src/tests/Feature/Jobs/PGP/KeyDeleteTest.php
+++ b/src/tests/Feature/Jobs/PGP/KeyDeleteTest.php
@@ -2,70 +2,22 @@
namespace Tests\Feature\Jobs\PGP;
-use App\Backends\PGP;
-use App\Backends\Roundcube;
-use App\User;
-use App\UserAlias;
-use Illuminate\Support\Facades\Queue;
+use App\Support\Facades\PGP;
use Tests\TestCase;
class KeyDeleteTest extends TestCase
{
- /**
- * {@inheritDoc}
- */
- public function setUp(): void
- {
- parent::setUp();
-
- $user = $this->getTestUser('john@kolab.org');
- UserAlias::where('alias', 'test-alias@kolab.org')->delete();
- PGP::homedirCleanup($user);
- \App\PowerDNS\Domain::where('name', '_woat.kolab.org')->delete();
- }
-
- /**
- * {@inheritDoc}
- */
- public function tearDown(): void
- {
- $user = $this->getTestUser('john@kolab.org');
- UserAlias::where('alias', 'test-alias@kolab.org')->delete();
- PGP::homedirCleanup($user);
- \App\PowerDNS\Domain::where('name', '_woat.kolab.org')->delete();
-
- parent::tearDown();
- }
-
/**
* Test job handle
- *
- * @group pgp
*/
public function testHandle(): void
{
- Queue::fake();
-
$user = $this->getTestUser('john@kolab.org');
- // First run the key create job
- $job = new \App\Jobs\PGP\KeyCreateJob($user->id, $user->email);
- $job->handle();
-
- // Assert the public key in DNS exist at this point
- $dns_domain = \App\PowerDNS\Domain::where('name', '_woat.kolab.org')->first();
- $this->assertNotNull($dns_domain);
- $this->assertSame(1, $dns_domain->records()->where('type', 'TXT')->count());
+ PGP::shouldReceive('keyDelete')->once()->with($user, $user->email);
- // Run the job
- $job = new \App\Jobs\PGP\KeyDeleteJob($user->id, $user->email);
+ $job = (new \App\Jobs\PGP\KeyDeleteJob($user->id, $user->email))->withFakeQueueInteractions();
$job->handle();
-
- $this->assertSame(0, $dns_domain->records()->where('type', 'TXT')->count());
-
- // Assert the created keypair parameters
- $keys = PGP::listKeys($user);
-
- $this->assertCount(0, $keys);
+ $job->assertNotFailed();
}
}
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
@@ -2,9 +2,9 @@
namespace Tests\Feature\Jobs\User;
-use App\Backends\Roundcube;
use App\Support\Facades\IMAP;
use App\Support\Facades\LDAP;
+use App\Support\Facades\Roundcube;
use App\User;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -33,24 +33,18 @@
/**
* Test job handle
- *
- * @group roundcube
*/
public function testHandle(): void
{
Queue::fake();
- $rcdb = Roundcube::dbh();
-
$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);
$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]);
@@ -80,6 +74,7 @@
IMAP::shouldReceive('deleteUser')->once()->with($user)->andReturn(true);
LDAP::shouldReceive('deleteUser')->once()->with($user)->andReturn(true);
+ Roundcube::shouldReceive('deleteUser')->once()->with($user->email);
$job = (new \App\Jobs\User\DeleteJob($user->id))->withFakeQueueInteractions();
$job->handle();
@@ -90,7 +85,6 @@
$this->assertFalse($user->isLdapReady());
$this->assertFalse($user->isImapReady());
$this->assertTrue($user->isDeleted());
- $this->assertNull($rcdb->table('users')->where('username', $user->email)->first());
Queue::assertPushed(\App\Jobs\User\UpdateJob::class, 0);
diff --git a/src/tests/ModelMatcher.php b/src/tests/ModelMatcher.php
--- a/src/tests/ModelMatcher.php
+++ b/src/tests/ModelMatcher.php
@@ -8,7 +8,7 @@
{
public function match(&$actual)
{
- return $this->_expected->is($actual);
+ return $this->_expected->is($actual); // @phpstan-ignore-line
}
public function __toString()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 4, 1:30 AM (5 h, 52 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18827579
Default Alt Text
D5208.1775266200.diff (26 KB)
Attached To
Mode
D5208: Add more facades for backend classes
Attached
Detach File
Event Timeline