2018-11-09 18:22:43 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
|
|
|
*
|
2019-11-28 08:16:50 +08:00
|
|
|
* For detailed copyright and license information, please view the
|
|
|
|
* LICENSE file that was distributed with this source code.
|
2018-11-09 18:22:43 +08:00
|
|
|
*/
|
|
|
|
|
2020-03-27 19:22:22 +08:00
|
|
|
namespace Flarum\Tests\integration\api\users;
|
2018-11-09 18:22:43 +08:00
|
|
|
|
2020-03-27 19:22:22 +08:00
|
|
|
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
|
|
|
use Flarum\Tests\integration\TestCase;
|
2018-11-09 18:22:43 +08:00
|
|
|
|
2020-03-27 19:22:22 +08:00
|
|
|
class UpdateTest extends TestCase
|
2018-11-09 18:22:43 +08:00
|
|
|
{
|
2020-03-27 19:22:22 +08:00
|
|
|
use RetrievesAuthorizedUsers;
|
2018-11-09 18:22:43 +08:00
|
|
|
|
2019-01-31 04:15:27 +08:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->prepareDatabase([
|
|
|
|
'users' => [
|
|
|
|
$this->adminUser(),
|
|
|
|
$this->normalUser(),
|
|
|
|
],
|
|
|
|
'groups' => [
|
|
|
|
$this->adminGroup(),
|
|
|
|
$this->memberGroup(),
|
|
|
|
],
|
|
|
|
'group_user' => [
|
|
|
|
['user_id' => 1, 'group_id' => 1],
|
|
|
|
['user_id' => 2, 'group_id' => 3],
|
|
|
|
],
|
|
|
|
'group_permission' => [
|
|
|
|
['permission' => 'viewUserList', 'group_id' => 3],
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
}
|
2018-11-09 18:22:43 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function users_can_see_their_private_information()
|
|
|
|
{
|
2020-03-27 19:22:22 +08:00
|
|
|
$response = $this->send(
|
|
|
|
$this->request('PATCH', '/api/users/2', [
|
|
|
|
'authenticatedAs' => 2,
|
|
|
|
'json' => [],
|
|
|
|
])
|
|
|
|
);
|
2018-11-09 18:22:43 +08:00
|
|
|
|
|
|
|
// Test for successful response and that the email is included in the response
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
2019-01-31 04:15:27 +08:00
|
|
|
$this->assertContains('normal@machine.local', (string) $response->getBody());
|
2018-11-09 18:22:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function users_can_not_see_other_users_private_information()
|
|
|
|
{
|
2020-03-27 19:22:22 +08:00
|
|
|
$response = $this->send(
|
|
|
|
$this->request('PATCH', '/api/users/1', [
|
|
|
|
'authenticatedAs' => 2,
|
|
|
|
'json' => [],
|
|
|
|
])
|
|
|
|
);
|
2018-11-09 18:22:43 +08:00
|
|
|
|
|
|
|
// Make sure sensitive information is not made public
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
2019-01-31 04:15:27 +08:00
|
|
|
$this->assertNotContains('admin@machine.local', (string) $response->getBody());
|
2018-11-09 18:22:43 +08:00
|
|
|
}
|
|
|
|
}
|