ResetDemoTest.php 5.6 KB

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