diff --git a/app/Http/Controllers/Web/HealthCheckController.php b/app/Http/Controllers/Web/HealthCheckController.php index 1c4ff277..399818e6 100644 --- a/app/Http/Controllers/Web/HealthCheckController.php +++ b/app/Http/Controllers/Web/HealthCheckController.php @@ -45,18 +45,34 @@ public function debug(Request $request): JsonResponse $dbTimezone = DB::select('show timezone;'); + $response = [ + 'ip_address' => $ipAddress, + 'url' => $request->url(), + 'path' => $request->path(), + 'hostname' => $hostname, + 'timestamp' => Carbon::now()->timestamp, + 'date_time_utc' => Carbon::now('UTC')->toDateTimeString(), + 'date_time_app' => Carbon::now()->toDateTimeString(), + 'timezone' => $dbTimezone[0]->TimeZone, + 'secure' => $secure, + 'is_trusted_proxy' => $isTrustedProxy, + ]; + + if (app()->hasDebugModeEnabled()) { + $response['app_debug'] = true; + $response['app_url'] = config('app.url'); + $response['app_env'] = app()->environment(); + $response['app_timezone'] = config('app.timezone'); + $response['app_force_https'] = config('app.force_https'); + $response['trusted_proxies'] = config('trustedproxy.proxies'); + $headers = $request->headers->all(); + if (isset($headers['cookie'])) { + $headers['cookie'] = '***'; + } + $response['headers'] = $headers; + } + return response() - ->json([ - 'ip_address' => $ipAddress, - 'url' => $request->url(), - 'path' => $request->path(), - 'hostname' => $hostname, - 'timestamp' => Carbon::now()->timestamp, - 'date_time_utc' => Carbon::now('UTC')->toDateTimeString(), - 'date_time_app' => Carbon::now()->toDateTimeString(), - 'timezone' => $dbTimezone[0]->TimeZone, - 'secure' => $secure, - 'is_trusted_proxy' => $isTrustedProxy, - ]); + ->json($response); } } diff --git a/config/app.php b/config/app.php index 1cc8a5b0..f2eababf 100644 --- a/config/app.php +++ b/config/app.php @@ -65,7 +65,7 @@ 'asset_url' => env('ASSET_URL'), - 'force_https' => env('APP_FORCE_HTTPS', false), + 'force_https' => (bool) env('APP_FORCE_HTTPS', false), /* |-------------------------------------------------------------------------- diff --git a/tests/Unit/Endpoint/Web/HealthCheckEndpointTest.php b/tests/Unit/Endpoint/Web/HealthCheckEndpointTest.php index 73362416..a9e4592a 100644 --- a/tests/Unit/Endpoint/Web/HealthCheckEndpointTest.php +++ b/tests/Unit/Endpoint/Web/HealthCheckEndpointTest.php @@ -33,20 +33,57 @@ public function test_up_endpoint_returns_ok(): void public function test_debug_endpoint_returns_ok(): void { + // Arrange + config(['app.debug' => false]); + // Act $response = $this->get('health-check/debug'); // Assert $response->assertSuccessful(); - $response->assertJsonStructure([ - 'ip_address', + $response->assertExactJsonStructure([ + 'date_time_app', + 'date_time_utc', 'hostname', + 'ip_address', + 'is_trusted_proxy', + 'path', + 'secure', 'timestamp', - 'date_time_utc', - 'date_time_app', 'timezone', - 'secure', + 'url', + ]); + config(['app.debug' => true]); + } + + public function test_debug_endpoint_returns_more_information_if_debug_mode_is_enabled(): void + { + // Arrange + config(['app.debug' => true]); + + // Act + $response = $this->get('health-check/debug'); + + // Assert + $response->assertSuccessful(); + $response->assertExactJsonStructure([ + 'app_debug', + 'app_env', + 'app_force_https', + 'app_timezone', + 'app_url', + 'date_time_app', + 'date_time_utc', + 'headers', + 'hostname', + 'ip_address', 'is_trusted_proxy', + 'path', + 'secure', + 'timestamp', + 'timezone', + 'trusted_proxies', + 'url', ]); } }