(new): expand runtime APIs
(fix): harden concurrent lifecycle (tests): add regression coverage (doc): update v1.2 guidance
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package tgapi
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -37,3 +40,29 @@ func TestResponseLogSummaryNeverContainsBody(t *testing.T) {
|
||||
t.Fatalf("response summary does not explain omission: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRedactHTTPErrorRemovesTokenAndPreservesCause(t *testing.T) {
|
||||
const token = "123456:secret-token"
|
||||
cause := errors.New("transport failed")
|
||||
original := &url.Error{
|
||||
Op: "Post",
|
||||
URL: "https://api.telegram.org/bot" + token + "/sendMessage",
|
||||
Err: fmt.Errorf("request for %s failed: %w", token, cause),
|
||||
}
|
||||
|
||||
got := redactHTTPError(original, token)
|
||||
if strings.Contains(got.Error(), token) {
|
||||
t.Fatalf("redacted HTTP error contains bot token: %v", got)
|
||||
}
|
||||
if !errors.Is(got, cause) {
|
||||
t.Fatalf("redacted HTTP error lost its cause: %v", got)
|
||||
}
|
||||
|
||||
var gotURLError *url.Error
|
||||
if !errors.As(got, &gotURLError) {
|
||||
t.Fatalf("redacted HTTP error lost url.Error type: %T", got)
|
||||
}
|
||||
if strings.Contains(gotURLError.Error(), token) {
|
||||
t.Fatalf("redacted url.Error contains bot token: %v", gotURLError)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user