Dateien nur mit Anmeldung, nur Microsoft-Login, mehrere Titelbilder (0.47.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m25s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m46s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m52s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 8m5s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 10m33s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 10m53s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 9m1s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m49s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 54s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m4s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m25s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m46s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m52s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 8m5s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 10m33s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 10m53s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 9m1s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m49s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 54s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m4s
- /uploads nur über das Portal: UploadController prüft Sitzung bzw. App-Token; frei nur die Dateien der Anmeldeseite (Logos, Symbole, Anmeldehintergrund, Stylesheet, Schrift); public/uploads/.htaccess leitet alles an index.php (Migration schreibt sie, da der Ordner vor dem Updater geschützt ist); Systemzustand prüft die Regel; nginx-Hinweis in docs/SECURITY.md - Passwort-Anmeldung abschaltbar (PasswordLogin): Login-Formular, Passwort vergessen, App-Token und /api/v1/config; nur mit verknüpftem Konto abschaltbar, automatische Rückkehr ohne nutzbaren Dienst, Notausgang INHAUS_PASSWORD_LOGIN - Titelbilder: profile_covers (bis 12), zufällig je Seitenaufruf - ImageCompressor: Uploads im Backend (SafeUpload) und WordPress-Import auf ≤ 2400 px komprimiert, Format bleibt Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
47b55b4ce5
commit
d91570f118
155 changed files with 1035 additions and 382 deletions
|
|
@ -297,4 +297,30 @@ class AppearanceTest extends TestCase
|
|||
$theme->optimizePhotos();
|
||||
$this->assertStringEndsWith('.webp', $theme->published()['profile_cover']);
|
||||
}
|
||||
|
||||
public function test_several_cover_images_are_shown_at_random(): void
|
||||
{
|
||||
$disk = Storage::disk('uploads');
|
||||
foreach (['a', 'b', 'c'] as $name) {
|
||||
$disk->put("theme/{$name}.webp", UploadedFile::fake()->image("{$name}.webp", 40, 20)->getContent());
|
||||
}
|
||||
|
||||
$theme = app(Theme::class);
|
||||
|
||||
// Ein älteres Einzelbild wird zur Liste
|
||||
$theme->saveDraft(['profile_cover' => 'theme/a.webp']);
|
||||
$this->assertSame(['theme/a.webp'], $theme->draft()['profile_covers']);
|
||||
|
||||
$theme->saveDraft(['profile_covers' => ['theme/b.webp', 'theme/c.webp', '../geheim.webp']]);
|
||||
$this->assertSame(['theme/b.webp', 'theme/c.webp'], $theme->draft()['profile_covers']);
|
||||
$this->assertSame('theme/b.webp', $theme->draft()['profile_cover']);
|
||||
|
||||
app(Settings::class)->set('theme.published', $theme->draft());
|
||||
$this->app->forgetInstance(Branding::class);
|
||||
$seen = [];
|
||||
for ($i = 0; $i < 40; $i++) {
|
||||
$seen[app(Branding::class)->toArray()['profile_cover']['image_url']] = true;
|
||||
}
|
||||
$this->assertCount(2, $seen, 'Beide Titelbilder kommen vor');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
65
tests/Feature/Auth/PasswordLoginSwitchTest.php
Normal file
65
tests/Feature/Auth/PasswordLoginSwitchTest.php
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Auth;
|
||||
|
||||
use App\Filament\Resources\IdentityProviders\Pages\ListIdentityProviders;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use App\Support\PasswordLogin;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Livewire\Livewire;
|
||||
use Tests\Support\FakeEntra;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PasswordLoginSwitchTest extends TestCase
|
||||
{
|
||||
use FakeEntra;
|
||||
use RefreshDatabase;
|
||||
|
||||
private function admin(): User
|
||||
{
|
||||
return User::factory()->withRoles([Role::query()->where('slug', Role::ADMINISTRATION)->firstOrFail()])->create(['password' => 'geheim123']);
|
||||
}
|
||||
|
||||
public function test_only_linked_admins_can_switch_off_and_everything_follows(): void
|
||||
{
|
||||
$provider = $this->entraProvider();
|
||||
$admin = $this->admin();
|
||||
|
||||
// Nicht verknüpft: würde sich aussperren
|
||||
Livewire::actingAs($admin)->test(ListIdentityProviders::class)->callAction('passwordOff');
|
||||
$this->assertTrue(app(PasswordLogin::class)->enabled());
|
||||
|
||||
DB::table('user_identities')->insert(['user_id' => $admin->id, 'identity_provider_id' => $provider->id, 'subject' => 'oid-1', 'created_at' => now(), 'updated_at' => now()]);
|
||||
Livewire::actingAs($admin)->test(ListIdentityProviders::class)->callAction('passwordOff');
|
||||
$this->assertFalse(app(PasswordLogin::class)->enabled());
|
||||
auth()->logout();
|
||||
|
||||
$this->get('/login')->assertInertia(fn (Assert $p) => $p->where('passwordLogin', false)->where('canResetPassword', false)->has('providers', 1));
|
||||
$this->post('/login', ['email' => $admin->email, 'password' => 'geheim123'])->assertSessionHasErrors('email');
|
||||
$this->assertGuest();
|
||||
$this->get('/forgot-password')->assertRedirect('/login');
|
||||
$this->post('/forgot-password', ['email' => $admin->email])->assertRedirect('/login');
|
||||
|
||||
$this->getJson('/api/v1/config')->assertJsonPath('login.password', false);
|
||||
$this->postJson('/api/v1/token', ['email' => $admin->email, 'password' => 'geheim123', 'device_name' => 'iPhone'])->assertUnprocessable();
|
||||
|
||||
// Notausgang in der .env
|
||||
config(['inhaus.password_login_override' => 'true']);
|
||||
$this->post('/login', ['email' => $admin->email, 'password' => 'geheim123'])->assertRedirect();
|
||||
$this->assertAuthenticatedAs($admin);
|
||||
}
|
||||
|
||||
public function test_password_login_returns_when_no_provider_is_usable(): void
|
||||
{
|
||||
$provider = $this->entraProvider();
|
||||
app(PasswordLogin::class)->set(false);
|
||||
$this->assertFalse(app(PasswordLogin::class)->enabled());
|
||||
|
||||
$provider->update(['enabled' => false]);
|
||||
$this->assertTrue(app(PasswordLogin::class)->enabled(), 'Sonst käme niemand mehr hinein');
|
||||
$this->get('/login')->assertInertia(fn (Assert $p) => $p->where('passwordLogin', true));
|
||||
}
|
||||
}
|
||||
62
tests/Feature/ImageCompressorTest.php
Normal file
62
tests/Feature/ImageCompressorTest.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Support\ImageCompressor;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ImageCompressorTest extends TestCase
|
||||
{
|
||||
private function noise(int $width, int $height): \GdImage
|
||||
{
|
||||
// Rauschen wie bei einem Foto (einfarbige Testbilder wären winzig)
|
||||
$small = imagecreatetruecolor(intdiv($width, 10), intdiv($height, 10));
|
||||
for ($x = 0; $x < intdiv($width, 10); $x++) {
|
||||
for ($y = 0; $y < intdiv($height, 10); $y++) {
|
||||
imagesetpixel($small, $x, $y, random_int(0, 0xFFFFFF));
|
||||
}
|
||||
}
|
||||
$image = imagecreatetruecolor($width, $height);
|
||||
imagecopyresampled($image, $small, 0, 0, 0, 0, $width, $height, intdiv($width, 10), intdiv($height, 10));
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
public function test_photos_are_shrunk_and_compressed_in_their_format(): void
|
||||
{
|
||||
$jpeg = tempnam(sys_get_temp_dir(), 'cmp').'.jpg';
|
||||
imagejpeg($this->noise(4000, 3000), $jpeg, 97);
|
||||
$before = filesize($jpeg);
|
||||
|
||||
ImageCompressor::compressFile($jpeg);
|
||||
|
||||
clearstatcache();
|
||||
[$width, $height, $type] = getimagesize($jpeg);
|
||||
$this->assertSame([2400, 1800, IMAGETYPE_JPEG], [$width, $height, $type]);
|
||||
$this->assertLessThan($before / 2, filesize($jpeg));
|
||||
|
||||
// PNG bleibt PNG (Transparenz), nur kleiner in den Maßen
|
||||
$png = tempnam(sys_get_temp_dir(), 'cmp').'.png';
|
||||
$image = imagecreatetruecolor(3000, 1000);
|
||||
imagesavealpha($image, true);
|
||||
imagefill($image, 0, 0, imagecolorallocatealpha($image, 0, 0, 0, 127));
|
||||
imagepng($image, $png);
|
||||
ImageCompressor::compressFile($png);
|
||||
clearstatcache();
|
||||
[$width, , $type] = getimagesize($png);
|
||||
$this->assertSame([2400, IMAGETYPE_PNG], [$width, $type]);
|
||||
|
||||
// GIF (Animationen) und kleine Bilder bleiben unangetastet
|
||||
$gif = tempnam(sys_get_temp_dir(), 'cmp').'.gif';
|
||||
imagegif(imagecreatetruecolor(3000, 3000), $gif);
|
||||
$gifBefore = md5_file($gif);
|
||||
ImageCompressor::compressFile($gif);
|
||||
$this->assertSame($gifBefore, md5_file($gif));
|
||||
|
||||
$small = tempnam(sys_get_temp_dir(), 'cmp').'.jpg';
|
||||
imagejpeg(imagecreatetruecolor(300, 200), $small, 90);
|
||||
$smallBefore = md5_file($small);
|
||||
ImageCompressor::compressFile($small);
|
||||
$this->assertSame($smallBefore, md5_file($small));
|
||||
}
|
||||
}
|
||||
84
tests/Feature/UploadsProtectionTest.php
Normal file
84
tests/Feature/UploadsProtectionTest.php
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Support\Settings;
|
||||
use App\Support\Theme\Theme;
|
||||
use App\Support\UploadsGuard;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UploadsProtectionTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Storage::fake('uploads');
|
||||
$disk = Storage::disk('uploads');
|
||||
$disk->put('news/bild.webp', UploadedFile::fake()->image('b.webp', 20, 20)->getContent());
|
||||
$disk->put('theme/logo.png', UploadedFile::fake()->image('l.png', 20, 20)->getContent());
|
||||
$disk->put('theme/login.jpg', UploadedFile::fake()->image('l.jpg', 20, 20)->getContent());
|
||||
$disk->put('theme/cover.jpg', UploadedFile::fake()->image('c.jpg', 20, 20)->getContent());
|
||||
$disk->put('theme/alt.png', UploadedFile::fake()->image('a.png', 20, 20)->getContent());
|
||||
$disk->put('news/script.php', '<?php echo 1;');
|
||||
|
||||
app(Settings::class)->set('theme.published', [
|
||||
...app(Theme::class)->published(),
|
||||
'logo_light' => 'theme/logo.png', 'login_image' => 'theme/login.jpg', 'profile_cover' => 'theme/cover.jpg',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_files_need_a_login_except_what_the_login_page_needs(): void
|
||||
{
|
||||
// Ohne Anmeldung: nichts verraten
|
||||
$this->get('/uploads/news/bild.webp')->assertNotFound();
|
||||
$this->get('/uploads/theme/cover.jpg')->assertNotFound();
|
||||
$this->get('/uploads/theme/alt.png')->assertNotFound(); // nicht (mehr) im Erscheinungsbild
|
||||
|
||||
// Anmeldeseite: Logo und Hintergrund frei, öffentlich zwischenspeicherbar
|
||||
$logo = $this->get('/uploads/theme/logo.png')->assertOk();
|
||||
$this->assertStringContainsString('public', $logo->headers->get('Cache-Control'));
|
||||
$this->assertSame('nosniff', $logo->headers->get('X-Content-Type-Options'));
|
||||
$this->get('/uploads/theme/login.jpg')->assertOk();
|
||||
|
||||
// Angemeldet: alles, aber nur privat zwischengespeichert
|
||||
$user = User::factory()->create();
|
||||
$response = $this->actingAs($user)->get('/uploads/news/bild.webp')->assertOk();
|
||||
$this->assertStringContainsString('private', $response->headers->get('Cache-Control'));
|
||||
$this->assertSame('image/webp', $response->headers->get('Content-Type'));
|
||||
$this->actingAs($user)->get('/uploads/theme/cover.jpg')->assertOk();
|
||||
|
||||
// Nie: fremde Dateitypen, Pfade nach draußen
|
||||
$this->actingAs($user)->get('/uploads/news/script.php')->assertNotFound();
|
||||
$this->actingAs($user)->get('/uploads/../.env')->assertNotFound();
|
||||
$this->actingAs($user)->get('/uploads/news/..%2F..%2F.env')->assertNotFound();
|
||||
$this->actingAs($user)->get('/uploads/news/fehlt.webp')->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_app_token_and_deactivated_accounts(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$token = $user->createToken('App')->plainTextToken;
|
||||
$this->withToken($token)->get('/uploads/news/bild.webp')->assertOk();
|
||||
|
||||
$this->app['auth']->forgetGuards();
|
||||
$user->forceFill(['is_active' => false])->save();
|
||||
$this->withToken($token)->get('/uploads/news/bild.webp')->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_guard_file_is_written(): void
|
||||
{
|
||||
$dir = sys_get_temp_dir().'/inhaus-uploads-'.bin2hex(random_bytes(4));
|
||||
$this->assertFalse(UploadsGuard::installed($dir));
|
||||
$this->assertTrue(UploadsGuard::install($dir));
|
||||
$this->assertTrue(UploadsGuard::installed($dir));
|
||||
$this->assertStringContainsString('RewriteRule ^ ../index.php [L]', file_get_contents($dir.'/.htaccess'));
|
||||
$this->assertStringContainsString('Require all denied', file_get_contents($dir.'/.htaccess'));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue