Merge pull request #14912 from bryanlopezinc/addIsWritableTest

Add storage path permissions test
This commit is contained in:
snipe 2024-06-20 13:38:56 +01:00 committed by GitHub
commit 6dfedac7a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 49 additions and 11 deletions

View file

@ -25,6 +25,7 @@ use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\URL; use Illuminate\Support\Facades\URL;
@ -106,17 +107,7 @@ class SettingsController extends Controller
$start_settings['owner_is_admin'] = false; $start_settings['owner_is_admin'] = false;
} }
if ((is_writable(storage_path())) $start_settings['writable'] = $this->storagePathIsWritable();
&& (is_writable(storage_path().'/framework'))
&& (is_writable(storage_path().'/framework/cache'))
&& (is_writable(storage_path().'/framework/sessions'))
&& (is_writable(storage_path().'/framework/views'))
&& (is_writable(storage_path().'/logs'))
) {
$start_settings['writable'] = true;
} else {
$start_settings['writable'] = false;
}
$start_settings['gd'] = extension_loaded('gd'); $start_settings['gd'] = extension_loaded('gd');
@ -145,6 +136,19 @@ class SettingsController extends Controller
} }
} }
/**
* Determine if the app storage path is writable.
*/
protected function storagePathIsWritable(): bool
{
return File::isWritable(storage_path()) &&
File::isWritable(storage_path('framework')) &&
File::isWritable(storage_path('framework/cache')) &&
File::isWritable(storage_path('framework/sessions')) &&
File::isWritable(storage_path('framework/views')) &&
File::isWritable(storage_path('logs'));
}
/** /**
* Save the first admin user from Setup. * Save the first admin user from Setup.
* *

View file

@ -9,6 +9,7 @@ use Illuminate\Http\Client\Response;
use Illuminate\Log\Events\MessageLogged; use Illuminate\Log\Events\MessageLogged;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\URL; use Illuminate\Support\Facades\URL;
@ -267,4 +268,37 @@ class ShowSetUpPageTest extends TestCase
$this->assertSeeAppUrlMisconfigurationErrorMessage(); $this->assertSeeAppUrlMisconfigurationErrorMessage();
} }
public function testWillSeeDirectoryPermissionErrorWhenStoragePathIsNotWritable(): void
{
File::shouldReceive('isWritable')->andReturn(false);
$this->getSetUpPageResponse()->assertOk();
$this->assertSeeDirectoryPermissionError();
}
protected function assertSeeDirectoryPermissionError(bool $shouldSee = true): void
{
$storagePath = storage_path();
$errorMessage = "Uh-oh. Your <code>{$storagePath}</code> directory (or sub-directories within) are not writable by the web-server. Those directories need to be writable by the web server in order for the app to work.";
$successMessage = 'Yippee! Your app storage directory seems writable';
if ($shouldSee) {
self::$latestResponse->assertSee($errorMessage, false)->assertDontSee($successMessage, false);
return;
}
self::$latestResponse->assertSee($successMessage, false)->assertDontSee($errorMessage,false);
}
public function testWillNotSeeDirectoryPermissionErrorWhenStoragePathIsWritable(): void
{
File::shouldReceive('isWritable')->andReturn(true);
$this->getSetUpPageResponse()->assertOk();
$this->assertSeeDirectoryPermissionError(false);
}
} }