feat: import Sea vHost single-server testing release
This commit is contained in:
commit
248badd33e
441 files changed
+63221
No files matched your search
@@ -0,0 +1,60 @@
|
||||
package hosting
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestCronTimeZonesAndCalendar(t *testing.T) {
|
||||
for _, v := range []struct{ expression, zone, after, want string }{{"*/5 * * * *", "Asia/Shanghai", "2026-10-28T00:01:17Z", "2026-10-28T00:05:00Z"}, {"0 8 * * *", "Asia/Shanghai", "2026-10-28T00:00:00Z", "2026-10-29T00:00:00Z"}, {"0 0 * * 7", "UTC", "2026-10-28T00:00:00Z", "2026-11-01T00:00:00Z"}, {"0 0 1 * 1", "UTC", "2026-10-28T00:00:00Z", "2026-11-01T00:00:00Z"}, {"0 0 */2 * 1", "UTC", "2026-10-28T00:00:00Z", "2026-11-09T00:00:00Z"}} {
|
||||
c, e := ParseCron(v.expression, v.zone)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
after, _ := time.Parse(time.RFC3339, v.after)
|
||||
got, e := c.Next(after)
|
||||
if e != nil || got.Format(time.RFC3339) != v.want {
|
||||
t.Fatalf("%s: %s %v", v.expression, got, e)
|
||||
}
|
||||
}
|
||||
for _, expression := range []string{"@hourly", "60 * * * *", "*/0 * * * *", "* * * * 8", "* * 0 * *", "* * * * */-1", "1-2-3 * * * *", "* * * * ;id"} {
|
||||
if _, e := ParseCron(expression, "UTC"); e == nil {
|
||||
t.Fatalf("accepted %q", expression)
|
||||
}
|
||||
}
|
||||
if _, e := ParseCron("* * * * *", "Missing/Zone"); e == nil {
|
||||
t.Fatal("invalid timezone accepted")
|
||||
}
|
||||
}
|
||||
func TestStartupRejectsControlEnvironmentAndPaths(t *testing.T) {
|
||||
for _, key := range []string{"LD_PRELOAD", "ld_library_path", "DYLD_INSERT_LIBRARIES", "PATH", "BASH_ENV", "PORT", "A=B"} {
|
||||
v := Startup{Environment: map[string]string{key: "x"}}
|
||||
if v.Validate() == nil {
|
||||
t.Fatalf("accepted %s", key)
|
||||
}
|
||||
}
|
||||
for _, entry := range []string{"../other/app.py", "/etc/passwd", ".sea-runtime/config", "app;id", "a/../../secret"} {
|
||||
v := Startup{EntryFile: entry}
|
||||
if v.Validate() == nil {
|
||||
t.Fatalf("accepted %s", entry)
|
||||
}
|
||||
}
|
||||
v := Startup{Environment: map[string]string{"APP_KEY": "a'$(id)`x`"}, Arguments: []string{"a b", "$(id)"}}
|
||||
if e := v.Validate(); e != nil {
|
||||
t.Fatal("literal values should not be shell parsed", e)
|
||||
}
|
||||
}
|
||||
func TestWebsiteRejectsNginxInjection(t *testing.T) {
|
||||
for _, value := range []string{"https://example.com/;root /etc;", "https://user:pass@example.com/", "https://example.com/$request_uri", "https://example.com/\nreturn 200"} {
|
||||
v := DefaultWebsite()
|
||||
v.RedirectURL = value
|
||||
if v.Validate() == nil {
|
||||
t.Fatalf("accepted %s", value)
|
||||
}
|
||||
}
|
||||
v := DefaultWebsite()
|
||||
v.Error503 = "../other/secret.html"
|
||||
if v.Validate() == nil {
|
||||
t.Fatal("traversing error page accepted")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user