TwoFAccountUpdateRequestTest.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. namespace Tests\Api\v1\Requests;
  3. use App\Api\v1\Requests\TwoFAccountUpdateRequest;
  4. use Illuminate\Foundation\Testing\WithoutMiddleware;
  5. use Illuminate\Support\Facades\Validator;
  6. use Illuminate\Support\Facades\Auth;
  7. use Tests\TestCase;
  8. class TwoFAccountUpdateRequestTest extends TestCase
  9. {
  10. use WithoutMiddleware;
  11. /**
  12. * @test
  13. */
  14. public function test_user_is_authorized()
  15. {
  16. Auth::shouldReceive('check')
  17. ->once()
  18. ->andReturn(true);
  19. $request = new TwoFAccountUpdateRequest();
  20. $this->assertTrue($request->authorize());
  21. }
  22. /**
  23. * @dataProvider provideValidData
  24. */
  25. public function test_valid_data(array $data) : void
  26. {
  27. $request = new TwoFAccountUpdateRequest();
  28. $validator = Validator::make($data, $request->rules());
  29. $this->assertFalse($validator->fails());
  30. }
  31. /**
  32. * Provide Valid data for validation test
  33. */
  34. public function provideValidData() : array
  35. {
  36. return [
  37. [[
  38. 'service' => 'MyService',
  39. 'account' => 'MyAccount',
  40. 'icon' => 'icon.png',
  41. 'otp_type' => 'totp',
  42. 'secret' => 'A4GRFHZVRBGY7UIW',
  43. 'digits' => 6,
  44. 'algorithm' => 'sha1',
  45. 'period' => 30,
  46. ]],
  47. [[
  48. 'service' => 'MyService',
  49. 'account' => 'MyAccount',
  50. 'icon' => 'icon.png',
  51. 'otp_type' => 'hotp',
  52. 'secret' => 'A4GRFHZVRBGY7UIW',
  53. 'digits' => 8,
  54. 'algorithm' => 'sha1',
  55. 'counter' => 10,
  56. ]],
  57. [[
  58. 'service' => null,
  59. 'account' => 'MyAccount',
  60. 'icon' => null,
  61. 'otp_type' => 'hotp',
  62. 'secret' => 'A4GRFHZVRBGY7UIW',
  63. 'digits' => 10,
  64. 'algorithm' => 'sha1',
  65. 'period' => null,
  66. 'counter' => 15,
  67. ]],
  68. ];
  69. }
  70. /**
  71. * @dataProvider provideInvalidData
  72. */
  73. public function test_invalid_data(array $data) : void
  74. {
  75. $request = new TwoFAccountUpdateRequest();
  76. $validator = Validator::make($data, $request->rules());
  77. $this->assertTrue($validator->fails());
  78. }
  79. /**
  80. * Provide invalid data for validation test
  81. */
  82. public function provideInvalidData() : array
  83. {
  84. return [
  85. [[
  86. 'service' => null,
  87. 'account' => 'My:Account',
  88. 'icon' => null,
  89. 'otp_type' => 'hotp',
  90. 'secret' => 'A4GRFHZVRBGY7UIW',
  91. 'digits' => 6,
  92. 'algorithm' => 'sha1',
  93. 'period' => null,
  94. 'counter' => 15,
  95. ]],
  96. [[
  97. 'service' => 'My:Service',
  98. 'account' => 'MyAccount',
  99. 'icon' => null,
  100. 'otp_type' => 'hotp',
  101. 'secret' => 'A4GRFHZVRBGY7UIW',
  102. 'digits' => 6,
  103. 'algorithm' => 'sha1',
  104. 'period' => null,
  105. 'counter' => 15,
  106. ]],
  107. [[
  108. 'service' => null,
  109. 'account' => 'My:Account',
  110. 'icon' => null,
  111. 'otp_type' => 'Xotp',
  112. 'secret' => 'A4GRFHZVRBGY7UIW',
  113. 'digits' => 6,
  114. 'algorithm' => 'sha1',
  115. 'period' => null,
  116. 'counter' => 15,
  117. ]],
  118. [[
  119. 'service' => null,
  120. 'account' => 'MyAccount',
  121. 'icon' => null,
  122. 'otp_type' => 'hotp',
  123. 'secret' => 'notaBase32String',
  124. 'digits' => 6,
  125. 'algorithm' => 'sha1',
  126. 'period' => null,
  127. 'counter' => 15,
  128. ]],
  129. [[
  130. 'service' => 'MyService',
  131. 'account' => 'MyAccount',
  132. 'icon' => null,
  133. 'otp_type' => 'totp',
  134. 'secret' => 'A4GRFHZVRBGY7UIW',
  135. 'digits' => 4,
  136. 'algorithm' => 'sha1',
  137. 'period' => null,
  138. 'counter' => 15,
  139. ]],
  140. [[
  141. 'service' => 'MyService',
  142. 'account' => 'MyAccount',
  143. 'icon' => null,
  144. 'otp_type' => 'totp',
  145. 'secret' => 'A4GRFHZVRBGY7UIW',
  146. 'digits' => 11,
  147. 'algorithm' => 'sha1',
  148. 'period' => null,
  149. 'counter' => 15,
  150. ]],
  151. [[
  152. 'service' => 'MyService',
  153. 'account' => 'MyAccount',
  154. 'icon' => null,
  155. 'otp_type' => 'totp',
  156. 'secret' => 'A4GRFHZVRBGY7UIW',
  157. 'digits' => 6,
  158. 'algorithm' => 'Xsha1',
  159. 'period' => null,
  160. 'counter' => 15,
  161. ]],
  162. [[
  163. 'service' => 'MyService',
  164. 'account' => 'MyAccount',
  165. 'icon' => null,
  166. 'otp_type' => 'totp',
  167. 'secret' => 'A4GRFHZVRBGY7UIW',
  168. 'digits' => 6,
  169. 'algorithm' => 'sha1',
  170. 'period' => 0,
  171. 'counter' => 15,
  172. ]],
  173. [[
  174. 'service' => 'MyService',
  175. 'account' => 'MyAccount',
  176. 'icon' => null,
  177. 'otp_type' => 'totp',
  178. 'secret' => 'A4GRFHZVRBGY7UIW',
  179. 'digits' => 4,
  180. 'algorithm' => 'sha1',
  181. 'period' => null,
  182. 'counter' => -1,
  183. ]],
  184. [[
  185. 'service' => 'MyService',
  186. 'account' => 'MyAccount',
  187. 'icon' => null,
  188. 'otp_type' => 'totp',
  189. 'secret' => 'A4GRFHZVRBGY7UIW',
  190. 'digits' => null,
  191. 'algorithm' => 'sha1',
  192. 'period' => null,
  193. 'counter' => 15,
  194. ]],
  195. [[
  196. 'service' => 'MyService',
  197. 'account' => 'MyAccount',
  198. 'icon' => null,
  199. 'otp_type' => 'totp',
  200. 'secret' => 'A4GRFHZVRBGY7UIW',
  201. 'digits' => 6,
  202. 'algorithm' => null,
  203. 'period' => null,
  204. 'counter' => 15,
  205. ]],
  206. ];
  207. }
  208. }