|
9 | 9 | "path/filepath" |
10 | 10 | "strings" |
11 | 11 | "testing" |
| 12 | + "time" |
12 | 13 |
|
13 | 14 | "github.com/ldm0206/vless-to-http/internal/auth" |
14 | 15 | "github.com/ldm0206/vless-to-http/internal/config" |
@@ -535,6 +536,42 @@ func TestSettingsPatchAndSecrecy(t *testing.T) { |
535 | 536 | } |
536 | 537 | } |
537 | 538 |
|
| 539 | +// The panel edits the core's connection-idle timeout as a duration string, so |
| 540 | +// the settings view and the patch have to agree on that format. |
| 541 | +func TestSettingsPatchProxyTimeout(t *testing.T) { |
| 542 | + ts := newTestServer(t) |
| 543 | + cookie, csrf := ts.login(t, adminPassword) |
| 544 | + headers := [][2]string{{"X-CSRF-Token", csrf}} |
| 545 | + |
| 546 | + resp := ts.do(t, http.MethodGet, "/api/settings", cookie, nil) |
| 547 | + var settings map[string]any |
| 548 | + decodeBody(t, resp, &settings) |
| 549 | + proxy, _ := settings["proxy"].(map[string]any) |
| 550 | + if proxy["timeout"] != "5m0s" { |
| 551 | + t.Fatalf("settings proxy.timeout = %v, want 5m0s", proxy["timeout"]) |
| 552 | + } |
| 553 | + |
| 554 | + resp = ts.do(t, http.MethodPatch, "/api/settings", cookie, |
| 555 | + map[string]any{"proxy": map[string]any{"timeout": "15m"}}, headers...) |
| 556 | + resp.Body.Close() |
| 557 | + if resp.StatusCode != http.StatusOK { |
| 558 | + t.Fatalf("patch = %d", resp.StatusCode) |
| 559 | + } |
| 560 | + if got := ts.store.Get().Proxy.Timeout.D(); got != 15*time.Minute { |
| 561 | + t.Fatalf("proxy timeout = %v, want 15m", got) |
| 562 | + } |
| 563 | + |
| 564 | + bad := ts.do(t, http.MethodPatch, "/api/settings", cookie, |
| 565 | + map[string]any{"proxy": map[string]any{"timeout": "soon"}}, headers...) |
| 566 | + bad.Body.Close() |
| 567 | + if bad.StatusCode != http.StatusBadRequest { |
| 568 | + t.Fatalf("invalid timeout = %d, want 400", bad.StatusCode) |
| 569 | + } |
| 570 | + if got := ts.store.Get().Proxy.Timeout.D(); got != 15*time.Minute { |
| 571 | + t.Fatalf("a rejected patch changed the timeout to %v", got) |
| 572 | + } |
| 573 | +} |
| 574 | + |
538 | 575 | func TestStaticPanelIsServed(t *testing.T) { |
539 | 576 | ts := newTestServer(t) |
540 | 577 | resp := ts.do(t, http.MethodGet, "/", "", nil) |
|
0 commit comments