Refactoring: Throw HttpAuthExpired on csrf token mismatch
parent
9788c5095a
commit
55beca95cd
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Http\Exceptions;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class HttpAuthExpired extends HttpException
|
||||
{
|
||||
/**
|
||||
* @param string $message
|
||||
* @param array $headers
|
||||
* @param int $code
|
||||
* @param Throwable|null $previous
|
||||
*/
|
||||
public function __construct(
|
||||
string $message = 'Authentication Expired',
|
||||
array $headers = [],
|
||||
int $code = 0,
|
||||
Throwable $previous = null
|
||||
) {
|
||||
// The 419 code is used as "Page Expired" to differentiate from a 401 (not authorized)
|
||||
parent::__construct(419, $message, $headers, $code, $previous);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Test\Unit\Http\Exceptions;
|
||||
|
||||
use Engelsystem\Http\Exceptions\HttpAuthExpired;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class HttpAuthExpiredTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Engelsystem\Http\Exceptions\HttpAuthExpired::__construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$exception = new HttpAuthExpired();
|
||||
$this->assertEquals(419, $exception->getStatusCode());
|
||||
$this->assertEquals('Authentication Expired', $exception->getMessage());
|
||||
|
||||
$exception = new HttpAuthExpired('Oops!');
|
||||
$this->assertEquals('Oops!', $exception->getMessage());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue