Files
takeone-youtube-clone/app/Providers/AppServiceProvider.php
T
ghassanandClaude Opus 4.7 4718888de0 test(phase-1): feature coverage for security + data-integrity fixes
Seven feature tests, run against an in-memory SQLite forced via putenv
in setUp (keeps the shared dev DB safe). Covers:

- Reserved-identifier rule rejects admin / super_admin / takeone /
  support / etc, matches both name and email local-part only, and
  lets normal names through.
- SafeNotifier swallows a notification throw without re-raising.
- Identical comments within 60s collapse to the first row.
- X-Idempotency-Key returns the first comment on retry.
- Owner viewing their own video does not insert a video_views row.

AppServiceProvider stops force-upgrading the scheme in the testing env
so the HTTP test client isn't 302'd before reaching the controller.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2026-10-21 00:44:58 +03:00

63 lines
2.7 KiB
PHP
Executable File

<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Request;
use Illuminate\Pagination\Paginator;
class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
//
}
public function boot(): void
{
// Trust Cloudflare proxies
Request::setTrustedProxies(
['*'],
\Illuminate\Http\Request::HEADER_X_FORWARDED_FOR |
\Illuminate\Http\Request::HEADER_X_FORWARDED_HOST |
\Illuminate\Http\Request::HEADER_X_FORWARDED_PORT |
\Illuminate\Http\Request::HEADER_X_FORWARDED_PROTO |
\Illuminate\Http\Request::HEADER_X_FORWARDED_AWS_ELB
);
// Force HTTPS unless we're running under phpunit — the test client
// speaks plain http://localhost; forcing https would make every POST
// in a feature test resolve to a 302 instead of hitting the controller.
if (! $this->app->environment('testing')) {
URL::forceScheme('https');
}
// Universal pagination view — used everywhere by default
Paginator::defaultView('partials.pagination');
Paginator::defaultSimpleView('partials.pagination');
// Merge NAS credentials stored in the DB into the package config at runtime.
// This way the live browser and all NAS operations use DB values without needing .env.
$this->app->booted(function () {
try {
$host = \App\Models\Setting::get('nas_host', '');
if ($host) {
config([
'nas-file-manager.connection.protocol' => \App\Models\Setting::get('nas_protocol', 'smb'),
'nas-file-manager.connection.host' => $host,
'nas-file-manager.connection.port' => (int) \App\Models\Setting::get('nas_port', 445),
'nas-file-manager.connection.username' => \App\Models\Setting::get('nas_username', ''),
'nas-file-manager.connection.password' => \App\Models\Setting::get('nas_password', ''),
'nas-file-manager.connection.path' => \App\Models\Setting::get('nas_path', '/media'),
'nas-file-manager.connection.smb_share' => \App\Models\Setting::get('nas_smb_share', ''),
'nas-file-manager.connection.smb_domain' => \App\Models\Setting::get('nas_smb_domain', ''),
]);
}
} catch (\Throwable $e) {
// DB may not exist yet (fresh install / migrations not run) — silently skip
}
});
}
}