mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-08-14 07:48:37 +02:00
Fix and complete tests
This commit is contained in:
115
tests/Feature/Http/Auth/WebAuthnRecoveryControllerTest.php
Normal file
115
tests/Feature/Http/Auth/WebAuthnRecoveryControllerTest.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Auth;
|
||||
|
||||
use App\Models\User;
|
||||
use Tests\FeatureTestCase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
|
||||
class WebAuthnRecoveryControllerTest extends FeatureTestCase
|
||||
{
|
||||
/**
|
||||
* @var \App\Models\User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->user = User::factory()->create();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function test_options_returns_success()
|
||||
{
|
||||
$token = '$2y$10$hgGTVVTRLsSYSlAHpyydBu6m4ZuRheBqTTUfRE/aG89DaqEyo.HPu';
|
||||
Date::setTestNow($now = Date::create(2020, 01, 01, 16, 30));
|
||||
|
||||
DB::table('web_authn_recoveries')->insert([
|
||||
'email' => $this->user->email,
|
||||
'token' => $token,
|
||||
'created_at' => $now->toDateTimeString(),
|
||||
]);
|
||||
|
||||
$response = $this->json('POST', '/webauthn/recover/options', [
|
||||
'token' => 'test_token',
|
||||
'email' => $this->user->email,
|
||||
])
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function test_options_with_invalid_token_returns_error()
|
||||
{
|
||||
$response = $this->json('POST', '/webauthn/recover/options', [
|
||||
'token' => 'myToken',
|
||||
'email' => $this->user->email,
|
||||
])
|
||||
->assertStatus(401);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function test_options_without_inputs_returns_validation_errors()
|
||||
{
|
||||
$response = $this->json('POST', '/webauthn/recover/options', [
|
||||
'token' => '',
|
||||
'email' => '',
|
||||
]);
|
||||
|
||||
$response->assertStatus(422)
|
||||
->assertJsonValidationErrors(['token'])
|
||||
->assertJsonValidationErrors(['email']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
// public function test_recover_returns_success()
|
||||
// {
|
||||
// $token = '$2y$10$hgGTVVTRLsSYSlAHpyydBu6m4ZuRheBqTTUfRE/aG89DaqEyo.HPu';
|
||||
// Date::setTestNow($now = Date::create(2020, 01, 01, 16, 30));
|
||||
|
||||
// DB::table('web_authn_recoveries')->insert([
|
||||
// 'email' => $this->user->email,
|
||||
// 'token' => $token,
|
||||
// 'created_at' => $now->toDateTimeString(),
|
||||
// ]);
|
||||
|
||||
// $response = $this->json('POST', '/webauthn/recover', [], [
|
||||
// 'token' => $token,
|
||||
// 'email' => $this->user->email,
|
||||
// ])
|
||||
// ->assertStatus(200);
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function test_recover_with_invalid_token_returns_validation_error()
|
||||
{
|
||||
$response = $this->json('POST', '/webauthn/recover', [], [
|
||||
'token' => 'toekn',
|
||||
'email' => $this->user->email,
|
||||
])
|
||||
->assertStatus(422)
|
||||
->assertJsonValidationErrors(['email']);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user