ce7cb702218693d08ea6d83464d2457c9250027c
This commit is contained in:
commit
34c5f8963c
1 changed files with 145336 additions and 0 deletions
23
services/stalwart/cmd/controller/http_error_test.go
Normal file
23
services/stalwart/cmd/controller/http_error_test.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestResponseStatusErrorIncludesBoundedRedactedDetail(t *testing.T) {
|
||||
secret := "synthetic-secret"
|
||||
response := &http.Response{
|
||||
StatusCode: http.StatusBadRequest,
|
||||
Body: io.NopCloser(strings.NewReader(`{"errors":["invalid synthetic-secret"]}` + strings.Repeat("x", 8192))),
|
||||
}
|
||||
err := responseStatusError("synthetic request", response, secret)
|
||||
if err == nil || !strings.Contains(err.Error(), "HTTP 400") || !strings.Contains(err.Error(), "[redacted]") {
|
||||
t.Fatalf("error = %v", err)
|
||||
}
|
||||
if strings.Contains(err.Error(), secret) || len(err.Error()) > 4200 {
|
||||
t.Fatalf("error is unbounded or contains a secret: %v", err)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue