aboutsummaryrefslogtreecommitdiffstats
path: root/internal/crawler/security_test.go
blob: f4d7b67b2f30d2e8cd90149c7ffb3c982fd533df (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package crawler

import (
	"net/http"
	"net/http/httptest"
	"strings"
	"testing"

	"adammathes.com/neko/internal/safehttp"
)

func TestGetFeedContentLimit(t *testing.T) {
	// Enable local connections for this test
	originalAllowLocal := safehttp.AllowLocal
	safehttp.AllowLocal = true
	defer func() { safehttp.AllowLocal = originalAllowLocal }()

	// 10MB limit expected
	limit := 10 * 1024 * 1024
	// 11MB payload
	size := limit + 1024*1024
	largeBody := strings.Repeat("a", size)

	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(200)
		w.Write([]byte(largeBody))
	}))
	defer ts.Close()

	content := GetFeedContent(ts.URL)

	if len(content) != limit {
		t.Errorf("Expected content length %d, got %d", limit, len(content))
	}
}