Add unit tests for data file rotation utility functions
- Implement tests for writing data files with rotation, ensuring backups are created only on changes. - Verify that old backups are rotated correctly and the maximum number of backups is maintained. - Test restoration of backups while preserving the current state as a backup. - Utilize Vitest for testing framework and manage temporary file storage during tests.
This commit is contained in:
@@ -4,6 +4,7 @@ import crypto from 'crypto'
|
||||
import { promises as fs } from 'fs'
|
||||
import path from 'path'
|
||||
import { encryptObject, decryptObject } from './encryption.js'
|
||||
import { writeDataFileWithRotation } from './data-file-rotation.js'
|
||||
|
||||
// Export migrateUserRoles für Verwendung in anderen Modulen
|
||||
export function migrateUserRoles(user) {
|
||||
@@ -196,7 +197,7 @@ export async function writeUsers(users) {
|
||||
try {
|
||||
const encryptionKey = getEncryptionKey()
|
||||
const encryptedData = encryptObject(users, encryptionKey)
|
||||
await fs.writeFile(USERS_FILE, encryptedData, 'utf-8')
|
||||
await writeDataFileWithRotation(USERS_FILE, encryptedData, { encoding: 'utf-8' })
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Schreiben der Benutzerdaten:', error)
|
||||
@@ -262,7 +263,7 @@ export async function writeSessions(sessions) {
|
||||
try {
|
||||
const encryptionKey = getEncryptionKey()
|
||||
const encryptedData = encryptObject(sessions, encryptionKey)
|
||||
await fs.writeFile(SESSIONS_FILE, encryptedData, 'utf-8')
|
||||
await writeDataFileWithRotation(SESSIONS_FILE, encryptedData, { encoding: 'utf-8' })
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Schreiben der Sessions:', error)
|
||||
|
||||
Reference in New Issue
Block a user