Очередь job получила lease и fencing, телеметрия и прогресс deploy сохраняются, ревизия пишет manifest входов. Обновление префиксов не переписывает неизменённый снимок, большие наборы идут через COPY, а устаревшая ревизия не попадает в deploy. Бандл ноды кэшируется, prune и постановка job больше не держат горячий путь. Co-authored-by: Cursor <cursoragent@cursor.com>
80 lines
2.2 KiB
Go
80 lines
2.2 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"compress/gzip"
|
|
"context"
|
|
"errors"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"evobgp/internal/store"
|
|
)
|
|
|
|
func TestReadCDNBodyLimit(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
extra int64
|
|
large bool
|
|
}{
|
|
{"exact limit", 0, false},
|
|
{"one byte too large", 1, true},
|
|
}
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
reader := io.MultiReader(io.LimitReader(strings.NewReader(strings.Repeat("x", cdnBodyLimit)), cdnBodyLimit), strings.NewReader(strings.Repeat("y", int(tc.extra))))
|
|
body, err := ReadCDNBody(reader)
|
|
if tc.large {
|
|
if !errors.Is(err, ErrCDNBodyTooLarge) || body != nil {
|
|
t.Fatalf("body=%d err=%v", len(body), err)
|
|
}
|
|
} else if err != nil || len(body) != cdnBodyLimit {
|
|
t.Fatalf("body=%d err=%v", len(body), err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFetchCDNSourceRowsRejectsOversizedBody(t *testing.T) {
|
|
t.Setenv("EVOBGP_CDN_ALLOW_PRIVATE", "1")
|
|
srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
_, _ = io.Copy(w, strings.NewReader(strings.Repeat("x", cdnBodyLimit+1)))
|
|
}))
|
|
defer srv.Close()
|
|
_, err := fetchCDNSourceRows(context.Background(), nil, srv.Client(), "", "", nil,
|
|
&store.CDNSource{ID: "source", URL: srv.URL, SourceKind: "plain"}, modulePrior{}, time.Now())
|
|
if !errors.Is(err, ErrCDNBodyTooLarge) {
|
|
t.Fatalf("oversized CDN source must fail: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestCDNTransportBoundsDecodedGzipBody(t *testing.T) {
|
|
t.Setenv("EVOBGP_CDN_ALLOW_PRIVATE", "1")
|
|
srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
w.Header().Set("Content-Encoding", "gzip")
|
|
zw := gzip.NewWriter(w)
|
|
_, _ = io.Copy(zw, io.LimitReader(strings.NewReader(strings.Repeat("x", cdnBodyLimit+1)), cdnBodyLimit+1))
|
|
_ = zw.Close()
|
|
}))
|
|
defer srv.Close()
|
|
|
|
client, err := secureCDNClient(srv.Client())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
resp, err := client.Get(srv.URL)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer func() { _ = resp.Body.Close() }()
|
|
if !resp.Uncompressed {
|
|
t.Fatal("expected net/http gzip decompression")
|
|
}
|
|
if _, err := ReadCDNBody(resp.Body); !errors.Is(err, ErrCDNBodyTooLarge) {
|
|
t.Fatalf("oversized decoded body: %v", err)
|
|
}
|
|
}
|