2FAuth/tests/Feature/Http/Requests/WebauthnAssertedRequestTest.php

83 lines
2.1 KiB
PHP
Raw Normal View History

2023-03-18 17:33:43 +01:00
<?php
namespace Tests\Feature\Http\Requests;
use App\Http\Requests\WebauthnAssertedRequest;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Support\Facades\Validator;
2023-08-01 11:28:27 +02:00
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
2023-03-18 17:33:43 +01:00
use Tests\TestCase;
/**
2023-08-01 11:28:27 +02:00
* WebauthnAssertedRequestTest test class
2023-03-18 17:33:43 +01:00
*/
2023-08-01 11:28:27 +02:00
#[CoversClass(WebauthnAssertedRequest::class)]
2023-03-18 17:33:43 +01:00
class WebauthnAssertedRequestTest extends TestCase
{
use WithoutMiddleware;
#[Test]
2023-08-01 11:28:27 +02:00
#[DataProvider('provideValidData')]
2023-03-18 17:33:43 +01:00
public function test_valid_data(array $data) : void
{
2024-09-26 23:50:01 +02:00
$request = new WebauthnAssertedRequest;
2023-03-18 17:33:43 +01:00
$validator = Validator::make($data, $request->rules());
$this->assertFalse($validator->fails());
}
/**
* Provide Valid data for validation test
*/
2023-08-01 11:28:27 +02:00
public static function provideValidData() : array
2023-03-18 17:33:43 +01:00
{
return [
[[
'id' => 'string',
'rawId' => 'string',
'type' => 'string',
'response' => [
'clientDataJSON' => 'string',
'authenticatorData' => 'string',
'signature' => 'string',
'userHandle' => null,
],
'email' => 'valid@email.com',
]],
];
}
#[Test]
2023-08-01 11:28:27 +02:00
#[DataProvider('provideInvalidData')]
2023-03-18 17:33:43 +01:00
public function test_invalid_data(array $data) : void
{
2024-09-26 23:50:01 +02:00
$request = new WebauthnAssertedRequest;
2023-03-18 17:33:43 +01:00
$validator = Validator::make($data, $request->rules());
$this->assertTrue($validator->fails());
}
/**
* Provide invalid data for validation test
*/
2023-08-01 11:28:27 +02:00
public static function provideInvalidData() : array
2023-03-18 17:33:43 +01:00
{
return [
[[
'email' => '', // required
]],
[[
'email' => true, // email
]],
[[
'email' => 0, // email
]],
[[
'email' => 'sdfsdf@', // email
]],
];
}
}