Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
81 lines
2.4 KiB
Go
81 lines
2.4 KiB
Go
package yunzhijia
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
)
|
|
|
|
func TestDeriveWebSocketURL(t *testing.T) {
|
|
got, err := deriveWebSocketURL(
|
|
"https://dev.kdweibo.cn:8443/gateway/robot/webhook/send?yzjtype=12&yzjtoken=token%20value",
|
|
"kdweibo.cn",
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("deriveWebSocketURL() error = %v", err)
|
|
}
|
|
want := "wss://dev.kdweibo.cn:8443/xuntong/websocket?yzjtoken=token+value"
|
|
if got != want {
|
|
t.Fatalf("deriveWebSocketURL() = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestDeriveWebSocketURLRejectsMissingToken(t *testing.T) {
|
|
_, err := deriveWebSocketURL("https://www.yunzhijia.com/gateway/robot/webhook/send", "yunzhijia.com")
|
|
if err == nil {
|
|
t.Fatal("deriveWebSocketURL() expected missing-token error")
|
|
}
|
|
}
|
|
|
|
func TestValidateEndpointURLHostSuffixBoundary(t *testing.T) {
|
|
valid := []string{
|
|
"https://yunzhijia.com/path",
|
|
"https://www.yunzhijia.com/path",
|
|
}
|
|
for _, rawURL := range valid {
|
|
if _, err := validateEndpointURL(rawURL, "https", "yunzhijia.com"); err != nil {
|
|
t.Errorf("validateEndpointURL(%q) unexpected error: %v", rawURL, err)
|
|
}
|
|
}
|
|
|
|
invalid := []string{
|
|
"http://www.yunzhijia.com/path",
|
|
"https://evilyunzhijia.com/path",
|
|
"https://127.0.0.1/path",
|
|
"https://localhost/path",
|
|
}
|
|
for _, rawURL := range invalid {
|
|
if _, err := validateEndpointURL(rawURL, "https", "yunzhijia.com"); err == nil {
|
|
t.Errorf("validateEndpointURL(%q) expected error", rawURL)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestValidateEndpointURLRequiresHostSuffix(t *testing.T) {
|
|
if _, err := validateEndpointURL("https://www.yunzhijia.com/path", "https", ""); err == nil {
|
|
t.Fatal("validateEndpointURL() expected missing host suffix error")
|
|
}
|
|
}
|
|
|
|
func TestIsPublicIP(t *testing.T) {
|
|
for _, rawIP := range []string{"127.0.0.1", "10.0.0.1", "169.254.169.254", "::1", "fc00::1"} {
|
|
if isPublicIP(net.ParseIP(rawIP)) {
|
|
t.Errorf("isPublicIP(%q) = true, want false", rawIP)
|
|
}
|
|
}
|
|
if !isPublicIP(net.ParseIP("8.8.8.8")) {
|
|
t.Error("isPublicIP(8.8.8.8) = false, want true")
|
|
}
|
|
}
|
|
|
|
func TestPositiveIntCredential(t *testing.T) {
|
|
if got := positiveIntCredential(map[string]any{"timeout": float64(25)}, "timeout", 10); got != 25 {
|
|
t.Fatalf("numeric timeout = %d, want 25", got)
|
|
}
|
|
if got := positiveIntCredential(map[string]any{"timeout": "30"}, "timeout", 10); got != 30 {
|
|
t.Fatalf("string timeout = %d, want 30", got)
|
|
}
|
|
if got := positiveIntCredential(map[string]any{"timeout": float64(0)}, "timeout", 10); got != 10 {
|
|
t.Fatalf("invalid timeout = %d, want fallback 10", got)
|
|
}
|
|
}
|