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 { readMembers } from './members.js'
|
||||
import { readUsers } from './auth.js'
|
||||
import { encryptObject, decryptObject } from './encryption.js'
|
||||
import crypto from 'crypto'
|
||||
import { writeDataFileWithRotation } from './data-file-rotation.js'
|
||||
|
||||
// nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
|
||||
// filename is always a hardcoded constant (e.g., 'newsletter-subscribers.json'), never user input
|
||||
@@ -136,7 +137,7 @@ export async function writeSubscribers(subscribers) {
|
||||
try {
|
||||
const encryptionKey = getEncryptionKey()
|
||||
const encryptedData = encryptObject(subscribers, encryptionKey)
|
||||
await fs.writeFile(NEWSLETTER_SUBSCRIBERS_FILE, encryptedData, 'utf-8')
|
||||
await writeDataFileWithRotation(NEWSLETTER_SUBSCRIBERS_FILE, encryptedData, { encoding: 'utf-8' })
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Schreiben der Newsletter-Abonnenten:', error)
|
||||
|
||||
Reference in New Issue
Block a user