Backup notturno: le impostazioni senza il token del bot Telegram (#32)

Il backup logico scrive la tabella settings in chiaro in /config/backup, e con lei il token del bot
Telegram. Ora settings esce con value - 'TelegramBotToken', come già fa lo strumento dei dati; la chat
resta, perché non è un segreto. Dopo un ripristino da quei file il token va riscritto: lo dicono README
e architettura. Una prova su PostgreSQL controlla che il file non contenga il token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-24 18:23:41 +01:00
1 parent ceca0013b8
commit f92b8d08f0
4 files changed
+38 -3

No files matched your search

+25
View File
@@ -279,6 +279,31 @@ public class ArchiveDownloaderTests(DatabaseFixture fx)
Assert.True((bool)(await none.ExecuteScalarAsync())!);
}
[DbFact]
public async Task Il_backup_notturno_delle_impostazioni_non_contiene_il_token_di_telegram()
{
var db = fx.Db!;
await db.ExecuteAsync("INSERT INTO settings(id, value) VALUES (1, '{\"TelegramBotToken\": \"123:segreto\", \"TelegramChatId\": \"42\", \"MaxBids\": 5}') " +
"ON CONFLICT (id) DO UPDATE SET value = excluded.value");
var file = Path.Combine(Path.GetTempPath(), "mimante-backup-" + Guid.NewGuid().ToString("N") + ".csv");
try
{
await using (var conn = await db.Writer.OpenConnectionAsync())
await BulkCopy.ToFileAsync(conn, Maintenance.BackupCopySql("settings"), file);
var text = await File.ReadAllTextAsync(file);
Assert.StartsWith("id,value,updated_at", text);
Assert.DoesNotContain("segreto", text);
Assert.DoesNotContain("TelegramBotToken", text);
Assert.Contains("MaxBids", text);
Assert.Contains("TelegramChatId", text);
}
finally
{
File.Delete(file);
}
Assert.Equal("COPY bids TO STDOUT (FORMAT csv, HEADER)", Maintenance.BackupCopySql("bids"));
}
[DbFact]
public async Task La_connessione_dello_strumento_non_puo_scrivere()
{