Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/Reseller/UsersTest.php
Show All 37 Lines | public function tearDown(): void | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test user deleting (DELETE /api/v4/users/<id>) | * Test user deleting (DELETE /api/v4/users/<id>) | ||||
*/ | */ | ||||
public function testDestroy(): void | public function testDestroy(): void | ||||
{ | { | ||||
$reseller1 = $this->getTestUser('reseller@kolabnow.com'); | $reseller1 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | $user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | ||||
// Test unauth access | // Test unauth access | ||||
$response = $this->delete("api/v4/users/{$user->id}"); | $response = $this->delete("api/v4/users/{$user->id}"); | ||||
$response->assertStatus(401); | $response->assertStatus(401); | ||||
// The end-point does not exist | // The end-point does not exist | ||||
$response = $this->actingAs($reseller1)->delete("api/v4/users/{$user->id}"); | $response = $this->actingAs($reseller1)->delete("api/v4/users/{$user->id}"); | ||||
$response->assertStatus(404); | $response->assertStatus(404); | ||||
} | } | ||||
/** | /** | ||||
* Test users searching (/api/v4/users) | * Test users searching (/api/v4/users) | ||||
*/ | */ | ||||
public function testIndex(): void | public function testIndex(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
$reseller1 = $this->getTestUser('reseller@kolabnow.com'); | $reseller1 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$reseller2 = $this->getTestUser('reseller@reseller.com'); | $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local'); | ||||
\config(['app.tenant_id' => 2]); | \config(['app.tenant_id' => 2]); | ||||
// Guess access | // Guess access | ||||
$response = $this->get("api/v4/users"); | $response = $this->get("api/v4/users"); | ||||
$response->assertStatus(401); | $response->assertStatus(401); | ||||
// Normal user | // Normal user | ||||
▲ Show 20 Lines • Show All 180 Lines • ▼ Show 20 Lines | class UsersTest extends TestCase | ||||
/** | /** | ||||
* Test reseting 2FA (POST /api/v4/users/<user-id>/reset2FA) | * Test reseting 2FA (POST /api/v4/users/<user-id>/reset2FA) | ||||
*/ | */ | ||||
public function testReset2FA(): void | public function testReset2FA(): void | ||||
{ | { | ||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | $user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
$reseller1 = $this->getTestUser('reseller@kolabnow.com'); | $reseller1 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$reseller2 = $this->getTestUser('reseller@reseller.com'); | $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local'); | ||||
$sku2fa = \App\Sku::firstOrCreate(['title' => '2fa']); | $sku2fa = \App\Sku::firstOrCreate(['title' => '2fa']); | ||||
$user->assignSku($sku2fa); | $user->assignSku($sku2fa); | ||||
\App\Auth\SecondFactor::seed('userscontrollertest1@userscontroller.com'); | \App\Auth\SecondFactor::seed('userscontrollertest1@userscontroller.com'); | ||||
// Test unauthorized access | // Test unauthorized access | ||||
$response = $this->actingAs($user)->post("/api/v4/users/{$user->id}/reset2FA", []); | $response = $this->actingAs($user)->post("/api/v4/users/{$user->id}/reset2FA", []); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
Show All 36 Lines | public function testReset2FA(): void | ||||
$response->assertStatus(404); | $response->assertStatus(404); | ||||
} | } | ||||
/** | /** | ||||
* Test user creation (POST /api/v4/users) | * Test user creation (POST /api/v4/users) | ||||
*/ | */ | ||||
public function testStore(): void | public function testStore(): void | ||||
{ | { | ||||
$reseller1 = $this->getTestUser('reseller@kolabnow.com'); | $reseller1 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
// The end-point does not exist | // The end-point does not exist | ||||
$response = $this->actingAs($reseller1)->post("/api/v4/users", []); | $response = $this->actingAs($reseller1)->post("/api/v4/users", []); | ||||
$response->assertStatus(404); | $response->assertStatus(404); | ||||
} | } | ||||
/** | /** | ||||
* Test user suspending (POST /api/v4/users/<user-id>/suspend) | * Test user suspending (POST /api/v4/users/<user-id>/suspend) | ||||
*/ | */ | ||||
public function testSuspend(): void | public function testSuspend(): void | ||||
{ | { | ||||
Queue::fake(); // disable jobs | Queue::fake(); // disable jobs | ||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | $user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
$reseller1 = $this->getTestUser('reseller@kolabnow.com'); | $reseller1 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$reseller2 = $this->getTestUser('reseller@reseller.com'); | $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local'); | ||||
// Test unauthorized access | // Test unauthorized access | ||||
$response = $this->actingAs($user)->post("/api/v4/users/{$user->id}/suspend", []); | $response = $this->actingAs($user)->post("/api/v4/users/{$user->id}/suspend", []); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
$response = $this->actingAs($admin)->post("/api/v4/users/{$user->id}/suspend", []); | $response = $this->actingAs($admin)->post("/api/v4/users/{$user->id}/suspend", []); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
Show All 27 Lines | class UsersTest extends TestCase | ||||
* Test user un-suspending (POST /api/v4/users/<user-id>/unsuspend) | * Test user un-suspending (POST /api/v4/users/<user-id>/unsuspend) | ||||
*/ | */ | ||||
public function testUnsuspend(): void | public function testUnsuspend(): void | ||||
{ | { | ||||
Queue::fake(); // disable jobs | Queue::fake(); // disable jobs | ||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | $user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
$reseller1 = $this->getTestUser('reseller@kolabnow.com'); | $reseller1 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$reseller2 = $this->getTestUser('reseller@reseller.com'); | $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local'); | ||||
// Test unauthorized access to admin API | // Test unauthorized access to admin API | ||||
$response = $this->actingAs($user)->post("/api/v4/users/{$user->id}/unsuspend", []); | $response = $this->actingAs($user)->post("/api/v4/users/{$user->id}/unsuspend", []); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
$response = $this->actingAs($admin)->post("/api/v4/users/{$user->id}/unsuspend", []); | $response = $this->actingAs($admin)->post("/api/v4/users/{$user->id}/unsuspend", []); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
Show All 27 Lines | class UsersTest extends TestCase | ||||
/** | /** | ||||
* Test user update (PUT /api/v4/users/<user-id>) | * Test user update (PUT /api/v4/users/<user-id>) | ||||
*/ | */ | ||||
public function testUpdate(): void | public function testUpdate(): void | ||||
{ | { | ||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | $user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
$reseller1 = $this->getTestUser('reseller@kolabnow.com'); | $reseller1 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$reseller2 = $this->getTestUser('reseller@reseller.com'); | $reseller2 = $this->getTestUser('reseller@sample-tenant.dev-local'); | ||||
// Test unauthorized access | // Test unauthorized access | ||||
$response = $this->actingAs($user)->put("/api/v4/users/{$user->id}", []); | $response = $this->actingAs($user)->put("/api/v4/users/{$user->id}", []); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
$response = $this->actingAs($admin)->put("/api/v4/users/{$user->id}", []); | $response = $this->actingAs($admin)->put("/api/v4/users/{$user->id}", []); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |