Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Jobs/PGP/KeyCreateTest.php
Show All 15 Lines | class KeyCreateTest extends TestCase | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
UserAlias::where('alias', 'test-alias@kolab.org')->delete(); | UserAlias::where('alias', 'test-alias@kolab.org')->delete(); | ||||
PGP::homedirCleanup($user); | PGP::homedirCleanup($user); | ||||
\App\PowerDNS\Domain::where('name', '_woat.kolab.org')->delete(); | |||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
UserAlias::where('alias', 'test-alias@kolab.org')->delete(); | UserAlias::where('alias', 'test-alias@kolab.org')->delete(); | ||||
PGP::homedirCleanup($user); | PGP::homedirCleanup($user); | ||||
\App\PowerDNS\Domain::where('name', '_woat.kolab.org')->delete(); | |||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test job handle | * Test job handle | ||||
* | * | ||||
* @group pgp | * @group pgp | ||||
Show All 35 Lines | public function testHandle(): void | ||||
$key = $keys[0]->getSubKeys()[1]; | $key = $keys[0]->getSubKeys()[1]; | ||||
$this->assertSame(\Crypt_GPG_SubKey::ALGORITHM_RSA, $key->getAlgorithm()); | $this->assertSame(\Crypt_GPG_SubKey::ALGORITHM_RSA, $key->getAlgorithm()); | ||||
$this->assertSame(0, $key->getExpirationDate()); | $this->assertSame(0, $key->getExpirationDate()); | ||||
$this->assertSame((int) \config('pgp.length'), $key->getLength()); | $this->assertSame((int) \config('pgp.length'), $key->getLength()); | ||||
$this->assertSame(false, $key->canSign()); | $this->assertSame(false, $key->canSign()); | ||||
$this->assertSame(true, $key->canEncrypt()); | $this->assertSame(true, $key->canEncrypt()); | ||||
$this->assertSame(false, $key->isRevoked()); | $this->assertSame(false, $key->isRevoked()); | ||||
// TODO: Assert the public key in DNS? | // 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 | // Test an alias | ||||
Queue::fake(); | Queue::fake(); | ||||
UserAlias::create(['user_id' => $user->id, 'alias' => 'test-alias@kolab.org']); | UserAlias::create(['user_id' => $user->id, 'alias' => 'test-alias@kolab.org']); | ||||
$job = new \App\Jobs\PGP\KeyCreateJob($user->id, 'test-alias@kolab.org'); | $job = new \App\Jobs\PGP\KeyCreateJob($user->id, 'test-alias@kolab.org'); | ||||
$job->handle(); | $job->handle(); | ||||
// Assert the created keypair parameters | // Assert the created keypair parameters | ||||
Show All 20 Lines | public function testHandle(): void | ||||
$key = $keys[1]->getSubKeys()[1]; | $key = $keys[1]->getSubKeys()[1]; | ||||
$this->assertSame(\Crypt_GPG_SubKey::ALGORITHM_RSA, $key->getAlgorithm()); | $this->assertSame(\Crypt_GPG_SubKey::ALGORITHM_RSA, $key->getAlgorithm()); | ||||
$this->assertSame(0, $key->getExpirationDate()); | $this->assertSame(0, $key->getExpirationDate()); | ||||
$this->assertSame((int) \config('pgp.length'), $key->getLength()); | $this->assertSame((int) \config('pgp.length'), $key->getLength()); | ||||
$this->assertSame(false, $key->canSign()); | $this->assertSame(false, $key->canSign()); | ||||
$this->assertSame(true, $key->canEncrypt()); | $this->assertSame(true, $key->canEncrypt()); | ||||
$this->assertSame(false, $key->isRevoked()); | $this->assertSame(false, $key->isRevoked()); | ||||
$this->assertSame(2, $dns_domain->records()->where('type', 'TXT')->count()); | |||||
} | } | ||||
} | } |