Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/DomainsTest.php
Show All 22 Lines | public function setUp(): void | ||||
$this->deleteTestDomain('domainscontroller.com'); | $this->deleteTestDomain('domainscontroller.com'); | ||||
} | } | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestUser('test1@domainscontroller.com'); | $this->deleteTestUser('test1@domainscontroller.com'); | ||||
$this->deleteTestDomain('domainscontroller.com'); | $this->deleteTestDomain('domainscontroller.com'); | ||||
$domain = $this->getTestDomain('kolab.org'); | |||||
$domain->settings()->whereIn('key', ['spf_whitelist'])->delete(); | |||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test domain confirm request | * Test domain confirm request | ||||
*/ | */ | ||||
public function testConfirm(): void | public function testConfirm(): void | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | public function testIndex(): void | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(1, $json); | $this->assertCount(1, $json); | ||||
$this->assertSame('kolab.org', $json[0]['namespace']); | $this->assertSame('kolab.org', $json[0]['namespace']); | ||||
} | } | ||||
/** | /** | ||||
* Test domain config update (POST /api/v4/domains/<domain>/config) | |||||
*/ | |||||
public function testSetConfig(): void | |||||
{ | |||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$jack = $this->getTestUser('jack@kolab.org'); | |||||
$domain = $this->getTestDomain('kolab.org'); | |||||
$domain->setSetting('spf_whitelist', null); | |||||
// Test unknown domain id | |||||
$post = ['spf_whitelist' => []]; | |||||
$response = $this->actingAs($john)->post("/api/v4/domains/123/config", $post); | |||||
$json = $response->json(); | |||||
$response->assertStatus(404); | |||||
// Test access by user not being a wallet controller | |||||
$post = ['spf_whitelist' => []]; | |||||
$response = $this->actingAs($jack)->post("/api/v4/domains/{$domain->id}/config", $post); | |||||
$json = $response->json(); | |||||
$response->assertStatus(403); | |||||
$this->assertSame('error', $json['status']); | |||||
$this->assertSame("Access denied", $json['message']); | |||||
$this->assertCount(2, $json); | |||||
// Test some invalid data | |||||
$post = ['grey' => 1]; | |||||
$response = $this->actingAs($john)->post("/api/v4/domains/{$domain->id}/config", $post); | |||||
$response->assertStatus(422); | |||||
$json = $response->json(); | |||||
$this->assertSame('error', $json['status']); | |||||
$this->assertCount(2, $json); | |||||
$this->assertCount(1, $json['errors']); | |||||
$this->assertSame('The requested configuration parameter is not supported.', $json['errors']['grey']); | |||||
$this->assertNull($domain->fresh()->getSetting('spf_whitelist')); | |||||
// Test some valid data | |||||
$post = ['spf_whitelist' => ['.test.domain.com']]; | |||||
$response = $this->actingAs($john)->post("/api/v4/domains/{$domain->id}/config", $post); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertCount(2, $json); | |||||
$this->assertSame('success', $json['status']); | |||||
$this->assertSame('Domain settings updated successfully.', $json['message']); | |||||
$expected = \json_encode($post['spf_whitelist']); | |||||
$this->assertSame($expected, $domain->fresh()->getSetting('spf_whitelist')); | |||||
// Test input validation | |||||
$post = ['spf_whitelist' => ['aaa']]; | |||||
$response = $this->actingAs($john)->post("/api/v4/domains/{$domain->id}/config", $post); | |||||
$response->assertStatus(422); | |||||
$json = $response->json(); | |||||
$this->assertCount(2, $json); | |||||
$this->assertSame('error', $json['status']); | |||||
$this->assertCount(1, $json['errors']); | |||||
$this->assertSame( | |||||
'The entry format is invalid. Expected a domain name starting with a dot.', | |||||
$json['errors']['spf_whitelist'][0] | |||||
); | |||||
$this->assertSame($expected, $domain->fresh()->getSetting('spf_whitelist')); | |||||
} | |||||
/** | |||||
* Test fetching domain info | * Test fetching domain info | ||||
*/ | */ | ||||
public function testShow(): void | public function testShow(): void | ||||
{ | { | ||||
$sku_domain = Sku::where('title', 'domain-hosting')->first(); | $sku_domain = Sku::where('title', 'domain-hosting')->first(); | ||||
$user = $this->getTestUser('test1@domainscontroller.com'); | $user = $this->getTestUser('test1@domainscontroller.com'); | ||||
$domain = $this->getTestDomain('domainscontroller.com', [ | $domain = $this->getTestDomain('domainscontroller.com', [ | ||||
'status' => Domain::STATUS_NEW, | 'status' => Domain::STATUS_NEW, | ||||
Show All 14 Lines | public function testShow(): void | ||||
$this->assertEquals($domain->id, $json['id']); | $this->assertEquals($domain->id, $json['id']); | ||||
$this->assertEquals($domain->namespace, $json['namespace']); | $this->assertEquals($domain->namespace, $json['namespace']); | ||||
$this->assertEquals($domain->status, $json['status']); | $this->assertEquals($domain->status, $json['status']); | ||||
$this->assertEquals($domain->type, $json['type']); | $this->assertEquals($domain->type, $json['type']); | ||||
$this->assertSame($domain->hash(Domain::HASH_TEXT), $json['hash_text']); | $this->assertSame($domain->hash(Domain::HASH_TEXT), $json['hash_text']); | ||||
$this->assertSame($domain->hash(Domain::HASH_CNAME), $json['hash_cname']); | $this->assertSame($domain->hash(Domain::HASH_CNAME), $json['hash_cname']); | ||||
$this->assertSame($domain->hash(Domain::HASH_CODE), $json['hash_code']); | $this->assertSame($domain->hash(Domain::HASH_CODE), $json['hash_code']); | ||||
$this->assertCount(4, $json['config']); | $this->assertSame([], $json['config']['spf_whitelist']); | ||||
$this->assertTrue(strpos(implode("\n", $json['config']), $domain->namespace) !== false); | $this->assertCount(4, $json['mx']); | ||||
$this->assertTrue(strpos(implode("\n", $json['mx']), $domain->namespace) !== false); | |||||
$this->assertCount(8, $json['dns']); | $this->assertCount(8, $json['dns']); | ||||
$this->assertTrue(strpos(implode("\n", $json['dns']), $domain->namespace) !== false); | $this->assertTrue(strpos(implode("\n", $json['dns']), $domain->namespace) !== false); | ||||
$this->assertTrue(strpos(implode("\n", $json['dns']), $domain->hash()) !== false); | $this->assertTrue(strpos(implode("\n", $json['dns']), $domain->hash()) !== false); | ||||
$this->assertTrue(is_array($json['statusInfo'])); | $this->assertTrue(is_array($json['statusInfo'])); | ||||
// Values below are tested by Unit tests | // Values below are tested by Unit tests | ||||
$this->assertArrayHasKey('isConfirmed', $json); | $this->assertArrayHasKey('isConfirmed', $json); | ||||
$this->assertArrayHasKey('isDeleted', $json); | $this->assertArrayHasKey('isDeleted', $json); | ||||
$this->assertArrayHasKey('isVerified', $json); | $this->assertArrayHasKey('isVerified', $json); | ||||
▲ Show 20 Lines • Show All 75 Lines • Show Last 20 Lines |