mirror of
https://gitcode.com/JianFeeeee/webui4frpc.git
synced 2026-09-19 16:38:31 +00:00
- store: Local 增加 useEncryption/useCompression/bandwidthLimit/poolCount/metadatas/annotations;Remote 增加 transportProtocol/transportTls/transportPool/transportTlsServerName;新增 migrate() ALTER TABLE 迁移旧库 - render: 输出 transport 段(protocol/tls/poolCount)与 proxy 高级字段;补 TestRenderTransportAdvanced/OmittedWhenEmpty - main: renderRemote 闭包透传 M1 字段到 render.Proxy - web: LocalNode/RemoteNode 折叠高级区表单,types.ts 接口扩展 - 验证:go test 全绿、vue-tsc/build 通过、端到端 PUT canvas→frpc JSON 输出完整
104 lines
3.2 KiB
Go
104 lines
3.2 KiB
Go
package render
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"webui4frpc/internal/store"
|
|
)
|
|
|
|
func TestRenderTCPProxy(t *testing.T) {
|
|
remote := store.Remote{Name: "srv", IP: "1.2.3.4", Port: 7000, Token: "secret"}
|
|
data, err := Render(remote, []Proxy{
|
|
{Name: "web", Type: "tcp", LocalIP: "127.0.0.1", LocalPort: 8080, RemotePort: 8080},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var cfg Config
|
|
if err := json.Unmarshal(data, &cfg); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg.ServerAddr != "1.2.3.4" || cfg.Auth.Token != "secret" {
|
|
t.Fatalf("cfg = %+v", cfg)
|
|
}
|
|
if len(cfg.Proxies) != 1 || cfg.Proxies[0].RemotePort != 8080 {
|
|
t.Fatalf("proxies = %+v", cfg.Proxies)
|
|
}
|
|
}
|
|
|
|
func TestRenderDuplicateServiceGetsPortSuffix(t *testing.T) {
|
|
remote := store.Remote{Name: "srv", IP: "1.2.3.4", Port: 7000}
|
|
proxy := []Proxy{
|
|
{Name: "web", Type: "tcp", LocalIP: "127.0.0.1", LocalPort: 8080, RemotePort: 8080},
|
|
{Name: "web", Type: "tcp", LocalIP: "127.0.0.1", LocalPort: 8080, RemotePort: 8081},
|
|
}
|
|
data, err := Render(remote, proxy)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var cfg Config
|
|
_ = json.Unmarshal(data, &cfg)
|
|
if len(cfg.Proxies) != 2 {
|
|
t.Fatalf("proxies = %+v", cfg.Proxies)
|
|
}
|
|
if cfg.Proxies[1].Name != "web-8081" {
|
|
t.Fatalf("second proxy name = %q", cfg.Proxies[1].Name)
|
|
}
|
|
}
|
|
|
|
func TestRenderTransportAdvanced(t *testing.T) {
|
|
remote := store.Remote{
|
|
Name: "srv", IP: "1.2.3.4", Port: 7000, Token: "secret",
|
|
TransportProtocol: "kcp", TransportTLS: true, TransportPool: 3, TransportTLSServerName: "frps.local",
|
|
}
|
|
data, err := Render(remote, []Proxy{
|
|
{Name: "web", Type: "tcp", LocalIP: "127.0.0.1", LocalPort: 8080, RemotePort: 8080,
|
|
UseEncryption: true, UseCompression: true, BandwidthLimit: "1MB", PoolCount: 2,
|
|
Metadatas: map[string]string{"env": "prod"}, Annotations: map[string]string{"owner": "ops"}},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var cfg Config
|
|
if err := json.Unmarshal(data, &cfg); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg.Transport.Protocol != "kcp" {
|
|
t.Fatalf("transport.protocol = %q, want kcp", cfg.Transport.Protocol)
|
|
}
|
|
if cfg.Transport.TLS == nil || !cfg.Transport.TLS.Enable || cfg.Transport.TLS.ServerName != "frps.local" {
|
|
t.Fatalf("transport.tls = %+v", cfg.Transport.TLS)
|
|
}
|
|
if cfg.Transport.PoolCount != 3 {
|
|
t.Fatalf("transport.poolCount = %d, want 3", cfg.Transport.PoolCount)
|
|
}
|
|
p := cfg.Proxies[0]
|
|
if !p.UseEncryption || !p.UseCompression || p.BandwidthLimit != "1MB" || p.PoolCount != 2 {
|
|
t.Fatalf("proxy advanced fields = %+v", p)
|
|
}
|
|
if p.Metadatas["env"] != "prod" || p.Annotations["owner"] != "ops" {
|
|
t.Fatalf("proxy metadatas/annotations = %+v", p)
|
|
}
|
|
}
|
|
|
|
func TestRenderTransportOmittedWhenEmpty(t *testing.T) {
|
|
remote := store.Remote{Name: "srv", IP: "1.2.3.4", Port: 7000}
|
|
data, err := Render(remote, []Proxy{
|
|
{Name: "web", Type: "tcp", LocalIP: "127.0.0.1", LocalPort: 8080, RemotePort: 8080},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var cfg Config
|
|
if err := json.Unmarshal(data, &cfg); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg.Transport.Protocol != "" || cfg.Transport.TLS != nil || cfg.Transport.PoolCount != 0 {
|
|
t.Fatalf("transport should be empty, got %+v", cfg.Transport)
|
|
}
|
|
if cfg.Proxies[0].UseEncryption || cfg.Proxies[0].BandwidthLimit != "" {
|
|
t.Fatalf("proxy advanced should be empty, got %+v", cfg.Proxies[0])
|
|
}
|
|
}
|