Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/PasswordPolicyTest.php
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | class PasswordPolicyTest extends TestCase | ||||
{ | { | ||||
// Unauth access not allowed | // Unauth access not allowed | ||||
$response = $this->get('/api/v4/password-policy'); | $response = $this->get('/api/v4/password-policy'); | ||||
$response->assertStatus(401); | $response->assertStatus(401); | ||||
$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('password_policy', 'min:8,max:255,special'); | $john->setSetting('password_policy', 'min:8,max:255,special'); | ||||
$john->setSetting('max_password_age', 6); | |||||
// Get available policy rules | // Get available policy rules | ||||
$response = $this->actingAs($john)->get('/api/v4/password-policy'); | $response = $this->actingAs($john)->get('/api/v4/password-policy'); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertCount(2, $json); | $this->assertCount(3, $json); | ||||
$this->assertSame(7, $json['count']); | $this->assertSame(7, $json['count']); | ||||
$this->assertCount(7, $json['list']); | $this->assertCount(7, $json['list']); | ||||
$this->assertSame(['max_password_age' => '6'], $json['config']); | |||||
$this->assertSame('Minimum password length: 8 characters', $json['list'][0]['name']); | $this->assertSame('Minimum password length: 8 characters', $json['list'][0]['name']); | ||||
$this->assertSame('min', $json['list'][0]['label']); | $this->assertSame('min', $json['list'][0]['label']); | ||||
$this->assertSame('8', $json['list'][0]['param']); | $this->assertSame('8', $json['list'][0]['param']); | ||||
$this->assertSame(true, $json['list'][0]['enabled']); | $this->assertSame(true, $json['list'][0]['enabled']); | ||||
$this->assertSame('Maximum password length: 255 characters', $json['list'][1]['name']); | $this->assertSame('Maximum password length: 255 characters', $json['list'][1]['name']); | ||||
$this->assertSame('max', $json['list'][1]['label']); | $this->assertSame('max', $json['list'][1]['label']); | ||||
$this->assertSame('255', $json['list'][1]['param']); | $this->assertSame('255', $json['list'][1]['param']); | ||||
$this->assertSame(true, $json['list'][1]['enabled']); | $this->assertSame(true, $json['list'][1]['enabled']); | ||||
Show All 9 Lines | public function testIndex(): void | ||||
$this->assertSame(false, $json['list'][6]['enabled']); | $this->assertSame(false, $json['list'][6]['enabled']); | ||||
// Test acting as Jack | // Test acting as Jack | ||||
$response = $this->actingAs($jack)->get('/api/v4/password-policy'); | $response = $this->actingAs($jack)->get('/api/v4/password-policy'); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertCount(2, $json); | $this->assertCount(3, $json); | ||||
$this->assertSame(7, $json['count']); | $this->assertSame(7, $json['count']); | ||||
$this->assertCount(7, $json['list']); | $this->assertCount(7, $json['list']); | ||||
$this->assertSame(['max_password_age' => '6'], $json['config']); | |||||
$this->assertSame('Minimum password length: 8 characters', $json['list'][0]['name']); | $this->assertSame('Minimum password length: 8 characters', $json['list'][0]['name']); | ||||
$this->assertSame('min', $json['list'][0]['label']); | $this->assertSame('min', $json['list'][0]['label']); | ||||
$this->assertSame('8', $json['list'][0]['param']); | $this->assertSame('8', $json['list'][0]['param']); | ||||
$this->assertSame(true, $json['list'][0]['enabled']); | $this->assertSame(true, $json['list'][0]['enabled']); | ||||
$this->assertSame('Maximum password length: 255 characters', $json['list'][1]['name']); | $this->assertSame('Maximum password length: 255 characters', $json['list'][1]['name']); | ||||
$this->assertSame('max', $json['list'][1]['label']); | $this->assertSame('max', $json['list'][1]['label']); | ||||
$this->assertSame('255', $json['list'][1]['param']); | $this->assertSame('255', $json['list'][1]['param']); | ||||
$this->assertSame(true, $json['list'][1]['enabled']); | $this->assertSame(true, $json['list'][1]['enabled']); | ||||
Show All 12 Lines |