mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-22 06:38:26 +08:00
Users: Changed name validation to min:1 instead of 2
Some checks failed
lint-php / build (push) Has been cancelled
test-migrations / build (8.1) (push) Has been cancelled
test-migrations / build (8.2) (push) Has been cancelled
test-migrations / build (8.3) (push) Has been cancelled
test-php / build (8.1) (push) Has been cancelled
test-php / build (8.2) (push) Has been cancelled
analyse-php / build (push) Has been cancelled
test-php / build (8.3) (push) Has been cancelled
Some checks failed
lint-php / build (push) Has been cancelled
test-migrations / build (8.1) (push) Has been cancelled
test-migrations / build (8.2) (push) Has been cancelled
test-migrations / build (8.3) (push) Has been cancelled
test-php / build (8.1) (push) Has been cancelled
test-php / build (8.2) (push) Has been cancelled
analyse-php / build (push) Has been cancelled
test-php / build (8.3) (push) Has been cancelled
Would cause scenarios where users could be created with 1 char, but then fail to update due to validation differences. Added test to cover. For #5263
This commit is contained in:
parent
4dc75bad05
commit
6f1c54d018
|
@ -37,7 +37,7 @@ class UserApiController extends ApiController
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'create' => [
|
'create' => [
|
||||||
'name' => ['required', 'string', 'min:2', 'max:100'],
|
'name' => ['required', 'string', 'min:1', 'max:100'],
|
||||||
'email' => [
|
'email' => [
|
||||||
'required', 'string', 'email', 'min:2', new Unique('users', 'email'),
|
'required', 'string', 'email', 'min:2', new Unique('users', 'email'),
|
||||||
],
|
],
|
||||||
|
@ -49,7 +49,7 @@ class UserApiController extends ApiController
|
||||||
'send_invite' => ['boolean'],
|
'send_invite' => ['boolean'],
|
||||||
],
|
],
|
||||||
'update' => [
|
'update' => [
|
||||||
'name' => ['string', 'min:2', 'max:100'],
|
'name' => ['string', 'min:1', 'max:100'],
|
||||||
'email' => [
|
'email' => [
|
||||||
'string',
|
'string',
|
||||||
'email',
|
'email',
|
||||||
|
|
|
@ -144,7 +144,7 @@ class UserController extends Controller
|
||||||
$this->checkPermission('users-manage');
|
$this->checkPermission('users-manage');
|
||||||
|
|
||||||
$validated = $this->validate($request, [
|
$validated = $this->validate($request, [
|
||||||
'name' => ['min:2', 'max:100'],
|
'name' => ['min:1', 'max:100'],
|
||||||
'email' => ['min:2', 'email', 'unique:users,email,' . $id],
|
'email' => ['min:2', 'email', 'unique:users,email,' . $id],
|
||||||
'password' => ['required_with:password_confirm', Password::default()],
|
'password' => ['required_with:password_confirm', Password::default()],
|
||||||
'password-confirm' => ['same:password', 'required_with:password'],
|
'password-confirm' => ['same:password', 'required_with:password'],
|
||||||
|
|
|
@ -11,7 +11,6 @@ use BookStack\Users\Models\User;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Mockery\MockInterface;
|
use Mockery\MockInterface;
|
||||||
use RuntimeException;
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class UserManagementTest extends TestCase
|
class UserManagementTest extends TestCase
|
||||||
|
@ -86,6 +85,16 @@ class UserManagementTest extends TestCase
|
||||||
$this->assertTrue(Hash::check('newpassword', $userPassword));
|
$this->assertTrue(Hash::check('newpassword', $userPassword));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_user_can_be_updated_with_single_char_name()
|
||||||
|
{
|
||||||
|
$user = $this->users->viewer();
|
||||||
|
$this->asAdmin()->put("/settings/users/{$user->id}", [
|
||||||
|
'name' => 'b'
|
||||||
|
])->assertRedirect('/settings/users');
|
||||||
|
|
||||||
|
$this->assertEquals('b', $user->refresh()->name);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_user_cannot_be_deleted_if_last_admin()
|
public function test_user_cannot_be_deleted_if_last_admin()
|
||||||
{
|
{
|
||||||
$adminRole = Role::getRole('admin');
|
$adminRole = Role::getRole('admin');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user