mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-12-06 01:53:42 +01:00
35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
package model
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/oapi-codegen/nullable"
|
|
"github.com/phishingclub/phishingclub/vo"
|
|
)
|
|
|
|
func TestValidateWebhookURL(t *testing.T) {
|
|
ok := []string{"https://hooks.example.com/x", "http://api-test-server/webhook"}
|
|
for _, u := range ok {
|
|
if err := ValidateWebhookURL(u); err != nil {
|
|
t.Errorf("expected %q to be valid, got %v", u, err)
|
|
}
|
|
}
|
|
bad := []string{"", "file:///etc/passwd", "gopher://x", "javascript:alert(1)", "example.com/hook", "//example.com"}
|
|
for _, u := range bad {
|
|
if err := ValidateWebhookURL(u); err == nil {
|
|
t.Errorf("expected %q to be rejected", u)
|
|
}
|
|
}
|
|
w := &Webhook{
|
|
Name: nullable.NewNullableWithValue(*vo.NewString127Must("hook")),
|
|
URL: nullable.NewNullableWithValue(*vo.NewString1024Must("ftp://example.com")),
|
|
}
|
|
if err := w.Validate(); err == nil {
|
|
t.Fatal("expected webhook with ftp url to be rejected")
|
|
}
|
|
w.URL = nullable.NewNullableWithValue(*vo.NewString1024Must("https://example.com"))
|
|
if err := w.Validate(); err != nil {
|
|
t.Fatalf("expected webhook to validate, got %v", err)
|
|
}
|
|
}
|