Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/DomainsTest.php
Show All 32 Lines | class DomainsTest extends TestCase | ||||
} | } | ||||
/** | /** | ||||
* Test domain confirm request | * Test domain confirm request | ||||
*/ | */ | ||||
public function testConfirm(): void | public function testConfirm(): void | ||||
{ | { | ||||
$sku_domain = Sku::where('title', 'domain')->first(); | $sku_domain = Sku::where('title', 'domain')->first(); | ||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$ned = $this->getTestUser('ned@kolab.org'); | |||||
$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, | ||||
'type' => Domain::TYPE_EXTERNAL, | 'type' => Domain::TYPE_EXTERNAL, | ||||
]); | ]); | ||||
// No entitlement (user has no access to this domain), expect 403 | |||||
$response = $this->actingAs($user)->get("api/v4/domains/{$domain->id}/confirm"); | |||||
$response->assertStatus(403); | |||||
Entitlement::create([ | Entitlement::create([ | ||||
'owner_id' => $user->id, | 'owner_id' => $user->id, | ||||
'wallet_id' => $user->wallets()->first()->id, | 'wallet_id' => $user->wallets()->first()->id, | ||||
'sku_id' => $sku_domain->id, | 'sku_id' => $sku_domain->id, | ||||
'entitleable_id' => $domain->id, | 'entitleable_id' => $domain->id, | ||||
'entitleable_type' => Domain::class | 'entitleable_type' => Domain::class | ||||
]); | ]); | ||||
$response = $this->actingAs($user)->get("api/v4/domains/{$domain->id}/confirm"); | $response = $this->actingAs($user)->get("api/v4/domains/{$domain->id}/confirm"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertEquals('error', $json['status']); | $this->assertEquals('error', $json['status']); | ||||
$domain->status |= Domain::STATUS_CONFIRMED; | $domain->status |= Domain::STATUS_CONFIRMED; | ||||
$domain->save(); | $domain->save(); | ||||
$response = $this->actingAs($user)->get("api/v4/domains/{$domain->id}/confirm"); | $response = $this->actingAs($user)->get("api/v4/domains/{$domain->id}/confirm"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertEquals('success', $json['status']); | $this->assertEquals('success', $json['status']); | ||||
$this->assertEquals('Domain verified successfully', $json['message']); | $this->assertEquals('Domain verified successfully.', $json['message']); | ||||
// Not authorized access | |||||
$response = $this->actingAs($john)->get("api/v4/domains/{$domain->id}/confirm"); | |||||
$response->assertStatus(403); | |||||
// Authorized access by additional account controller | |||||
$domain = $this->getTestDomain('kolab.org'); | |||||
$response = $this->actingAs($ned)->get("api/v4/domains/{$domain->id}/confirm"); | |||||
$response->assertStatus(200); | |||||
} | } | ||||
/** | /** | ||||
* Test fetching domains list | * Test fetching domains list | ||||
*/ | */ | ||||
public function testIndex(): void | public function testIndex(): void | ||||
{ | { | ||||
// User with no domains | // User with no domains | ||||
$user = $this->getTestUser('test1@domainscontroller.com'); | $user = $this->getTestUser('test1@domainscontroller.com'); | ||||
$response = $this->actingAs($user)->get("api/v4/domains"); | $response = $this->actingAs($user)->get("api/v4/domains"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame([], $json); | $this->assertSame([], $json); | ||||
// User with custom domain(s) | // User with custom domain(s) | ||||
$user = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$ned = $this->getTestUser('ned@kolab.org'); | |||||
$response = $this->actingAs($user)->get("api/v4/domains"); | $response = $this->actingAs($john)->get("api/v4/domains"); | ||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertCount(1, $json); | |||||
$this->assertSame('kolab.org', $json[0]['namespace']); | |||||
$response = $this->actingAs($ned)->get("api/v4/domains"); | |||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$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 fetching domain info | * Test fetching domain info | ||||
*/ | */ | ||||
public function testShow(): void | public function testShow(): void | ||||
{ | { | ||||
$sku_domain = Sku::where('title', 'domain')->first(); | $sku_domain = Sku::where('title', 'domain')->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, | ||||
'type' => Domain::TYPE_EXTERNAL, | 'type' => Domain::TYPE_EXTERNAL, | ||||
]); | ]); | ||||
// No entitlement (user has no access to this domain), expect 403 | |||||
$response = $this->actingAs($user)->get("api/v4/domains/{$domain->id}"); | |||||
$response->assertStatus(403); | |||||
Entitlement::create([ | Entitlement::create([ | ||||
'owner_id' => $user->id, | 'owner_id' => $user->id, | ||||
'wallet_id' => $user->wallets()->first()->id, | 'wallet_id' => $user->wallets()->first()->id, | ||||
'sku_id' => $sku_domain->id, | 'sku_id' => $sku_domain->id, | ||||
'entitleable_id' => $domain->id, | 'entitleable_id' => $domain->id, | ||||
'entitleable_type' => Domain::class | 'entitleable_type' => Domain::class | ||||
]); | ]); | ||||
Show All 10 Lines | public function testShow(): void | ||||
$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->assertCount(4, $json['config']); | ||||
$this->assertTrue(strpos(implode("\n", $json['config']), $domain->namespace) !== false); | $this->assertTrue(strpos(implode("\n", $json['config']), $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); | ||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$ned = $this->getTestUser('ned@kolab.org'); | |||||
$jack = $this->getTestUser('jack@kolab.org'); | |||||
// Not authorized - Other account domain | |||||
$response = $this->actingAs($john)->get("api/v4/domains/{$domain->id}"); | |||||
$response->assertStatus(403); | |||||
$domain = $this->getTestDomain('kolab.org'); | |||||
// Ned is an additional controller on kolab.org's wallet | |||||
$response = $this->actingAs($ned)->get("api/v4/domains/{$domain->id}"); | |||||
$response->assertStatus(200); | |||||
// Jack has no entitlement/control over kolab.org | |||||
$response = $this->actingAs($jack)->get("api/v4/domains/{$domain->id}"); | |||||
$response->assertStatus(403); | |||||
} | } | ||||
} | } |