Files

37 lines
1.1 KiB
Go

package telegram
import (
"errors"
"net/http"
"strings"
"testing"
)
func TestRedactForLogCredentials(t *testing.T) {
nsec := "nsec1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"
for _, in := range []string{"/nostr add " + nsec, "/nostr " + nsec, "please use " + nsec} {
if out := redactForLog(in); strings.Contains(out, "nsec1qqq") {
t.Errorf("%q leaked: %q", in, out)
}
}
if out := redactForLog("/pay lntb10u1pabcdefghijklmnopqrstuvwxyz0123456789"); strings.Contains(out, "lntb10u1p") {
t.Errorf("testnet invoice leaked: %q", out)
}
}
func TestErrorForLogDropsURLQuery(t *testing.T) {
_, err := http.Get("http://127.0.0.1:1/w?tag=withdrawRequest&k1=SECRETK1")
if err == nil {
t.Skip("unexpectedly reachable")
}
if !strings.Contains(err.Error(), "SECRETK1") {
t.Fatal("test premise: the url.Error text should contain the URL")
}
if got := errorForLog(err); strings.Contains(got, "SECRETK1") {
t.Errorf("k1 leaked: %q", got)
}
if got := errorForLog(errors.New("plain")); got != "plain" {
t.Errorf("plain error changed: %q", got)
}
}