Files
admin 860fb66442
Build way-node / Test, Build, Push (push) Failing after 14s
feat: way-node — 完整更名与 Gitea CI
- Go module: github.com/cedar2025/xboard-node → github.com/viaeon/way-node(307 处 import 同步)
- cmd/xboard-node/ → cmd/way-node/
- install.sh: APP_NAME / INSTALL_ROOT(/etc/way-node) / BINARY_PATH / SERVICE_NAME 全部更名,
  下载源与 Documentaion 指向 git.viaeon.com/admin/way-node
- Makefile / Dockerfile 产物与镜像路径更名
- README 全篇重写链接
- 新增 .gitea/workflows/build.yml:容器内跑测试 + 交叉编译 + 构建镜像推 git.viaeon.com/admin/way-node
  构建全程在 golang:1.26 容器里,不依赖 runner 宿主装 Go
- 禁用 .github/workflows/ci.yml(依赖 ghcr.io 与 GITHUB_TOKEN,Gitea 上跑不通)

保留:xbctl 工具名(不含旧品牌)、go.sum 里上游依赖哈希
2026-11-27 11:41:30 +08:00

96 lines
3.9 KiB
Go

package controlplane
import (
"context"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/viaeon/way-node/internal/config"
panelapi "github.com/viaeon/way-node/internal/panel"
)
func TestPanelControlPlaneInitialRejectsInvalidCustomOutbounds(t *testing.T) {
server := newPanelTestServer(`{"protocol":"shadowsocks","server_port":8388,"custom_outbounds":[{"tag":"proxy","protocol":"socks","proxy_tag":"missing","settings":{"server":"2.2.2.2","server_port":1080}}]}`)
defer server.Close()
cp := NewPanelControlPlane(config.PanelConfig{URL: server.URL, Token: "token", NodeID: 1}, config.WSConfig{}, config.KernelConfig{Type: "singbox"})
_, err := cp.Initial(context.Background(), nil, nil, nil)
if err == nil {
t.Fatal("expected error, got nil")
}
if !strings.Contains(err.Error(), `initial config normalize: validate custom outbounds: custom_outbounds[0].proxy_tag references unknown outbound "missing"`) {
t.Fatalf("unexpected error: %v", err)
}
}
func TestPanelControlPlanePollRejectsInvalidCustomOutbounds(t *testing.T) {
server := newPanelTestServer(`{"protocol":"shadowsocks","server_port":8388,"custom_outbounds":[{"tag":"proxy","protocol":"socks","proxy_tag":"missing","settings":{"server":"2.2.2.2","server_port":1080}}]}`)
defer server.Close()
cp := NewPanelControlPlane(config.PanelConfig{URL: server.URL, Token: "token", NodeID: 1}, config.WSConfig{}, config.KernelConfig{Type: "singbox"})
_, err := cp.Poll(context.Background())
if err == nil {
t.Fatal("expected error, got nil")
}
if !strings.Contains(err.Error(), `poll config normalize: validate custom outbounds: custom_outbounds[0].proxy_tag references unknown outbound "missing"`) {
t.Fatalf("unexpected error: %v", err)
}
}
func TestTranslateWSEventRejectsInvalidCustomOutbounds(t *testing.T) {
_, err := TranslateWSEvent(panelapi.WSEvent{
Type: panelapi.WSEventSyncConfig,
Config: &panelapi.NodeConfig{
Protocol: "shadowsocks",
ServerPort: 8388,
CustomOutbounds: []panelapi.OutboundConfig{
{Tag: "proxy", Protocol: "socks", ProxyTag: "missing", Settings: map[string]any{"server": "2.2.2.2", "server_port": 1080}},
},
},
}, config.KernelConfig{Type: "singbox"})
if err == nil {
t.Fatal("expected error, got nil")
}
if !strings.Contains(err.Error(), `translate node config: validate custom outbounds: custom_outbounds[0].proxy_tag references unknown outbound "missing"`) {
t.Fatalf("unexpected error: %v", err)
}
}
func newPanelTestServer(configBody string) *httptest.Server {
mux := http.NewServeMux()
mux.HandleFunc("/api/v2/server/handshake", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"websocket":{"enabled":false},"settings":{"push_interval":60,"pull_interval":60}}`))
})
mux.HandleFunc("/api/v1/server/UniProxy/config", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(configBody))
})
mux.HandleFunc("/api/v1/server/UniProxy/user", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"users":[{"id":1,"uuid":"11111111-1111-1111-1111-111111111111"}]}`))
})
return httptest.NewServer(mux)
}
func TestTranslateWSEventRejectsUnsupportedProtocolForKernel(t *testing.T) {
_, err := TranslateWSEvent(panelapi.WSEvent{
Type: panelapi.WSEventSyncConfig,
Config: &panelapi.NodeConfig{
Protocol: "shadowsocks",
ServerPort: 8388,
CustomOutbounds: []panelapi.OutboundConfig{
{Tag: "hy2", Protocol: "hysteria2", Settings: map[string]any{"server": "2.2.2.2", "server_port": 8443}},
},
},
}, config.KernelConfig{Type: "xray"})
if err == nil {
t.Fatal("expected error, got nil")
}
if !strings.Contains(err.Error(), `translate node config: validate custom outbounds: custom_outbounds[0].protocol "hysteria2" is not supported by kernel "xray"`) {
t.Fatalf("unexpected error: %v", err)
}
}