Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show First 20 Lines • Show All 526 Lines • ▼ Show 20 Lines | class UsersTest extends TestCase | ||||
*/ | */ | ||||
public function testSetConfig(): void | public function testSetConfig(): void | ||||
{ | { | ||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$john->setSetting('greylist_enabled', null); | $john->setSetting('greylist_enabled', null); | ||||
$john->setSetting('password_policy', null); | $john->setSetting('password_policy', null); | ||||
$john->setSetting('max_password_age', null); | |||||
// Test unknown user id | // Test unknown user id | ||||
$post = ['greylist_enabled' => 1]; | $post = ['greylist_enabled' => 1]; | ||||
$response = $this->actingAs($john)->post("/api/v4/users/123/config", $post); | $response = $this->actingAs($john)->post("/api/v4/users/123/config", $post); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(404); | $response->assertStatus(404); | ||||
Show All 19 Lines | public function testSetConfig(): void | ||||
$this->assertCount(2, $json); | $this->assertCount(2, $json); | ||||
$this->assertCount(2, $json['errors']); | $this->assertCount(2, $json['errors']); | ||||
$this->assertSame("The requested configuration parameter is not supported.", $json['errors']['grey']); | $this->assertSame("The requested configuration parameter is not supported.", $json['errors']['grey']); | ||||
$this->assertSame("Minimum password length cannot be less than 6.", $json['errors']['password_policy']); | $this->assertSame("Minimum password length cannot be less than 6.", $json['errors']['password_policy']); | ||||
$this->assertNull($john->fresh()->getSetting('greylist_enabled')); | $this->assertNull($john->fresh()->getSetting('greylist_enabled')); | ||||
// Test some valid data | // Test some valid data | ||||
$post = ['greylist_enabled' => 1, 'password_policy' => 'min:10,max:255,upper,lower,digit,special']; | $post = [ | ||||
'greylist_enabled' => 1, | |||||
'password_policy' => 'min:10,max:255,upper,lower,digit,special', | |||||
'max_password_age' => 6, | |||||
]; | |||||
$response = $this->actingAs($john)->post("/api/v4/users/{$john->id}/config", $post); | $response = $this->actingAs($john)->post("/api/v4/users/{$john->id}/config", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(2, $json); | $this->assertCount(2, $json); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame('User settings updated successfully.', $json['message']); | $this->assertSame('User settings updated successfully.', $json['message']); | ||||
$this->assertSame('true', $john->fresh()->getSetting('greylist_enabled')); | $this->assertSame('true', $john->getSetting('greylist_enabled')); | ||||
$this->assertSame('min:10,max:255,upper,lower,digit,special', $john->fresh()->getSetting('password_policy')); | $this->assertSame('min:10,max:255,upper,lower,digit,special', $john->getSetting('password_policy')); | ||||
$this->assertSame('6', $john->getSetting('max_password_age')); | |||||
// Test some valid data, acting as another account controller | // Test some valid data, acting as another account controller | ||||
$ned = $this->getTestUser('ned@kolab.org'); | $ned = $this->getTestUser('ned@kolab.org'); | ||||
$post = ['greylist_enabled' => 0, 'password_policy' => 'min:10,max:255,upper,last:1']; | $post = ['greylist_enabled' => 0, 'password_policy' => 'min:10,max:255,upper,last:1']; | ||||
$response = $this->actingAs($ned)->post("/api/v4/users/{$john->id}/config", $post); | $response = $this->actingAs($ned)->post("/api/v4/users/{$john->id}/config", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
▲ Show 20 Lines • Show All 920 Lines • Show Last 20 Lines |