WebauthnAssertedRequestTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Tests\Feature\Http\Requests;
  3. use App\Http\Requests\WebauthnAssertedRequest;
  4. use Illuminate\Foundation\Testing\WithoutMiddleware;
  5. use Illuminate\Support\Facades\Validator;
  6. use PHPUnit\Framework\Attributes\CoversClass;
  7. use PHPUnit\Framework\Attributes\DataProvider;
  8. use PHPUnit\Framework\Attributes\Test;
  9. use Tests\TestCase;
  10. /**
  11. * WebauthnAssertedRequestTest test class
  12. */
  13. #[CoversClass(WebauthnAssertedRequest::class)]
  14. class WebauthnAssertedRequestTest extends TestCase
  15. {
  16. use WithoutMiddleware;
  17. #[Test]
  18. #[DataProvider('provideValidData')]
  19. public function test_valid_data(array $data) : void
  20. {
  21. $request = new WebauthnAssertedRequest;
  22. $validator = Validator::make($data, $request->rules());
  23. $this->assertFalse($validator->fails());
  24. }
  25. /**
  26. * Provide Valid data for validation test
  27. */
  28. public static function provideValidData() : array
  29. {
  30. return [
  31. [[
  32. 'id' => 'string',
  33. 'rawId' => 'string',
  34. 'type' => 'string',
  35. 'response' => [
  36. 'clientDataJSON' => 'string',
  37. 'authenticatorData' => 'string',
  38. 'signature' => 'string',
  39. 'userHandle' => null,
  40. ],
  41. 'email' => 'valid@email.com',
  42. ]],
  43. ];
  44. }
  45. #[Test]
  46. #[DataProvider('provideInvalidData')]
  47. public function test_invalid_data(array $data) : void
  48. {
  49. $request = new WebauthnAssertedRequest;
  50. $validator = Validator::make($data, $request->rules());
  51. $this->assertTrue($validator->fails());
  52. }
  53. /**
  54. * Provide invalid data for validation test
  55. */
  56. public static function provideInvalidData() : array
  57. {
  58. return [
  59. [[
  60. 'email' => '', // required
  61. ]],
  62. [[
  63. 'email' => true, // email
  64. ]],
  65. [[
  66. 'email' => 0, // email
  67. ]],
  68. [[
  69. 'email' => 'sdfsdf@', // email
  70. ]],
  71. ];
  72. }
  73. }