dir = sys_get_temp_dir().'/inhaus-sdk-'.bin2hex(random_bytes(4)); mkdir($this->dir.'/core', 0777, true); mkdir($this->dir.'/custom', 0777, true); config(['inhaus.plugin_assets_path' => $this->dir.'/public']); } protected function tearDown(): void { Filesystem::deleteDirectory($this->dir); parent::tearDown(); } /** * Kunden-Plugin mit vorkompilierter Oberfläche unter dist/. */ private function makeUiPlugin(string $slug, string $base = 'custom'): string { $namespace = 'SdkTest'.bin2hex(random_bytes(3)); $path = "{$this->dir}/{$base}/{$slug}"; mkdir("{$path}/src", 0777, true); mkdir("{$path}/dist/pages", 0777, true); file_put_contents("{$path}/plugin.json", json_encode([ 'slug' => $slug, 'name' => 'SDK-Test', 'version' => '1.2.3', 'namespace' => "{$namespace}\\", 'class' => "{$namespace}\\Plugin", ])); file_put_contents("{$path}/src/Plugin.php", " ['pages/Index' => 'pages/Index.js', 'widgets/Böse' => '../../.env'], 'css' => ['style.css'], ])); file_put_contents("{$path}/dist/pages/Index.js", 'export default {};'); file_put_contents("{$path}/dist/style.css", '.ih\:grid{display:grid}'); file_put_contents("{$path}/dist/geheim.php", 'dir.'/state.json'); foreach ($enabled as $slug) { $state->setEnabled($slug, true); } $manager = new PluginManager($this->app, $state, $this->dir.'/core', $this->dir.'/custom'); $manager->registerAll(); $manager->bootAll(); $this->app->instance(PluginManager::class, $manager); $this->app->instance(PluginAssets::class, new PluginAssets($manager)); return $manager; } public function test_active_customer_plugins_expose_their_components(): void { $this->makeUiPlugin('mit-ui'); $this->makeUiPlugin('inaktiv'); $this->makeUiPlugin('kern-ui', 'core'); $this->boot('mit-ui'); $assets = app(PluginAssets::class)->forFrontend(); $this->assertSame(['mit-ui'], array_keys($assets)); $this->assertSame('/plugin-assets/mit-ui/1.2.3/', $assets['mit-ui']['base']); $this->assertSame(['pages/Index' => 'pages/Index.js'], $assets['mit-ui']['components']); $this->assertSame(['style.css'], $assets['mit-ui']['css']); } public function test_asset_route_serves_only_whitelisted_files_from_dist(): void { $this->makeUiPlugin('mit-ui'); $this->makeUiPlugin('inaktiv'); $this->boot('mit-ui'); $response = $this->get('/plugin-assets/mit-ui/1.2.3/pages/Index.js'); $response->assertOk(); $this->assertStringStartsWith('text/javascript', $response->headers->get('Content-Type')); $this->assertStringContainsString('immutable', $response->headers->get('Cache-Control')); $this->assertSame('nosniff', $response->headers->get('X-Content-Type-Options')); $this->get('/plugin-assets/mit-ui/1.2.3/style.css')->assertOk(); $this->get('/plugin-assets/mit-ui/1.2.3/geheim.php')->assertNotFound(); $this->get('/plugin-assets/mit-ui/1.2.3/../plugin-geheim.js')->assertNotFound(); $this->get('/plugin-assets/mit-ui/1.2.3/fehlt.js')->assertNotFound(); $this->get('/plugin-assets/inaktiv/1.2.3/pages/Index.js')->assertNotFound(); $this->assertNull(app(PluginAssets::class)->file('mit-ui', '../plugin-geheim.js')); } public function test_assets_are_published_for_the_web_server_and_removed_again(): void { $this->makeUiPlugin('mit-ui'); file_put_contents($this->dir.'/custom/mit-ui/dist/geheim.php', 'boot('mit-ui'); @mkdir($this->dir.'/public/mit-ui/1.0.0', 0777, true); // ältere Version app(PluginAssets::class)->forFrontend(); $published = $this->dir.'/public/mit-ui/1.2.3'; $this->assertFileExists($published.'/pages/Index.js'); $this->assertFileExists($published.'/style.css'); $this->assertFileDoesNotExist($published.'/geheim.php', 'Nur erlaubte Dateitypen'); $this->assertDirectoryDoesNotExist($this->dir.'/public/mit-ui/1.0.0'); $this->assertSame(file_get_contents($this->dir.'/custom/mit-ui/dist/pages/Index.js'), file_get_contents($published.'/pages/Index.js')); // Neuer Build bei gleicher Version wird neu kopiert // (Seiten behalten ihren Namen – inhaus.json bleibt gleich, nur die Datei ist neuer) file_put_contents($this->dir.'/custom/mit-ui/dist/pages/Index.js', 'export default { neu: true };'); touch($this->dir.'/custom/mit-ui/dist/pages/Index.js', time() + 60); (new PluginAssets($manager))->forFrontend(); $this->assertStringContainsString('neu: true', file_get_contents($published.'/pages/Index.js')); $manager->deactivate('mit-ui'); $this->assertDirectoryDoesNotExist($this->dir.'/public/mit-ui'); } public function test_pages_carry_import_map_and_plugin_manifest(): void { $this->makeUiPlugin('mit-ui'); $this->boot('mit-ui'); $html = $this->actingAs(User::factory()->create())->get('/')->assertOk()->getContent(); $this->assertStringContainsString('