Files
netslim-core/tests/Identity/PasswordRequestHandlingTest.php
2026-03-20 22:13:41 +01:00

86 lines
3.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Identity;
use Netig\Netslim\Identity\UI\Http\Request\ChangePasswordRequest;
use Netig\Netslim\Identity\UI\Http\Request\CreateUserRequest;
use Netig\Netslim\Identity\UI\Http\Request\LoginRequest;
use Netig\Netslim\Identity\UI\Http\Request\ResetPasswordRequest;
use PHPUnit\Framework\TestCase;
use Slim\Psr7\Factory\ServerRequestFactory;
final class PasswordRequestHandlingTest extends TestCase
{
public function testLoginRequestPreservesPasswordWhitespace(): void
{
$request = (new ServerRequestFactory())
->createServerRequest('POST', '/login')
->withParsedBody([
'username' => ' alice ',
'password' => ' secret ',
]);
$payload = LoginRequest::fromRequest($request);
self::assertSame('alice', $payload->username);
self::assertSame(' secret ', $payload->password);
}
public function testChangePasswordRequestPreservesPasswordWhitespace(): void
{
$request = (new ServerRequestFactory())
->createServerRequest('POST', '/account/password')
->withParsedBody([
'current_password' => ' current ',
'new_password' => ' nextpass ',
'new_password_confirm' => ' nextpass ',
]);
$payload = ChangePasswordRequest::fromRequest($request);
self::assertSame(' current ', $payload->currentPassword);
self::assertSame(' nextpass ', $payload->newPassword);
self::assertSame(' nextpass ', $payload->newPasswordConfirm);
}
public function testResetPasswordRequestPreservesPasswordWhitespace(): void
{
$request = (new ServerRequestFactory())
->createServerRequest('POST', '/password/reset')
->withParsedBody([
'token' => ' token ',
'new_password' => ' nextpass ',
'new_password_confirm' => ' nextpass ',
]);
$payload = ResetPasswordRequest::fromRequest($request);
self::assertSame('token', $payload->token);
self::assertSame(' nextpass ', $payload->newPassword);
self::assertSame(' nextpass ', $payload->newPasswordConfirm);
}
public function testCreateUserRequestPreservesPasswordWhitespace(): void
{
$request = (new ServerRequestFactory())
->createServerRequest('POST', '/admin/users')
->withParsedBody([
'username' => ' Alice ',
'email' => ' alice@example.com ',
'password' => ' secret123 ',
'password_confirm' => ' secret123 ',
'role' => 'editor',
]);
$payload = CreateUserRequest::fromRequest($request, ['user', 'editor']);
self::assertSame('Alice', $payload->username);
self::assertSame('alice@example.com', $payload->email);
self::assertSame(' secret123 ', $payload->password);
self::assertSame(' secret123 ', $payload->passwordConfirm);
self::assertSame('editor', $payload->role);
}
}