InstallerSecurityTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. use function Pest\Laravel\get;
  3. use function Pest\Laravel\post;
  4. it('should block access to installer index page when application is already installed', function () {
  5. // Act and Assert.
  6. get(route('installer.index'))
  7. ->assertRedirect(route('shop.home.index'));
  8. });
  9. it('should block access to env file setup endpoint when application is already installed', function () {
  10. // Act and Assert.
  11. $response = post(route('installer.env_file_setup'), [
  12. 'db_hostname' => 'localhost',
  13. 'db_port' => '3306',
  14. 'db_name' => 'test_db',
  15. 'db_username' => 'root',
  16. 'db_password' => '',
  17. ]);
  18. $response->assertRedirect(route('shop.home.index'));
  19. });
  20. it('should block access to run migration endpoint when application is already installed', function () {
  21. // Act and Assert.
  22. post(route('installer.run_migration'))
  23. ->assertRedirect(route('shop.home.index'));
  24. });
  25. it('should block access to run seeder endpoint when application is already installed', function () {
  26. // Act and Assert.
  27. post(route('installer.run_seeder'), [
  28. 'selectedParameters' => [
  29. 'allowed_locales' => ['en'],
  30. 'allowed_currencies' => ['USD'],
  31. ],
  32. 'allParameters' => [
  33. 'app_locale' => 'en',
  34. 'app_currency' => 'USD',
  35. ],
  36. ])
  37. ->assertRedirect(route('shop.home.index'));
  38. });
  39. it('should block access to download sample endpoint when application is already installed', function () {
  40. // Act and Assert.
  41. get(route('installer.download_sample'))
  42. ->assertRedirect(route('shop.home.index'));
  43. });
  44. it('should block access to admin config setup endpoint when application is already installed', function () {
  45. // Act and Assert.
  46. post(route('installer.admin_config_setup'), [
  47. 'admin' => 'Admin User',
  48. 'email' => 'admin@example.com',
  49. 'password' => 'admin123',
  50. ])
  51. ->assertRedirect(route('shop.home.index'));
  52. });
  53. it('should block access to sample products setup endpoint when application is already installed', function () {
  54. // Act and Assert.
  55. post(route('installer.sample_products_setup'), [
  56. 'selectedLocales' => ['en'],
  57. 'selectedCurrencies' => ['USD'],
  58. ])
  59. ->assertRedirect(route('shop.home.index'));
  60. });
  61. it('should return 403 for ajax request to env file setup endpoint when already installed', function () {
  62. // Act and Assert.
  63. post(route('installer.env_file_setup'), [
  64. 'db_hostname' => 'localhost',
  65. 'db_port' => '3306',
  66. 'db_name' => 'test_db',
  67. 'db_username' => 'root',
  68. 'db_password' => '',
  69. ], [
  70. 'X-Requested-With' => 'XMLHttpRequest',
  71. ])
  72. ->assertStatus(403)
  73. ->assertJson([
  74. 'message' => trans('installer::app.installer.middleware.already-installed'),
  75. ]);
  76. });
  77. it('should return 403 for ajax request to run migration endpoint when already installed', function () {
  78. // Act and Assert.
  79. post(route('installer.run_migration'), [], [
  80. 'X-Requested-With' => 'XMLHttpRequest',
  81. ])
  82. ->assertStatus(403)
  83. ->assertJson([
  84. 'message' => trans('installer::app.installer.middleware.already-installed'),
  85. ]);
  86. });
  87. it('should return 403 for ajax request to run seeder endpoint when already installed', function () {
  88. // Act and Assert.
  89. post(route('installer.run_seeder'), [
  90. 'selectedParameters' => [
  91. 'allowed_locales' => ['en'],
  92. 'allowed_currencies' => ['USD'],
  93. ],
  94. 'allParameters' => [
  95. 'app_locale' => 'en',
  96. 'app_currency' => 'USD',
  97. ],
  98. ], [
  99. 'X-Requested-With' => 'XMLHttpRequest',
  100. ])
  101. ->assertStatus(403)
  102. ->assertJson([
  103. 'message' => trans('installer::app.installer.middleware.already-installed'),
  104. ]);
  105. });
  106. it('should return 403 for ajax request to download sample endpoint when already installed', function () {
  107. // Act and Assert.
  108. get(route('installer.download_sample'), [
  109. 'X-Requested-With' => 'XMLHttpRequest',
  110. ])
  111. ->assertStatus(403)
  112. ->assertJson([
  113. 'message' => trans('installer::app.installer.middleware.already-installed'),
  114. ]);
  115. });
  116. it('should return 403 for ajax request to admin config setup endpoint when already installed', function () {
  117. // Act and Assert.
  118. post(route('installer.admin_config_setup'), [
  119. 'admin' => 'Admin User',
  120. 'email' => 'admin@example.com',
  121. 'password' => 'admin123',
  122. ], [
  123. 'X-Requested-With' => 'XMLHttpRequest',
  124. ])
  125. ->assertStatus(403)
  126. ->assertJson([
  127. 'message' => trans('installer::app.installer.middleware.already-installed'),
  128. ]);
  129. });
  130. it('should return 403 for ajax request to sample products setup endpoint when already installed', function () {
  131. // Act and Assert.
  132. post(route('installer.sample_products_setup'), [
  133. 'selectedLocales' => ['en'],
  134. 'selectedCurrencies' => ['USD'],
  135. ], [
  136. 'X-Requested-With' => 'XMLHttpRequest',
  137. ])
  138. ->assertStatus(403)
  139. ->assertJson([
  140. 'message' => trans('installer::app.installer.middleware.already-installed'),
  141. ]);
  142. });