TwoFAccountUriRequestTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace Tests\Api\v1\Requests;
  3. use App\Api\v1\Requests\TwoFAccountUriRequest;
  4. use Illuminate\Foundation\Testing\WithoutMiddleware;
  5. use Illuminate\Support\Facades\Auth;
  6. use Illuminate\Support\Facades\Validator;
  7. use Tests\TestCase;
  8. /**
  9. * @covers \App\Api\v1\Requests\TwoFAccountUriRequest
  10. */
  11. class TwoFAccountUriRequestTest extends TestCase
  12. {
  13. use WithoutMiddleware;
  14. /**
  15. * @test
  16. */
  17. public function test_user_is_authorized()
  18. {
  19. Auth::shouldReceive('check')
  20. ->once()
  21. ->andReturn(true);
  22. $request = new TwoFAccountUriRequest();
  23. $this->assertTrue($request->authorize());
  24. }
  25. /**
  26. * @dataProvider provideValidData
  27. */
  28. public function test_valid_data(array $data): void
  29. {
  30. $request = new TwoFAccountUriRequest();
  31. $validator = Validator::make($data, $request->rules());
  32. $this->assertFalse($validator->fails());
  33. }
  34. /**
  35. * Provide Valid data for validation test
  36. */
  37. public function provideValidData(): array
  38. {
  39. return [
  40. [[
  41. 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHZVRBGY7UIW&issuer=test',
  42. ]],
  43. [[
  44. 'uri' => 'otpauth://hotp/test@test.com?secret=A4GRFHZVRBGY7UIW&issuer=test',
  45. ]],
  46. [[
  47. 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHZVRBGY7UIW&issuer=test',
  48. 'custom_otp' => 'steamtotp',
  49. ]],
  50. ];
  51. }
  52. /**
  53. * @dataProvider provideInvalidData
  54. */
  55. public function test_invalid_data(array $data): void
  56. {
  57. $request = new TwoFAccountUriRequest();
  58. $validator = Validator::make($data, $request->rules());
  59. $this->assertTrue($validator->fails());
  60. }
  61. /**
  62. * Provide invalid data for validation test
  63. */
  64. public function provideInvalidData(): array
  65. {
  66. return [
  67. [[
  68. 'uri' => null, // required
  69. ]],
  70. [[
  71. 'uri' => '', // required
  72. ]],
  73. [[
  74. 'uri' => true, // string
  75. ]],
  76. [[
  77. 'uri' => 8, // string
  78. ]],
  79. [[
  80. 'uri' => 'otpXauth://totp/test@test.com?secret=A4GRFHZVRBGY7UIW&issuer=test', // regex
  81. ]],
  82. [[
  83. 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHZVRBGY7UIW&issuer=test',
  84. 'custom_otp' => 'notSteam', // not in
  85. ]],
  86. [[
  87. 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHZVRBGY7UIW&issuer=test',
  88. 'custom_otp' => 0, // string
  89. ]],
  90. [[
  91. 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHZVRBGY7UIW&issuer=test',
  92. 'custom_otp' => true, // string
  93. ]],
  94. ];
  95. }
  96. }