Files

41 lines
860 B
Go
Raw Permalink Normal View History

package woocommerce
import (
"errors"
"testing"
)
func TestNormalizeStoreURLHTTPS(t *testing.T) {
got, err := NormalizeStoreURL("https://example.com/shop/")
if err != nil {
t.Fatal(err)
}
if got != "https://example.com/shop" {
t.Fatalf("got %q", got)
}
}
func TestNormalizeStoreURLBlocksPrivateIP(t *testing.T) {
_, err := NormalizeStoreURL("https://192.168.1.10")
if !errors.Is(err, ErrBlockedStoreURL) {
t.Fatalf("expected blocked, got %v", err)
}
}
func TestNormalizeStoreURLRejectsPlainHTTPRemote(t *testing.T) {
_, err := NormalizeStoreURL("http://example.com")
if err == nil {
t.Fatal("expected error")
}
}
func TestNormalizeStoreURLAllowsLocalhostHTTP(t *testing.T) {
got, err := NormalizeStoreURL("http://127.0.0.1:8080")
if err != nil {
t.Fatal(err)
}
if got != "http://127.0.0.1:8080" {
t.Fatalf("got %q", got)
}
}