mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-03 12:26:36 +08:00
fix: improve telegram channel connectivity
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTelegramMethodURLUsesCustomAPIBase(t *testing.T) {
|
||||
got, err := telegramMethodURL(map[string]string{
|
||||
"api_base_url": "https://tg.example.com/",
|
||||
}, "123456:ABC-def", "sendMessage")
|
||||
if err != nil {
|
||||
t.Fatalf("telegramMethodURL returned error: %v", err)
|
||||
}
|
||||
want := "https://tg.example.com/bot123456:ABC-def/sendMessage"
|
||||
if got != want {
|
||||
t.Fatalf("got %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSanitizeTelegramErrorRedactsBotToken(t *testing.T) {
|
||||
err := sanitizeTelegramError(errors.New(`Post "https://api.telegram.org/bot123456:SECRET/sendMessage": context deadline exceeded`))
|
||||
if err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
msg := err.Error()
|
||||
if strings.Contains(msg, "SECRET") || strings.Contains(msg, "123456:") {
|
||||
t.Fatalf("telegram token leaked in error: %s", msg)
|
||||
}
|
||||
if !strings.Contains(msg, "timeout") {
|
||||
t.Fatalf("expected timeout hint, got: %s", msg)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user