feat: import Sea vHost single-server testing release

This commit is contained in:
canglan committed 2026-10-30 08:39:10 +08:00
commit 248badd33e
441 files changed
+63221

No files matched your search

@@ -0,0 +1,30 @@
package httpapi
import (
"net/netip"
"testing"
)
func TestWebhookNetworkRestrictions(t *testing.T) {
for _, raw := range []string{"http://example.com/callback", "https://127.0.0.1/cb", "https://[::1]/cb", "https://[::ffff:127.0.0.1]/cb", "https://10.0.0.1/cb", "https://100.64.1.2/cb", "https://169.254.169.254/latest", "https://user:password@example.com/cb", "https://example.com:9443/cb", "https://example.com/cb?token=secret", "https://localhost/cb"} {
if _, e := validateWebhookURL(raw); e == nil {
t.Fatalf("accepted unsafe callback %q", raw)
}
}
if _, e := validateWebhookURL("https://billing.example.com/callback"); e != nil {
t.Fatal(e)
}
for _, ip := range []string{"192.168.1.2", "0.0.0.0", "224.0.0.1", "198.18.0.1", "2001:db8::1", "fc00::1"} {
if publicWebhookIP(netip.MustParseAddr(ip)) {
t.Fatalf("accepted %s", ip)
}
}
}
func TestWebhookSignatureBindsTimeEventAndExactBody(t *testing.T) {
signature := webhookSignature("secret", "100", "event", []byte(`{"id":1}`))
for _, s := range []string{webhookSignature("other", "100", "event", []byte(`{"id":1}`)), webhookSignature("secret", "101", "event", []byte(`{"id":1}`)), webhookSignature("secret", "100", "another", []byte(`{"id":1}`)), webhookSignature("secret", "100", "event", []byte(`{ "id":1}`))} {
if signature == s {
t.Fatal("signature failed to bind request")
}
}
}