Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/DomainTest.php
Show All 11 Lines | |||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class DomainTest extends TestCase | class DomainTest extends TestCase | ||||
{ | { | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
Domain::where('namespace', 'public-active.com') | $domains = [ | ||||
->orWhere('namespace', 'gmail.com')->delete(); | 'public-active.com', | ||||
'gmail.com', | |||||
'ci-success-cname.kolab.org', | |||||
'ci-success-txt.kolab.org', | |||||
'ci-failure-cname.kolab.org', | |||||
'ci-failure-txt.kolab.org', | |||||
'ci-failure-none.kolab.org', | |||||
]; | |||||
Domain::whereIn('namespace', $domains)->delete(); | |||||
} | } | ||||
/** | /** | ||||
* Test domain creating jobs | * Test domain creating jobs | ||||
*/ | */ | ||||
public function testCreateJobs(): void | public function testCreateJobs(): void | ||||
{ | { | ||||
// Fake the queue, assert that no jobs were pushed... | // Fake the queue, assert that no jobs were pushed... | ||||
Queue::fake(); | Queue::fake(); | ||||
Queue::assertNothingPushed(); | Queue::assertNothingPushed(); | ||||
$domain = Domain::create([ | $domain = Domain::create([ | ||||
'namespace' => 'gmail.com', | 'namespace' => 'gmail.com', | ||||
'status' => Domain::STATUS_NEW, | 'status' => Domain::STATUS_NEW, | ||||
'type' => Domain::TYPE_EXTERNAL, | 'type' => Domain::TYPE_EXTERNAL, | ||||
]); | ]); | ||||
Queue::assertPushed(\App\Jobs\ProcessDomainCreate::class, 1); | Queue::assertPushed(\App\Jobs\ProcessDomainCreate::class, 1); | ||||
Queue::assertPushed(\App\Jobs\ProcessDomainCreate::class, function ($job) use ($domain) { | Queue::assertPushed(\App\Jobs\ProcessDomainCreate::class, function ($job) use ($domain) { | ||||
$job_domain = TestCase::getObjectProperty($job, 'domain'); | $job_domain = TestCase::getObjectProperty($job, 'domain'); | ||||
return $job_domain->id === $domain->id | return $job_domain->id === $domain->id | ||||
&& $job_domain->namespace === $domain->namespace; | && $job_domain->namespace === $domain->namespace; | ||||
}); | }); | ||||
/* | |||||
Queue::assertPushedWithChain(\App\Jobs\ProcessDomainCreate::class, [ | Queue::assertPushedWithChain(\App\Jobs\ProcessDomainCreate::class, [ | ||||
\App\Jobs\ProcessDomainVerify::class, | \App\Jobs\ProcessDomainVerify::class, | ||||
]); | ]); | ||||
*/ | |||||
/* | /* | ||||
FIXME: Looks like we can't really do detailed assertions on chained jobs | FIXME: Looks like we can't really do detailed assertions on chained jobs | ||||
Another thing to consider is if we maybe should run these jobs | Another thing to consider is if we maybe should run these jobs | ||||
independently (not chained) and make sure there's no race-condition | independently (not chained) and make sure there's no race-condition | ||||
in status update | in status update | ||||
Queue::assertPushed(\App\Jobs\ProcessDomainVerify::class, 1); | Queue::assertPushed(\App\Jobs\ProcessDomainVerify::class, 1); | ||||
Queue::assertPushed(\App\Jobs\ProcessDomainVerify::class, function ($job) use ($domain) { | Queue::assertPushed(\App\Jobs\ProcessDomainVerify::class, function ($job) use ($domain) { | ||||
Show All 31 Lines | public function testGetPublicDomains(): void | ||||
$domain->save(); | $domain->save(); | ||||
// Public and active domain should be returned | // Public and active domain should be returned | ||||
$public_domains = Domain::getPublicDomains(); | $public_domains = Domain::getPublicDomains(); | ||||
$this->assertContains('public-active.com', $public_domains); | $this->assertContains('public-active.com', $public_domains); | ||||
} | } | ||||
/** | /** | ||||
* Test domain confirmation | * Test domain (ownership) confirmation | ||||
* | * | ||||
* @group dns | * @group dns | ||||
*/ | */ | ||||
public function testConfirm(): void | public function testConfirm(): void | ||||
{ | { | ||||
// TODO | /* | ||||
$this->markTestIncomplete(); | DNS records for positive and negative tests - kolab.org: | ||||
} | |||||
/** | ci-success-cname A 212.103.80.148 | ||||
* Test domain verification | ci-success-cname MX 10 mx01.kolabnow.com. | ||||
* | ci-success-cname TXT "v=spf1 mx -all" | ||||
* @group dns | kolab-verify.ci-success-cname CNAME 2b719cfa4e1033b1e1e132977ed4fe3e.ci-success-cname | ||||
ci-failure-cname A 212.103.80.148 | |||||
ci-failure-cname MX 10 mx01.kolabnow.com. | |||||
kolab-verify.ci-failure-cname CNAME 2b719cfa4e1033b1e1e132977ed4fe3e.ci-failure-cname | |||||
ci-success-txt A 212.103.80.148 | |||||
ci-success-txt MX 10 mx01.kolabnow.com. | |||||
ci-success-txt TXT "v=spf1 mx -all" | |||||
ci-success-txt TXT "kolab-verify=de5d04ababb52d52e2519a2f16d11422" | |||||
ci-failure-txt A 212.103.80.148 | |||||
ci-failure-txt MX 10 mx01.kolabnow.com. | |||||
kolab-verify.ci-failure-txt TXT "kolab-verify=de5d04ababb52d52e2519a2f16d11422" | |||||
ci-failure-none A 212.103.80.148 | |||||
ci-failure-none MX 10 mx01.kolabnow.com. | |||||
*/ | */ | ||||
public function testVerify(): void | |||||
{ | Queue::fake(); | ||||
// TODO | |||||
$this->markTestIncomplete(); | $domain_props = ['status' => Domain::STATUS_NEW, 'type' => Domain::TYPE_EXTERNAL]; | ||||
$domain = $this->getTestDomain('ci-failure-none.kolab.org', $domain_props); | |||||
$this->assertTrue($domain->confirm() === false); | |||||
$this->assertTrue(!$domain->isConfirmed()); | |||||
$domain = $this->getTestDomain('ci-failure-txt.kolab.org', $domain_props); | |||||
$this->assertTrue($domain->confirm() === false); | |||||
$this->assertTrue(!$domain->isConfirmed()); | |||||
$domain = $this->getTestDomain('ci-failure-cname.kolab.org', $domain_props); | |||||
$this->assertTrue($domain->confirm() === false); | |||||
$this->assertTrue(!$domain->isConfirmed()); | |||||
$domain = $this->getTestDomain('ci-success-txt.kolab.org', $domain_props); | |||||
$this->assertTrue($domain->confirm()); | |||||
$this->assertTrue($domain->isConfirmed()); | |||||
$domain = $this->getTestDomain('ci-success-cname.kolab.org', $domain_props); | |||||
$this->assertTrue($domain->confirm()); | |||||
$this->assertTrue($domain->isConfirmed()); | |||||
} | } | ||||
} | } |