Phase 1: core bot
Link in, card, download, send, in private chats and groups. - cmd/core with an embedded download worker - Telegram front end on telego v1.13.0 (Bot API 10.4): link card with thumbnail and format buttons, one live status message, /dl /audio /thumb /info /queue /cancel, group support with requester-only buttons - Database backed queue: paid and free lanes, leases with heartbeats, one automatic retry, cancel, queue position and wait estimate - yt-dlp and ffprobe behind a Runner interface with classified, redacted errors mapped to friendly messages - SQLite via modernc with goose migrations, portable schema - Local file storage behind a Storage interface - go-i18n with an English catalog, no literal text in handlers - Free tier limits enforced before queueing and again on the real file - Bot token and webhook secret are stripped from all log output - Tests: URL parsing, job lifecycle, worker, yt-dlp wrapper, and end to end flows against a fake Bot API server; opt-in test with the real yt-dlp Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRedactorRemovesSecretsFromLogs(t *testing.T) {
|
||||
const token = "123456789:FAKEfakeFAKEfakeFAKEfakeFAKEfake-01"
|
||||
var buf bytes.Buffer
|
||||
log := slog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{ReplaceAttr: Redactor(token, "", "abc")}))
|
||||
|
||||
err := errors.New(`Post "https://api.telegram.org/bot` + token + `/sendMessage": context canceled`)
|
||||
log.Error("request failed: "+token, "err", err, "url", "https://x/bot"+token+"/y",
|
||||
slog.Group("nested", "token", token), "n", 3)
|
||||
|
||||
out := buf.String()
|
||||
if strings.Contains(out, token) {
|
||||
t.Fatalf("the token leaked into the log: %s", out)
|
||||
}
|
||||
if strings.Count(out, "[REDACTED]") != 4 {
|
||||
t.Fatalf("expected the message, the error, the url and the nested value to be redacted: %s", out)
|
||||
}
|
||||
if !strings.Contains(out, "context canceled") || !strings.Contains(out, `"n":3`) {
|
||||
t.Fatalf("the rest of the entry must survive: %s", out)
|
||||
}
|
||||
if Redactor("", "abc") != nil {
|
||||
t.Fatal("without usable secrets no replacer is needed")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user