ver. 0.300: Manifest-based update system with checksum verification and file backup
Replaces the manual ZIP packaging workflow with an automated build script. UpdateRepository now supports both manifest JSON format (new) and legacy _sql.txt/_files.txt format (fallback), enabling a smooth transition for existing client instances. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -50,7 +50,7 @@ class UpdateRepositoryTest extends TestCase
|
||||
$repository = new UpdateRepository($db);
|
||||
$repository->runPendingMigrations();
|
||||
|
||||
$this->assertTrue(true); // No exception thrown
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testHasPrivateHelperMethods(): void
|
||||
@@ -59,6 +59,11 @@ class UpdateRepositoryTest extends TestCase
|
||||
|
||||
$privateMethods = [
|
||||
'downloadAndApply',
|
||||
'downloadAndApplyLegacy',
|
||||
'downloadAndApplyWithManifest',
|
||||
'downloadManifest',
|
||||
'verifyChecksum',
|
||||
'createBackup',
|
||||
'executeSql',
|
||||
'deleteFiles',
|
||||
'extractZip',
|
||||
@@ -77,4 +82,99 @@ class UpdateRepositoryTest extends TestCase
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testVerifyChecksumValidFormat(): void
|
||||
{
|
||||
$db = $this->createMockDb();
|
||||
$repository = new UpdateRepository($db);
|
||||
|
||||
$reflection = new \ReflectionClass($repository);
|
||||
$method = $reflection->getMethod('verifyChecksum');
|
||||
$method->setAccessible(true);
|
||||
|
||||
// Create a temp file with known content
|
||||
$tmpFile = tempnam(sys_get_temp_dir(), 'test_checksum_');
|
||||
file_put_contents($tmpFile, 'test content for checksum');
|
||||
|
||||
$expectedHash = hash_file('sha256', $tmpFile);
|
||||
$result = $method->invoke($repository, $tmpFile, 'sha256:' . $expectedHash, []);
|
||||
|
||||
$this->assertTrue($result['valid']);
|
||||
$this->assertNotEmpty($result['log']);
|
||||
|
||||
@unlink($tmpFile);
|
||||
}
|
||||
|
||||
public function testVerifyChecksumInvalidHash(): void
|
||||
{
|
||||
$db = $this->createMockDb();
|
||||
$repository = new UpdateRepository($db);
|
||||
|
||||
$reflection = new \ReflectionClass($repository);
|
||||
$method = $reflection->getMethod('verifyChecksum');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$tmpFile = tempnam(sys_get_temp_dir(), 'test_checksum_');
|
||||
file_put_contents($tmpFile, 'test content');
|
||||
|
||||
$result = $method->invoke($repository, $tmpFile, 'sha256:invalidhash', []);
|
||||
|
||||
$this->assertFalse($result['valid']);
|
||||
|
||||
@unlink($tmpFile);
|
||||
}
|
||||
|
||||
public function testVerifyChecksumInvalidFormat(): void
|
||||
{
|
||||
$db = $this->createMockDb();
|
||||
$repository = new UpdateRepository($db);
|
||||
|
||||
$reflection = new \ReflectionClass($repository);
|
||||
$method = $reflection->getMethod('verifyChecksum');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($repository, '/tmp/nonexistent', 'badformat', []);
|
||||
|
||||
$this->assertFalse($result['valid']);
|
||||
}
|
||||
|
||||
public function testCreateBackupWithEmptyManifest(): void
|
||||
{
|
||||
$db = $this->createMockDb();
|
||||
$repository = new UpdateRepository($db);
|
||||
|
||||
$reflection = new \ReflectionClass($repository);
|
||||
$method = $reflection->getMethod('createBackup');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$manifest = [
|
||||
'version' => '0.999',
|
||||
'files' => [],
|
||||
];
|
||||
|
||||
$log = $method->invoke($repository, $manifest, []);
|
||||
|
||||
$this->assertIsArray($log);
|
||||
$hasBackupInfo = false;
|
||||
foreach ($log as $entry) {
|
||||
if (strpos($entry, 'Brak plików do backupu') !== false) {
|
||||
$hasBackupInfo = true;
|
||||
}
|
||||
}
|
||||
$this->assertTrue($hasBackupInfo);
|
||||
}
|
||||
|
||||
public function testDownloadManifestReturnsNullForInvalidUrl(): void
|
||||
{
|
||||
$db = $this->createMockDb();
|
||||
$repository = new UpdateRepository($db);
|
||||
|
||||
$reflection = new \ReflectionClass($repository);
|
||||
$method = $reflection->getMethod('downloadManifest');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($repository, 'http://invalid.nonexistent.test', '0.999');
|
||||
|
||||
$this->assertNull($result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user