AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

SecurityTest.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace Tests\Feature\Settings;
  3. use App\Models\User;
  4. use Illuminate\Foundation\Testing\RefreshDatabase;
  5. use Illuminate\Support\Facades\Hash;
  6. use Inertia\Testing\AssertableInertia as Assert;
  7. use Laravel\Fortify\Features;
  8. use Tests\TestCase;
  9. class SecurityTest extends TestCase
  10. {
  11. use RefreshDatabase;
  12. public function test_security_page_is_displayed()
  13. {
  14. $this->skipUnlessFortifyHas(Features::twoFactorAuthentication());
  15. Features::twoFactorAuthentication([
  16. 'confirm' => true,
  17. 'confirmPassword' => true,
  18. ]);
  19. $user = User::factory()->create();
  20. $this->actingAs($user)
  21. ->withSession(['auth.password_confirmed_at' => time()])
  22. ->get(route('security.edit'))
  23. ->assertInertia(fn (Assert $page) => $page
  24. ->component('settings/security')
  25. ->where('canManageTwoFactor', true)
  26. ->where('twoFactorEnabled', false),
  27. );
  28. }
  29. public function test_security_page_requires_password_confirmation_when_enabled()
  30. {
  31. $this->skipUnlessFortifyHas(Features::twoFactorAuthentication());
  32. $user = User::factory()->create();
  33. Features::twoFactorAuthentication([
  34. 'confirm' => true,
  35. 'confirmPassword' => true,
  36. ]);
  37. $response = $this->actingAs($user)
  38. ->get(route('security.edit'));
  39. $response->assertRedirect(route('password.confirm'));
  40. }
  41. public function test_security_page_renders_without_two_factor_when_feature_is_disabled()
  42. {
  43. $this->skipUnlessFortifyHas(Features::twoFactorAuthentication());
  44. config(['fortify.features' => []]);
  45. $user = User::factory()->create();
  46. $this->actingAs($user)
  47. ->withSession(['auth.password_confirmed_at' => time()])
  48. ->get(route('security.edit'))
  49. ->assertOk()
  50. ->assertInertia(fn (Assert $page) => $page
  51. ->component('settings/security')
  52. ->where('canManageTwoFactor', false)
  53. ->missing('twoFactorEnabled')
  54. ->missing('requiresConfirmation'),
  55. );
  56. }
  57. public function test_password_can_be_updated()
  58. {
  59. $user = User::factory()->create();
  60. $response = $this
  61. ->actingAs($user)
  62. ->from(route('security.edit'))
  63. ->put(route('user-password.update'), [
  64. 'current_password' => 'password',
  65. 'password' => 'new-password',
  66. 'password_confirmation' => 'new-password',
  67. ]);
  68. $response
  69. ->assertSessionHasNoErrors()
  70. ->assertRedirect(route('security.edit'));
  71. $this->assertTrue(Hash::check('new-password', $user->refresh()->password));
  72. }
  73. public function test_correct_password_must_be_provided_to_update_password()
  74. {
  75. $user = User::factory()->create();
  76. $response = $this
  77. ->actingAs($user)
  78. ->from(route('security.edit'))
  79. ->put(route('user-password.update'), [
  80. 'current_password' => 'wrong-password',
  81. 'password' => 'new-password',
  82. 'password_confirmation' => 'new-password',
  83. ]);
  84. $response
  85. ->assertSessionHasErrors('current_password')
  86. ->assertRedirect(route('security.edit'));
  87. }
  88. }