Skip to content

Commit

Permalink
[5.x] Prevent user registration form saving password_confirmation (#…
Browse files Browse the repository at this point in the history
…10228)

Co-authored-by: Duncan McClean <[email protected]>
  • Loading branch information
ryanmitchell and duncanmcclean authored May 30, 2024
1 parent 725d9cf commit 0b80430
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Http/Requests/UserRegisterRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function processedValues()
{
return $this->blueprintFields->process()->values()
->only(array_keys($this->submittedValues))
->except(['email', 'groups', 'roles', 'super']);
->except(['email', 'groups', 'roles', 'super', 'password_confirmation']);
}

public function validator()
Expand Down
31 changes: 31 additions & 0 deletions tests/Tags/User/RegisterFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use Statamic\Facades\Blueprint;
use Statamic\Facades\Parse;
use Statamic\Facades\Role;
use Statamic\Facades\User;
use Statamic\Facades\UserGroup;
use Statamic\Statamic;
use Tests\NormalizesHtml;
use Tests\PreventSavingStacheItemsToDisk;
Expand Down Expand Up @@ -339,6 +341,35 @@ public function it_will_use_redirect_query_param_off_url()
$this->assertStringContainsString($expectedErrorRedirect, $output);
}

/** @test */
public function it_ensures_some_fields_arent_saved()
{
UserGroup::make('client')->title('Client')->save();
Role::make('admin')->title('Admin')->save();

$this->assertNull(User::findByEmail('[email protected]'));
$this->assertFalse(auth()->check());

$this
->post('/!/auth/register', [
'email' => '[email protected]',
'password' => 'chewbacca',
'password_confirmation' => 'chewbacca',
'groups' => ['client'],
'roles' => ['admin'],
'super' => true,
])
->assertSessionHasNoErrors()
->assertLocation('/');

$user = User::findByEmail('[email protected]');

$this->assertEquals($user->groups()->count(), 0);
$this->assertEquals($user->roles()->count(), 0);
$this->assertNull($user->get('super'));
$this->assertNull($user->get('password_confirmation'));
}

private function useCustomBlueprint()
{
$blueprint = Blueprint::make()->setContents([
Expand Down

0 comments on commit 0b80430

Please sign in to comment.