(new): rich message support
(fix): runtime reliability (tests): regression coverage (doc): v1.1 release notes
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package tgapi
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRedactRequestLogRemovesSensitiveValues(t *testing.T) {
|
||||
const input = `{"secret_token":"webhook-secret","provider_token":"payment-token","nested":{"data":"passport-data","callback_data":"callback-secret"},"chat_id":42}`
|
||||
got := redactRequestLog([]byte(input))
|
||||
|
||||
for _, secret := range []string{"webhook-secret", "payment-token", "passport-data", "callback-secret"} {
|
||||
if strings.Contains(got, secret) {
|
||||
t.Errorf("redacted request contains %q: %s", secret, got)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(got, `"chat_id":42`) {
|
||||
t.Errorf("redacted request lost non-sensitive field: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRedactRequestLogOmitsInvalidJSON(t *testing.T) {
|
||||
const secret = "not-json-secret"
|
||||
got := redactRequestLog([]byte(secret))
|
||||
if strings.Contains(got, secret) {
|
||||
t.Fatalf("invalid JSON was logged verbatim: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponseLogSummaryNeverContainsBody(t *testing.T) {
|
||||
const token = "managed-bot-token"
|
||||
got := responseLogSummary("getManagedBotToken", len(token))
|
||||
if strings.Contains(got, token) {
|
||||
t.Fatalf("response summary contains response body: %s", got)
|
||||
}
|
||||
if !strings.Contains(got, "body=omitted") {
|
||||
t.Fatalf("response summary does not explain omission: %s", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user