Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/AuthTest.php
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | public function testInfo(): void | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertEquals($user->id, $json['id']); | $this->assertEquals($user->id, $json['id']); | ||||
$this->assertEquals($user->email, $json['email']); | $this->assertEquals($user->email, $json['email']); | ||||
$this->assertEquals(User::STATUS_NEW | User::STATUS_ACTIVE, $json['status']); | $this->assertEquals(User::STATUS_NEW | User::STATUS_ACTIVE, $json['status']); | ||||
$this->assertTrue(is_array($json['statusInfo'])); | $this->assertTrue(is_array($json['statusInfo'])); | ||||
$this->assertTrue(is_array($json['settings'])); | $this->assertTrue(is_array($json['settings'])); | ||||
$this->assertTrue(is_array($json['aliases'])); | |||||
$this->assertTrue(!isset($json['access_token'])); | $this->assertTrue(!isset($json['access_token'])); | ||||
// Note: Details of the content are tested in testUserResponse() | // Note: Details of the content are tested in testUserResponse() | ||||
// Test token refresh via the info request | // Test token refresh via the info request | ||||
// First we log in to get the refresh token | // First we log in to get the refresh token | ||||
$post = ['email' => 'john@kolab.org', 'password' => 'simple123']; | $post = ['email' => 'john@kolab.org', 'password' => 'simple123']; | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$response = $this->post("api/auth/login", $post); | $response = $this->post("api/auth/login", $post); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response = $this->actingAs($user) | $response = $this->actingAs($user) | ||||
->post("api/auth/info?refresh=1", ['refresh_token' => $json['refresh_token']]); | ->post("api/auth/info?refresh=1", ['refresh_token' => $json['refresh_token']]); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertEquals('john@kolab.org', $json['email']); | $this->assertEquals('john@kolab.org', $json['email']); | ||||
$this->assertTrue(is_array($json['statusInfo'])); | $this->assertTrue(is_array($json['statusInfo'])); | ||||
$this->assertTrue(is_array($json['settings'])); | $this->assertTrue(is_array($json['settings'])); | ||||
$this->assertTrue(is_array($json['aliases'])); | |||||
$this->assertTrue(!empty($json['access_token'])); | $this->assertTrue(!empty($json['access_token'])); | ||||
$this->assertTrue(!empty($json['expires_in'])); | $this->assertTrue(!empty($json['expires_in'])); | ||||
} | } | ||||
/** | /** | ||||
* Test /api/auth/login | * Test /api/auth/login | ||||
*/ | */ | ||||
public function testLogin(): string | public function testLogin(): string | ||||
Show All 30 Lines | public function testLogin(): string | ||||
($this->expectedExpiry - 5) < $json['expires_in'] && | ($this->expectedExpiry - 5) < $json['expires_in'] && | ||||
$json['expires_in'] < ($this->expectedExpiry + 5) | $json['expires_in'] < ($this->expectedExpiry + 5) | ||||
); | ); | ||||
$this->assertEquals('bearer', $json['token_type']); | $this->assertEquals('bearer', $json['token_type']); | ||||
$this->assertEquals($user->id, $json['id']); | $this->assertEquals($user->id, $json['id']); | ||||
$this->assertEquals($user->email, $json['email']); | $this->assertEquals($user->email, $json['email']); | ||||
$this->assertTrue(is_array($json['statusInfo'])); | $this->assertTrue(is_array($json['statusInfo'])); | ||||
$this->assertTrue(is_array($json['settings'])); | $this->assertTrue(is_array($json['settings'])); | ||||
$this->assertTrue(is_array($json['aliases'])); | |||||
// Valid user+password (upper-case) | // Valid user+password (upper-case) | ||||
$post = ['email' => 'John@Kolab.org', 'password' => 'simple123']; | $post = ['email' => 'John@Kolab.org', 'password' => 'simple123']; | ||||
$response = $this->post("api/auth/login", $post); | $response = $this->post("api/auth/login", $post); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertTrue(!empty($json['access_token'])); | $this->assertTrue(!empty($json['access_token'])); | ||||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |