mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-08-09 13:55:01 +02:00
Update tests & minor fixes
This commit is contained in:
@ -7,6 +7,15 @@ use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Tests\TestCase;
|
||||
use App\Exceptions\InvalidOtpParameterException;
|
||||
use \App\Exceptions\InvalidQrCodeException;
|
||||
use App\Exceptions\InvalidSecretException;
|
||||
use App\Exceptions\DbEncryptionException;
|
||||
use App\Exceptions\InvalidMigrationDataException;
|
||||
use App\Exceptions\UndecipherableException;
|
||||
use App\Exceptions\UnsupportedMigrationException;
|
||||
use App\Exceptions\UnsupportedOtpTypeException;
|
||||
use App\Exceptions\EncryptedMigrationException;
|
||||
|
||||
/**
|
||||
* @covers \App\Exceptions\Handler
|
||||
@ -41,32 +50,35 @@ class HandlerTest extends TestCase
|
||||
/**
|
||||
* Provide Valid data for validation test
|
||||
*/
|
||||
public function provideExceptionsforBadRequest() : array
|
||||
public function provideExceptionsforBadRequest(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'\App\Exceptions\InvalidOtpParameterException',
|
||||
InvalidOtpParameterException::class,
|
||||
],
|
||||
[
|
||||
'\App\Exceptions\InvalidQrCodeException',
|
||||
InvalidQrCodeException::class,
|
||||
],
|
||||
[
|
||||
'\App\Exceptions\InvalidSecretException',
|
||||
InvalidSecretException::class,
|
||||
],
|
||||
[
|
||||
'\App\Exceptions\DbEncryptionException',
|
||||
DbEncryptionException::class,
|
||||
],
|
||||
[
|
||||
'\App\Exceptions\InvalidMigrationDataException',
|
||||
InvalidMigrationDataException::class,
|
||||
],
|
||||
[
|
||||
'\App\Exceptions\UndecipherableException',
|
||||
UndecipherableException::class,
|
||||
],
|
||||
[
|
||||
'\App\Exceptions\UnsupportedMigrationException',
|
||||
UnsupportedMigrationException::class,
|
||||
],
|
||||
[
|
||||
'\App\Exceptions\UnsupportedOtpTypeException',
|
||||
UnsupportedOtpTypeException::class,
|
||||
],
|
||||
[
|
||||
EncryptedMigrationException::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
@ -99,7 +111,7 @@ class HandlerTest extends TestCase
|
||||
/**
|
||||
* Provide Valid data for validation test
|
||||
*/
|
||||
public function provideExceptionsforNotFound() : array
|
||||
public function provideExceptionsforNotFound(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
@ -111,6 +123,32 @@ class HandlerTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function test_authenticationException_returns_unauthorized_json_response()
|
||||
{
|
||||
$request = $this->createMock(Request::class);
|
||||
$instance = new Handler($this->createMock(Container::class));
|
||||
$class = new \ReflectionClass(Handler::class);
|
||||
|
||||
$method = $class->getMethod('render');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$mockException = $this->createMock(\Illuminate\Auth\AuthenticationException::class);
|
||||
$mockException->method('guards')->willReturn(['web-guard']);
|
||||
|
||||
$response = $method->invokeArgs($instance, [$request, $mockException]);
|
||||
|
||||
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||
|
||||
$response = \Illuminate\Testing\TestResponse::fromBaseResponse($response);
|
||||
$response->assertStatus(401)
|
||||
->assertJsonStructure([
|
||||
'message',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
|
Reference in New Issue
Block a user