Add HTTP size limits
This commit is contained in:
@@ -436,12 +436,18 @@ schema_dir: ./from-config/schemas
|
||||
server:
|
||||
addr: 127.0.0.1:9000
|
||||
artifact_root: ./from-config/artifacts
|
||||
max_request_bytes: 1024
|
||||
max_artifact_bytes: 2048
|
||||
max_response_bytes: 4096
|
||||
`)
|
||||
|
||||
cfg, err := parseServeArgs([]string{
|
||||
"--config", configPath,
|
||||
"--addr", ":7777",
|
||||
"--artifact-root", "./from-cli/artifacts",
|
||||
"--max-request-bytes", "0",
|
||||
"--max-artifact-bytes", "8192",
|
||||
"--max-response-bytes", "16384",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("expected valid args, got %v", err)
|
||||
@@ -462,6 +468,15 @@ server:
|
||||
if cfg.artifactRoot != filepath.Clean("./from-cli/artifacts") {
|
||||
t.Fatalf("expected CLI artifact root override, got %q", cfg.artifactRoot)
|
||||
}
|
||||
if cfg.maxRequestBytes != 0 {
|
||||
t.Fatalf("expected CLI max request bytes override, got %d", cfg.maxRequestBytes)
|
||||
}
|
||||
if cfg.maxArtifactBytes != 8192 {
|
||||
t.Fatalf("expected CLI max artifact bytes override, got %d", cfg.maxArtifactBytes)
|
||||
}
|
||||
if cfg.maxResponseBytes != 16384 {
|
||||
t.Fatalf("expected CLI max response bytes override, got %d", cfg.maxResponseBytes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseServeArgsWithConfigProvidesRequiredDirectoriesAndAddr(t *testing.T) {
|
||||
@@ -472,6 +487,9 @@ schema_dir: ./from-config/schemas
|
||||
server:
|
||||
addr: 127.0.0.1:9000
|
||||
artifact_root: ./from-config/artifacts
|
||||
max_request_bytes: 1024
|
||||
max_artifact_bytes: 2048
|
||||
max_response_bytes: 4096
|
||||
`)
|
||||
|
||||
cfg, err := parseServeArgs([]string{
|
||||
@@ -496,6 +514,72 @@ server:
|
||||
if cfg.artifactRoot != filepath.Clean("./from-config/artifacts") {
|
||||
t.Fatalf("expected artifact root from config, got %q", cfg.artifactRoot)
|
||||
}
|
||||
if cfg.maxRequestBytes != 1024 {
|
||||
t.Fatalf("expected max request bytes from config, got %d", cfg.maxRequestBytes)
|
||||
}
|
||||
if cfg.maxArtifactBytes != 2048 {
|
||||
t.Fatalf("expected max artifact bytes from config, got %d", cfg.maxArtifactBytes)
|
||||
}
|
||||
if cfg.maxResponseBytes != 4096 {
|
||||
t.Fatalf("expected max response bytes from config, got %d", cfg.maxResponseBytes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseServeArgsRejectsNegativeSizeLimits(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
flag string
|
||||
}{
|
||||
{name: "request", flag: "--max-request-bytes"},
|
||||
{name: "artifact", flag: "--max-artifact-bytes"},
|
||||
{name: "response", flag: "--max-response-bytes"},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
_, err := parseServeArgs([]string{
|
||||
"--prompt-dir", "./prompts",
|
||||
tc.flag, "-1",
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("expected negative size limit error")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunAndRenderRejectServeSizeLimitFlags(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
parse func([]string) error
|
||||
}{
|
||||
{
|
||||
name: "run",
|
||||
parse: func(args []string) error {
|
||||
_, err := parseRunArgs(args)
|
||||
return err
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "render",
|
||||
parse: func(args []string) error {
|
||||
_, err := parseRenderArgs(args)
|
||||
return err
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
err := tc.parse([]string{
|
||||
"--prompt-dir", "./prompts",
|
||||
"--prompt", "p",
|
||||
"--input", "a=b",
|
||||
"--max-request-bytes", "1024",
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("expected unsupported flag error")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunAndRenderBuildEquivalentRuntimeOverrideRequestsForSharedFlags(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user