ResetDemoTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace Tests\Feature\Console;
  3. use Illuminate\Support\Facades\Artisan;
  4. use Illuminate\Support\Facades\Config;
  5. use Tests\FeatureTestCase;
  6. class ResetDemoTest extends FeatureTestCase
  7. {
  8. /**
  9. * @test
  10. */
  11. public function test_reset_demo_without_demo_mode_succeeded()
  12. {
  13. $this->artisan('2fauth:reset-demo')
  14. ->expectsOutput('2fauth:reset-demo can only run when isDemoApp option is On')
  15. ->assertSuccessful();
  16. }
  17. /**
  18. * @test
  19. */
  20. public function test_reset_demo_succeeded()
  21. {
  22. Artisan::call('passport:install', [
  23. '--verbose' => 2,
  24. '--no-interaction' => 1
  25. ]);
  26. Config::set('2fauth.config.isDemoApp', true);
  27. $this->artisan('2fauth:reset-demo')
  28. ->expectsOutput('This will reset the app in order to run a clean and fresh demo.')
  29. ->expectsQuestion('To prevent any mistake please type the word "demo" to go on', 'demo')
  30. ->assertSuccessful();
  31. $this->assertDatabaseCount('twofaccounts', 9);
  32. $this->assertDatabaseHas('twofaccounts', [
  33. 'otp_type' => 'totp',
  34. 'account' => 'johndoe@facebook.com',
  35. 'service' => 'Facebook',
  36. 'secret' => 'A4GRFTVVRBGY7UIW',
  37. 'algorithm' => 'sha1',
  38. 'digits' => 6,
  39. 'period' => 30,
  40. 'icon' => 'facebook.png',
  41. 'legacy_uri' => 'otpauth://totp/Facebook:johndoe@facebook.com?secret=A4GRFTVVRBGY7UIW',
  42. ]);
  43. $this->assertDatabaseHas('twofaccounts', [
  44. 'otp_type' => 'totp',
  45. 'service' => 'Twitter',
  46. 'account' => '@john',
  47. 'secret' => 'A2GRFTVVRBGY7UIW',
  48. 'algorithm' => 'sha1',
  49. 'digits' => 6,
  50. 'period' => 30,
  51. 'icon' => 'twitter.png',
  52. 'legacy_uri' => 'otpauth://totp/Twitter:@john?secret=A2GRFTVVRBGY7UIW',
  53. ]);
  54. $this->assertDatabaseHas('twofaccounts', [
  55. 'otp_type' => 'totp',
  56. 'service' => 'Instagram',
  57. 'account' => '@johndoe',
  58. 'secret' => 'A6GRFTVVRBGY7UIW',
  59. 'algorithm' => 'sha1',
  60. 'digits' => 6,
  61. 'period' => 30,
  62. 'icon' => 'instagram.png',
  63. 'legacy_uri' => 'otpauth://totp/Instagram:@johndoe?secret=A6GRFTVVRBGY7UIW',
  64. ]);
  65. $this->assertDatabaseHas('twofaccounts', [
  66. 'otp_type' => 'totp',
  67. 'service' => 'LinkedIn',
  68. 'account' => '@johndoe',
  69. 'secret' => 'A7GRFTVVRBGY7UIW',
  70. 'algorithm' => 'sha1',
  71. 'digits' => 6,
  72. 'period' => 30,
  73. 'icon' => 'linkedin.png',
  74. 'legacy_uri' => 'otpauth://totp/LinkedIn:@johndoe?secret=A7GRFTVVRBGY7UIW',
  75. ]);
  76. $this->assertDatabaseHas('twofaccounts', [
  77. 'otp_type' => 'totp',
  78. 'account' => 'johndoe',
  79. 'service' => 'Amazon',
  80. 'secret' => 'A7GRFTVVRBGY7UIW',
  81. 'algorithm' => 'sha1',
  82. 'digits' => 6,
  83. 'period' => 30,
  84. 'icon' => 'amazon.png',
  85. 'legacy_uri' => 'otpauth://totp/Amazon:johndoe?secret=A7GRFTVVRBGY7UIW',
  86. ]);
  87. $this->assertDatabaseHas('twofaccounts', [
  88. 'otp_type' => 'totp',
  89. 'account' => 'john.doe@icloud.com',
  90. 'service' => 'Apple',
  91. 'secret' => 'A2GRFTVVRBGY7UIW',
  92. 'algorithm' => 'sha1',
  93. 'digits' => 6,
  94. 'period' => 30,
  95. 'icon' => 'apple.png',
  96. 'legacy_uri' => 'otpauth://totp/Apple:john.doe@icloud.com?secret=A2GRFTVVRBGY7UIW',
  97. ]);
  98. $this->assertDatabaseHas('twofaccounts', [
  99. 'otp_type' => 'totp',
  100. 'account' => 'john.doe',
  101. 'service' => 'Dropbox',
  102. 'secret' => 'A3GRFTVVRBGY7UIW',
  103. 'algorithm' => 'sha1',
  104. 'digits' => 6,
  105. 'period' => 30,
  106. 'icon' => 'dropbox.png',
  107. 'legacy_uri' => 'otpauth://totp/Dropbox:john.doe?secret=A3GRFTVVRBGY7UIW',
  108. ]);
  109. $this->assertDatabaseHas('twofaccounts', [
  110. 'otp_type' => 'totp',
  111. 'account' => '@john',
  112. 'service' => 'Github',
  113. 'secret' => 'A2GRFTVVRBGY7UIW',
  114. 'algorithm' => 'sha1',
  115. 'digits' => 6,
  116. 'period' => 30,
  117. 'icon' => 'github.png',
  118. 'legacy_uri' => 'otpauth://totp/Github:@john?secret=A2GRFTVVRBGY7UIW',
  119. ]);
  120. $this->assertDatabaseHas('twofaccounts', [
  121. 'otp_type' => 'totp',
  122. 'service' => 'Google',
  123. 'account' => 'john.doe@gmail.com',
  124. 'secret' => 'A5GRFTVVRBGY7UIW',
  125. 'algorithm' => 'sha1',
  126. 'digits' => 6,
  127. 'period' => 30,
  128. 'icon' => 'google.png',
  129. 'legacy_uri' => 'otpauth://totp/Google:john.doe@gmail.com?secret=A5GRFTVVRBGY7UIW',
  130. ]);
  131. }
  132. /**
  133. * @test
  134. */
  135. public function test_reset_demo_with_invalid_confirmation_succeeded()
  136. {
  137. Config::set('2fauth.config.isDemoApp', true);
  138. $this->artisan('2fauth:reset-demo')
  139. ->expectsQuestion('To prevent any mistake please type the word "demo" to go on', 'null')
  140. ->expectsOutput('Bad confirmation word, nothing appened')
  141. ->assertSuccessful();
  142. }
  143. /**
  144. * @test
  145. */
  146. public function test_reset_demo_with_no_confirm_option_succeeded()
  147. {
  148. Config::set('2fauth.config.isDemoApp', true);
  149. $this->artisan('2fauth:reset-demo', [
  150. '--no-confirm' => true,
  151. ])
  152. ->assertSuccessful();
  153. }
  154. }