feat: add assessment, privacy and support flows
This commit is contained in:
1 parent
ee3738ee73
commit
e4f24fa202
339 files changed
+56454
-1126
No files matched your search
@@ -0,0 +1,52 @@
|
||||
package httpadapter
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLimitAssessmentSignalBodyBoundsFixedAndChunkedBodies(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
contentLength int64
|
||||
}{
|
||||
{name: "content length", contentLength: maxAssessmentSignalBodyBytes + 1},
|
||||
{name: "chunked body", contentLength: -1},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
request := httptest.NewRequest("POST", "/", strings.NewReader(strings.Repeat("x", int(maxAssessmentSignalBodyBytes+1))))
|
||||
request.ContentLength = testCase.contentLength
|
||||
response := httptest.NewRecorder()
|
||||
limitAssessmentSignalBody(response, request)
|
||||
|
||||
body, err := io.ReadAll(request.Body)
|
||||
var limitError *http.MaxBytesError
|
||||
if !errors.As(err, &limitError) {
|
||||
t.Fatalf("ReadAll() error = %v, want MaxBytesError", err)
|
||||
}
|
||||
if int64(len(body)) != maxAssessmentSignalBodyBytes {
|
||||
t.Fatalf("ReadAll() returned %d bytes, want %d", len(body), maxAssessmentSignalBodyBytes)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLimitAssessmentSignalBodyAllowsExactLimit(t *testing.T) {
|
||||
request := httptest.NewRequest("POST", "/", strings.NewReader(strings.Repeat("x", int(maxAssessmentSignalBodyBytes))))
|
||||
response := httptest.NewRecorder()
|
||||
limitAssessmentSignalBody(response, request)
|
||||
|
||||
body, err := io.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadAll() error = %v", err)
|
||||
}
|
||||
if int64(len(body)) != maxAssessmentSignalBodyBytes {
|
||||
t.Fatalf("ReadAll() returned %d bytes, want %d", len(body), maxAssessmentSignalBodyBytes)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user