@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DatabaseErrorRedactionTest extends TestCase
|
||||
{
|
||||
public function test_public_html_database_errors_do_not_expose_sql_or_connection_details(): void
|
||||
{
|
||||
config(['app.debug' => true]);
|
||||
Route::get('/_test/database-error-redaction', fn () => \DB::select('select missing_column from private_test_table'));
|
||||
|
||||
$response = $this->get('/_test/database-error-redaction');
|
||||
|
||||
$response->assertStatus(503)
|
||||
->assertSee('Serviço temporariamente indisponível')
|
||||
->assertDontSee('missing_column')
|
||||
->assertDontSee('private_test_table')
|
||||
->assertDontSee('investemoz_test')
|
||||
->assertDontSee('127.0.0.1')
|
||||
->assertDontSee('QueryException')
|
||||
->assertDontSee('C:\\laragon');
|
||||
}
|
||||
|
||||
public function test_api_database_errors_return_a_safe_reference_without_sql(): void
|
||||
{
|
||||
config(['app.debug' => true]);
|
||||
Route::get('/api/_test/database-error-redaction', fn () => \DB::select('select missing_column from private_test_table'));
|
||||
|
||||
$response = $this->getJson('/api/_test/database-error-redaction');
|
||||
|
||||
$response->assertStatus(503)
|
||||
->assertJsonPath('message', 'Serviço temporariamente indisponível. Tente novamente mais tarde.')
|
||||
->assertJsonStructure(['message', 'reference']);
|
||||
$this->assertStringNotContainsString('missing_column', $response->getContent());
|
||||
$this->assertStringNotContainsString('private_test_table', $response->getContent());
|
||||
}
|
||||
|
||||
public function test_connection_errors_do_not_expose_host_or_database_name(): void
|
||||
{
|
||||
config(['app.debug' => true, 'database.connections.pgsql.host' => '127.0.0.1',
|
||||
'database.connections.pgsql.port' => 1]);
|
||||
DB::purge('pgsql');
|
||||
Route::get('/_test/database-connection-error', fn () => DB::select('select 1'));
|
||||
|
||||
$response = $this->get('/_test/database-connection-error');
|
||||
|
||||
$response->assertStatus(503)->assertSee('Serviço temporariamente indisponível')
|
||||
->assertDontSee('127.0.0.1')->assertDontSee('investemoz_test');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user