mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-01 21:09:35 +00:00
Add tests for backup/update manager improvements
- Controller tests: auth, CSRF validation, 404 for missing backups, restore disabled check - UpdateExecutor: deleteLog validation, non-existent file, successful deletion - BackupManager: deleteBackup validation for missing/non-zip files
This commit is contained in:
parent
3c41597262
commit
e6ac77ffde
3 changed files with 180 additions and 0 deletions
|
|
@ -82,6 +82,16 @@ final class BackupManagerTest extends KernelTestCase
|
|||
$this->assertSame('2.6.0', $matches[2]);
|
||||
}
|
||||
|
||||
public function testDeleteBackupReturnsFalseForNonExistentFile(): void
|
||||
{
|
||||
$this->assertFalse($this->backupManager->deleteBackup('non-existent.zip'));
|
||||
}
|
||||
|
||||
public function testDeleteBackupReturnsFalseForNonZipFile(): void
|
||||
{
|
||||
$this->assertFalse($this->backupManager->deleteBackup('not-a-zip.txt'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test version parsing with different filename formats.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -139,6 +139,38 @@ final class UpdateExecutorTest extends KernelTestCase
|
|||
$this->assertFalse($this->updateExecutor->isLocked());
|
||||
}
|
||||
|
||||
public function testDeleteLogRejectsInvalidFilename(): void
|
||||
{
|
||||
// Path traversal attempts should be rejected
|
||||
$this->assertFalse($this->updateExecutor->deleteLog('../../../etc/passwd'));
|
||||
$this->assertFalse($this->updateExecutor->deleteLog('malicious.txt'));
|
||||
$this->assertFalse($this->updateExecutor->deleteLog(''));
|
||||
// Must start with "update-"
|
||||
$this->assertFalse($this->updateExecutor->deleteLog('backup-v1.0.0.log'));
|
||||
}
|
||||
|
||||
public function testDeleteLogReturnsFalseForNonExistentFile(): void
|
||||
{
|
||||
$this->assertFalse($this->updateExecutor->deleteLog('update-nonexistent-file.log'));
|
||||
}
|
||||
|
||||
public function testDeleteLogDeletesExistingFile(): void
|
||||
{
|
||||
// Create a temporary log file in the update logs directory
|
||||
$projectDir = self::getContainer()->getParameter('kernel.project_dir');
|
||||
$logDir = $projectDir . '/var/update_logs';
|
||||
|
||||
if (!is_dir($logDir)) {
|
||||
mkdir($logDir, 0755, true);
|
||||
}
|
||||
|
||||
$testFile = 'update-test-delete-' . uniqid() . '.log';
|
||||
file_put_contents($logDir . '/' . $testFile, 'test log content');
|
||||
|
||||
$this->assertTrue($this->updateExecutor->deleteLog($testFile));
|
||||
$this->assertFileDoesNotExist($logDir . '/' . $testFile);
|
||||
}
|
||||
|
||||
public function testEnableAndDisableMaintenanceMode(): void
|
||||
{
|
||||
// First, ensure maintenance mode is off
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue