dir = sys_get_temp_dir().'/inhaus-updates-'.bin2hex(random_bytes(4)); mkdir($this->dir.'/core', 0777, true); mkdir($this->dir.'/custom', 0777, true); $this->namespace = 'UpdTest'.bin2hex(random_bytes(3)); $this->writePlugin($this->dir.'/custom/spruch', '1.0.0'); $manager = new PluginManager($this->app, new PluginState($this->dir.'/state.json'), $this->dir.'/core', $this->dir.'/custom'); $this->app->instance(PluginManager::class, $manager); $this->app->forgetInstance(PluginUpdates::class); } protected function tearDown(): void { Filesystem::deleteDirectory($this->dir); parent::tearDown(); } private function writePlugin(string $path, string $version): void { @mkdir($path.'/src', 0777, true); file_put_contents($path.'/plugin.json', json_encode([ 'slug' => 'spruch', 'name' => 'Spruch', 'version' => $version, 'namespace' => $this->namespace.'\\', 'class' => $this->namespace.'\\Plugin', 'update_url' => 'https://git.example.org/api/v1/repos/acme/spruch/releases/latest', ])); file_put_contents($path.'/src/Plugin.php', "namespace};\nclass Plugin extends \\App\\Plugins\\Plugin {}\n"); } private function zip(string $version): string { $source = $this->dir.'/build-'.$version; $this->writePlugin($source.'/spruch', $version); $zipFile = $this->dir.'/spruch-'.$version.'.zip'; $zip = new ZipArchive; $zip->open($zipFile, ZipArchive::CREATE); $zip->addFile($source.'/spruch/plugin.json', 'spruch/plugin.json'); $zip->addFile($source.'/spruch/src/Plugin.php', 'spruch/src/Plugin.php'); $zip->close(); return (string) file_get_contents($zipFile); } public function test_forgejo_release_is_detected_and_installed(): void { $zip = $this->zip('1.1.0'); Http::fake([ 'git.example.org/api/v1/repos/acme/spruch/releases/latest' => Http::response([ 'tag_name' => 'v1.1.0', 'body' => 'Neue Sprüche für 2027', 'assets' => [['name' => 'spruch-1.1.0.zip', 'browser_download_url' => 'https://git.example.org/acme/spruch/releases/download/v1.1.0/spruch-1.1.0.zip']], ]), 'git.example.org/acme/spruch/releases/download/*' => Http::response($zip), ]); $updates = app(PluginUpdates::class); $updates->check(); $info = $updates->info('spruch'); $this->assertTrue($info['available']); $this->assertSame('1.1.0', $info['version']); $this->assertSame('Neue Sprüche für 2027', $info['changelog']); $this->actingAs(User::factory()->admin()->create()); Livewire::test(Plugins::class) ->assertSee('Update auf 1.1.0 verfügbar')->assertSee('Neue Sprüche für 2027')->assertSee('Nach Updates suchen') ->call('updatePlugin', 'spruch'); $this->assertNull(Plugins::getNavigationBadge()); // nach dem Update nichts mehr offen $manifest = PluginManifest::fromDirectory($this->dir.'/custom/spruch', false); $this->assertSame('1.1.0', $manifest->version); $this->assertSame('1.1.0', json_decode(file_get_contents($this->dir.'/custom/spruch/plugin.json'), true)['version']); $this->assertFalse($updates->info('spruch')['available']); } public function test_checksum_is_enforced(): void { Http::fake([ 'git.example.org/api/v1/*' => Http::response(['version' => '2.0.0', 'download_url' => 'https://git.example.org/spruch.zip', 'sha256' => str_repeat('a', 64)]), 'git.example.org/spruch.zip' => Http::response($this->zip('2.0.0')), ]); $updates = app(PluginUpdates::class); $updates->check(); try { $updates->update('spruch'); $this->fail('Falsche Prüfsumme wurde akzeptiert.'); } catch (RuntimeException $e) { $this->assertStringContainsString('Prüfsumme', $e->getMessage()); } $this->assertSame('1.0.0', json_decode(file_get_contents($this->dir.'/custom/spruch/plugin.json'), true)['version']); } public function test_updates_requiring_a_newer_core_are_not_installed(): void { Http::fake(['*' => Http::response(['version' => '3.0.0', 'download_url' => 'https://x.test/a.zip', 'requires' => ['core' => '>=99.0']])]); $updates = app(PluginUpdates::class); $updates->check(); $this->assertFalse($updates->info('spruch')['compatible']); $this->expectExceptionMessage('benötigt Inhaus >=99.0'); $updates->update('spruch'); } public function test_insecure_or_broken_update_urls_are_reported(): void { Http::fake(['*' => Http::response('Fehler', 500)]); $results = app(PluginUpdates::class)->check(); $this->assertStringContainsString('HTTP 500', $results['spruch']['error']); $this->assertFalse(app(PluginUpdates::class)->info('spruch')['available']); } }