test(listener): allow HTTP/SOCKS; keep excluding tun/tproxy/mixed

This commit is contained in:
kazeyukiro committed 2026-10-07 16:47:54 +00:00
1 parent a46b3b010b
commit a534463c18
2 files changed
+32 -3

No files matched your search

+17 -2
View File
@@ -48,9 +48,24 @@ func TestGenerateConfigYAML(t *testing.T) {
}
func TestGenerateConfigYAMLRejectsExcludedProtocol(t *testing.T) {
_, err := listener.GenerateConfigYAML([]models.Listener{{Name: "socks", Type: "socks", Protocol: "socks", Listen: "0.0.0.0", Port: "1080", Enabled: true}})
_, err := listener.GenerateConfigYAML([]models.Listener{{Name: "tun-bad", Type: "tun", Protocol: "tun", Listen: "0.0.0.0", Port: "1080", Enabled: true}})
if err == nil {
t.Fatal("expected excluded SOCKS listener protocol to be rejected")
t.Fatal("expected excluded TUN listener protocol to be rejected")
}
}
func TestGenerateConfigYAMLAcceptsHTTPAndSOCKS(t *testing.T) {
for _, protocol := range []string{"http", "socks"} {
yamlStr, err := listener.GenerateConfigYAML([]models.Listener{{
Name: "proxy-" + protocol, Type: protocol, Protocol: protocol,
Listen: "0.0.0.0", Port: "1080", Enabled: true, UDP: protocol == "socks",
}})
if err != nil {
t.Fatalf("%s: %v", protocol, err)
}
if !contains(yamlStr, "type: "+protocol) {
t.Fatalf("%s: expected type in yaml, got %q", protocol, yamlStr)
}
}
}
@@ -116,8 +116,22 @@ func TestGenerateShadowQUICUsesCredentialsAsList(t *testing.T) {
}
}
func TestGenerateListenersAcceptsHTTPAndSOCKS(t *testing.T) {
for _, protocol := range []string{"http", "socks"} {
result, err := generateListeners(nil, []models.Listener{{
Name: "p-" + protocol, Protocol: protocol, Port: "1080", Enabled: true, UDP: protocol == "socks",
}}, nil)
if err != nil {
t.Fatalf("%s: %v", protocol, err)
}
if len(result) != 1 || result[0]["type"] != protocol {
t.Fatalf("%s: unexpected result %#v", protocol, result)
}
}
}
func TestGenerateListenersRejectsExcludedProtocols(t *testing.T) {
for _, protocol := range []string{"socks", "http", "tproxy", "redir", "mixed", "tunnel", "tun", "wireguard"} {
for _, protocol := range []string{"tproxy", "redir", "mixed", "tunnel", "tun", "wireguard"} {
_, err := generateListeners(nil, []models.Listener{{Name: "bad", Protocol: protocol, Port: "1080", Enabled: true}}, nil)
if err == nil {
t.Fatalf("expected protocol %q to be rejected", protocol)