Files
Charon/backend/internal/services/backup_service_wave6_test.go
GitHub Actions 2cad49de85 chore: Add tests for backup service, crowdsec startup, log service, and security headers
- Implement tests for BackupService to handle database extraction from backup archives with SHM and WAL entries.
- Add tests for BackupService to validate behavior when creating backups for non-SQLite databases and handling oversized database entries.
- Introduce tests for CrowdSec startup to ensure proper error handling during configuration creation.
- Enhance LogService tests to cover scenarios for skipping dot and empty directories and handling read directory errors.
- Add tests for SecurityHeadersService to ensure proper error handling during preset creation and updates.
- Update ProxyHostForm tests to include HSTS subdomains toggle and validation for port input handling.
- Enhance DNSProviders tests to validate manual challenge completion and error handling when no providers are available.
- Extend UsersPage tests to ensure fallback mechanisms for clipboard operations when the clipboard API fails.
2026-02-17 19:13:28 +00:00

50 lines
1.3 KiB
Go

package services
import (
"archive/zip"
"io"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func TestBackupServiceWave6_ExtractDatabaseFromBackup_WithShmEntry(t *testing.T) {
tmpDir := t.TempDir()
dbPath := filepath.Join(tmpDir, "charon.db")
createSQLiteTestDB(t, dbPath)
zipPath := filepath.Join(tmpDir, "with-shm.zip")
zipFile, err := os.Create(zipPath) // #nosec G304 -- path is derived from t.TempDir()
require.NoError(t, err)
writer := zip.NewWriter(zipFile)
sourceDB, err := os.Open(dbPath) // #nosec G304 -- path is derived from t.TempDir()
require.NoError(t, err)
defer func() { _ = sourceDB.Close() }()
dbEntry, err := writer.Create("charon.db")
require.NoError(t, err)
_, err = io.Copy(dbEntry, sourceDB)
require.NoError(t, err)
walEntry, err := writer.Create("charon.db-wal")
require.NoError(t, err)
_, err = walEntry.Write([]byte("invalid wal content"))
require.NoError(t, err)
shmEntry, err := writer.Create("charon.db-shm")
require.NoError(t, err)
_, err = shmEntry.Write([]byte("shm placeholder"))
require.NoError(t, err)
require.NoError(t, writer.Close())
require.NoError(t, zipFile.Close())
svc := &BackupService{DatabaseName: "charon.db"}
restoredPath, err := svc.extractDatabaseFromBackup(zipPath)
require.NoError(t, err)
require.FileExists(t, restoredPath)
}