mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-12-02 15:46:47 +00:00
chore: clean up duplicate helpers in tests
This commit is contained in:
1 parent
9ab75434a9
commit
b75a776d39
6 files changed
+28
-145
No files matched your search
@@ -96,7 +96,7 @@ func TestInboundAnyTLS_TLS(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func testInboundAnyTLSShadowTLS(t *testing.T, inboundOptions inbound.AnyTLSOption, outboundOptions outbound.AnyTLSOption) {
|
||||
func testInboundAnyTLSUTLS(t *testing.T, inboundOptions inbound.AnyTLSOption, outboundOptions outbound.AnyTLSOption) {
|
||||
t.Parallel()
|
||||
t.Run("Conn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
@@ -124,20 +124,7 @@ func TestInboundAnyTLS_ShadowTLS(t *testing.T) {
|
||||
Fingerprint: tlsFingerprint,
|
||||
ShadowTLSOpts: outbound.ShadowTLSOptions{Password: password, Version: 3},
|
||||
}
|
||||
testInboundAnyTLSShadowTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func testInboundAnyTLSRestls(t *testing.T, inboundOptions inbound.AnyTLSOption, outboundOptions outbound.AnyTLSOption) {
|
||||
t.Parallel()
|
||||
t.Run("Conn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
testInboundAnyTLS(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
t.Run("UConn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
outboundOptions.ClientFingerprint = "chrome"
|
||||
testInboundAnyTLS(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
testInboundAnyTLSUTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func TestInboundAnyTLS_Restls(t *testing.T) {
|
||||
@@ -154,20 +141,7 @@ func TestInboundAnyTLS_Restls(t *testing.T) {
|
||||
Fingerprint: tlsFingerprint,
|
||||
RestlsOpts: outbound.RestlsOptions{Password: password, VersionHint: "tls13"},
|
||||
}
|
||||
testInboundAnyTLSRestls(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func testInboundAnyTLSJLS(t *testing.T, inboundOptions inbound.AnyTLSOption, outboundOptions outbound.AnyTLSOption) {
|
||||
t.Parallel()
|
||||
t.Run("Conn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
testInboundAnyTLS(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
t.Run("UConn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
outboundOptions.ClientFingerprint = "chrome"
|
||||
testInboundAnyTLS(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
testInboundAnyTLSUTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func TestInboundAnyTLS_JLS(t *testing.T) {
|
||||
@@ -185,5 +159,5 @@ func TestInboundAnyTLS_JLS(t *testing.T) {
|
||||
SNI: realityDest,
|
||||
JLSOpts: outbound.JLSOptions{Username: username, Password: password},
|
||||
}
|
||||
testInboundAnyTLSJLS(t, inboundOptions, outboundOptions)
|
||||
testInboundAnyTLSUTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
@@ -108,16 +108,16 @@ func TestInboundShadowSocks_Basic(t *testing.T) {
|
||||
testInboundShadowSocks(t, inboundOptions, outboundOptions, shadowsocksCipherLists, true)
|
||||
}
|
||||
|
||||
func testInboundShadowSocksShadowTls(t *testing.T, inboundOptions inbound.ShadowSocksOption, outboundOptions outbound.ShadowSocksOption) {
|
||||
func testInboundShadowSocksUTLS(t *testing.T, inboundOptions inbound.ShadowSocksOption, outboundOptions outbound.ShadowSocksOption, enableSingMux bool) {
|
||||
t.Parallel()
|
||||
t.Run("Conn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
testInboundShadowSocks(t, inboundOptions, outboundOptions, shadowsocksCipherShortLists, true)
|
||||
testInboundShadowSocks(t, inboundOptions, outboundOptions, shadowsocksCipherShortLists, enableSingMux)
|
||||
})
|
||||
t.Run("UConn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
outboundOptions.ClientFingerprint = "chrome"
|
||||
testInboundShadowSocks(t, inboundOptions, outboundOptions, shadowsocksCipherShortLists, true)
|
||||
testInboundShadowSocks(t, inboundOptions, outboundOptions, shadowsocksCipherShortLists, enableSingMux)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ func TestInboundShadowSocks_ShadowTlsv1(t *testing.T) {
|
||||
Plugin: shadowtls.Mode,
|
||||
PluginOpts: map[string]any{"host": realityDest, "fingerprint": tlsFingerprint, "version": 1},
|
||||
}
|
||||
testInboundShadowSocksShadowTls(t, inboundOptions, outboundOptions)
|
||||
testInboundShadowSocksUTLS(t, inboundOptions, outboundOptions, true)
|
||||
}
|
||||
|
||||
func TestInboundShadowSocks_ShadowTlsv2(t *testing.T) {
|
||||
@@ -150,7 +150,7 @@ func TestInboundShadowSocks_ShadowTlsv2(t *testing.T) {
|
||||
PluginOpts: map[string]any{"host": realityDest, "password": shadowsocksPassword16, "fingerprint": tlsFingerprint, "version": 2},
|
||||
}
|
||||
outboundOptions.PluginOpts["alpn"] = []string{"http/1.1"} // shadowtls v2 work confuse with http/2 server, so we set alpn to http/1.1 to pass the test
|
||||
testInboundShadowSocksShadowTls(t, inboundOptions, outboundOptions)
|
||||
testInboundShadowSocksUTLS(t, inboundOptions, outboundOptions, true)
|
||||
}
|
||||
|
||||
func TestInboundShadowSocks_ShadowTlsv3(t *testing.T) {
|
||||
@@ -166,7 +166,7 @@ func TestInboundShadowSocks_ShadowTlsv3(t *testing.T) {
|
||||
Plugin: shadowtls.Mode,
|
||||
PluginOpts: map[string]any{"host": realityDest, "password": shadowsocksPassword16, "fingerprint": tlsFingerprint, "version": 3},
|
||||
}
|
||||
testInboundShadowSocksShadowTls(t, inboundOptions, outboundOptions)
|
||||
testInboundShadowSocksUTLS(t, inboundOptions, outboundOptions, true)
|
||||
}
|
||||
|
||||
func TestInboundShadowSocks_Restls_tls12(t *testing.T) {
|
||||
@@ -199,19 +199,6 @@ func TestInboundShadowSocks_Restls_tls13(t *testing.T) {
|
||||
testInboundShadowSocks(t, inboundOptions, outboundOptions, shadowsocksCipherShortLists, false)
|
||||
}
|
||||
|
||||
func testInboundShadowSocksJLS(t *testing.T, inboundOptions inbound.ShadowSocksOption, outboundOptions outbound.ShadowSocksOption) {
|
||||
t.Parallel()
|
||||
t.Run("Conn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
testInboundShadowSocks(t, inboundOptions, outboundOptions, shadowsocksCipherShortLists, false)
|
||||
})
|
||||
t.Run("UConn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
outboundOptions.ClientFingerprint = "chrome"
|
||||
testInboundShadowSocks(t, inboundOptions, outboundOptions, shadowsocksCipherShortLists, false)
|
||||
})
|
||||
}
|
||||
|
||||
func TestInboundShadowSocks_JLS(t *testing.T) {
|
||||
username := "jls-user"
|
||||
password := "jls-password"
|
||||
@@ -231,7 +218,7 @@ func TestInboundShadowSocks_JLS(t *testing.T) {
|
||||
"password": password,
|
||||
},
|
||||
}
|
||||
testInboundShadowSocksJLS(t, inboundOptions, outboundOptions)
|
||||
testInboundShadowSocksUTLS(t, inboundOptions, outboundOptions, false)
|
||||
}
|
||||
|
||||
func TestInboundShadowSocks_SimpleObfs_Http(t *testing.T) {
|
||||
|
||||
@@ -78,7 +78,7 @@ func TestInboundSnell(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testInboundSnellTLS(t *testing.T, inboundOptions inbound.SnellOption, outboundOptions outbound.SnellOption) {
|
||||
func testInboundSnellUTLS(t *testing.T, inboundOptions inbound.SnellOption, outboundOptions outbound.SnellOption) {
|
||||
t.Parallel()
|
||||
t.Run("Conn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
@@ -105,7 +105,7 @@ func TestInboundSnell_ShadowTlsv2(t *testing.T) {
|
||||
ObfsOpts: map[string]any{"mode": shadowtls.Mode, "host": realityDest, "password": shadowsocksPassword16, "fingerprint": tlsFingerprint, "version": 2},
|
||||
}
|
||||
outboundOptions.ObfsOpts["alpn"] = []string{"http/1.1"} // shadowtls v2 work confuse with http/2 server, so we set alpn to http/1.1 to pass the test
|
||||
testInboundSnellTLS(t, inboundOptions, outboundOptions)
|
||||
testInboundSnellUTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func TestInboundSnell_ShadowTlsv3(t *testing.T) {
|
||||
@@ -121,7 +121,7 @@ func TestInboundSnell_ShadowTlsv3(t *testing.T) {
|
||||
Version: 5,
|
||||
ObfsOpts: map[string]any{"mode": shadowtls.Mode, "host": realityDest, "password": shadowsocksPassword16, "fingerprint": tlsFingerprint, "version": 3},
|
||||
}
|
||||
testInboundSnellTLS(t, inboundOptions, outboundOptions)
|
||||
testInboundSnellUTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func TestInboundSnell_Restls(t *testing.T) {
|
||||
@@ -137,7 +137,7 @@ func TestInboundSnell_Restls(t *testing.T) {
|
||||
Version: 5,
|
||||
ObfsOpts: map[string]any{"mode": restls.Mode, "host": realityDest, "password": password, "fingerprint": tlsFingerprint, "version-hint": "tls13"},
|
||||
}
|
||||
testInboundSnellTLS(t, inboundOptions, outboundOptions)
|
||||
testInboundSnellUTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func TestInboundSnell_JLS(t *testing.T) {
|
||||
@@ -155,5 +155,5 @@ func TestInboundSnell_JLS(t *testing.T) {
|
||||
Version: 5,
|
||||
ObfsOpts: map[string]any{"mode": jls.Mode, "host": realityDest, "username": username, "password": password},
|
||||
}
|
||||
testInboundSnellTLS(t, inboundOptions, outboundOptions)
|
||||
testInboundSnellUTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
@@ -168,7 +168,7 @@ func TestInboundTrojan_Grpc2(t *testing.T) {
|
||||
testInboundTrojanTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func testInboundTrojanShadowTLS(t *testing.T, inboundOptions inbound.TrojanOption, outboundOptions outbound.TrojanOption) {
|
||||
func testInboundTrojanUTLS(t *testing.T, inboundOptions inbound.TrojanOption, outboundOptions outbound.TrojanOption) {
|
||||
t.Parallel()
|
||||
t.Run("Conn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
@@ -196,20 +196,7 @@ func TestInboundTrojan_ShadowTLS(t *testing.T) {
|
||||
Fingerprint: tlsFingerprint,
|
||||
ShadowTLSOpts: outbound.ShadowTLSOptions{Password: password, Version: 3},
|
||||
}
|
||||
testInboundTrojanShadowTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func testInboundTrojanRestls(t *testing.T, inboundOptions inbound.TrojanOption, outboundOptions outbound.TrojanOption) {
|
||||
t.Parallel()
|
||||
t.Run("Conn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
testInboundTrojan(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
t.Run("UConn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
outboundOptions.ClientFingerprint = "chrome"
|
||||
testInboundTrojan(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
testInboundTrojanUTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func TestInboundTrojan_Restls(t *testing.T) {
|
||||
@@ -226,20 +213,7 @@ func TestInboundTrojan_Restls(t *testing.T) {
|
||||
Fingerprint: tlsFingerprint,
|
||||
RestlsOpts: outbound.RestlsOptions{Password: password, VersionHint: "tls13"},
|
||||
}
|
||||
testInboundTrojanRestls(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func testInboundTrojanJLS(t *testing.T, inboundOptions inbound.TrojanOption, outboundOptions outbound.TrojanOption) {
|
||||
t.Parallel()
|
||||
t.Run("Conn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
testInboundTrojan(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
t.Run("UConn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
outboundOptions.ClientFingerprint = "chrome"
|
||||
testInboundTrojan(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
testInboundTrojanUTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func TestInboundTrojan_JLS(t *testing.T) {
|
||||
@@ -257,7 +231,7 @@ func TestInboundTrojan_JLS(t *testing.T) {
|
||||
SNI: realityDest,
|
||||
JLSOpts: outbound.JLSOptions{Username: username, Password: password},
|
||||
}
|
||||
testInboundTrojanJLS(t, inboundOptions, outboundOptions)
|
||||
testInboundTrojanUTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func TestInboundTrojan_Reality(t *testing.T) {
|
||||
|
||||
@@ -278,7 +278,7 @@ func TestInboundVless_Grpc2(t *testing.T) {
|
||||
testInboundVlessTLS(t, inboundOptions, outboundOptions, false)
|
||||
}
|
||||
|
||||
func testInboundVlessShadowTLS(t *testing.T, inboundOptions inbound.VlessOption, outboundOptions outbound.VlessOption) {
|
||||
func testInboundVlessUTLS(t *testing.T, inboundOptions inbound.VlessOption, outboundOptions outbound.VlessOption) {
|
||||
t.Parallel()
|
||||
t.Run("Conn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
@@ -307,20 +307,7 @@ func TestInboundVless_ShadowTLS(t *testing.T) {
|
||||
Fingerprint: tlsFingerprint,
|
||||
ShadowTLSOpts: outbound.ShadowTLSOptions{Password: password, Version: 3},
|
||||
}
|
||||
testInboundVlessShadowTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func testInboundVlessRestls(t *testing.T, inboundOptions inbound.VlessOption, outboundOptions outbound.VlessOption) {
|
||||
t.Parallel()
|
||||
t.Run("Conn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
testInboundVless(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
t.Run("UConn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
outboundOptions.ClientFingerprint = "chrome"
|
||||
testInboundVless(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
testInboundVlessUTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func TestInboundVless_Restls(t *testing.T) {
|
||||
@@ -338,20 +325,7 @@ func TestInboundVless_Restls(t *testing.T) {
|
||||
Fingerprint: tlsFingerprint,
|
||||
RestlsOpts: outbound.RestlsOptions{Password: password, VersionHint: "tls13"},
|
||||
}
|
||||
testInboundVlessRestls(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func testInboundVlessJLS(t *testing.T, inboundOptions inbound.VlessOption, outboundOptions outbound.VlessOption) {
|
||||
t.Parallel()
|
||||
t.Run("Conn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
testInboundVless(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
t.Run("UConn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
outboundOptions.ClientFingerprint = "chrome"
|
||||
testInboundVless(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
testInboundVlessUTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func TestInboundVless_JLS(t *testing.T) {
|
||||
@@ -370,7 +344,7 @@ func TestInboundVless_JLS(t *testing.T) {
|
||||
ServerName: realityDest,
|
||||
JLSOpts: outbound.JLSOptions{Username: username, Password: password},
|
||||
}
|
||||
testInboundVlessJLS(t, inboundOptions, outboundOptions)
|
||||
testInboundVlessUTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func TestInboundVless_Reality(t *testing.T) {
|
||||
|
||||
@@ -502,7 +502,7 @@ func TestInboundVMess_Grpc2(t *testing.T) {
|
||||
testInboundVMessTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func testInboundVMessShadowTLS(t *testing.T, inboundOptions inbound.VmessOption, outboundOptions outbound.VmessOption) {
|
||||
func testInboundVMessUTLS(t *testing.T, inboundOptions inbound.VmessOption, outboundOptions outbound.VmessOption) {
|
||||
t.Parallel()
|
||||
t.Run("Conn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
@@ -531,20 +531,7 @@ func TestInboundVMess_ShadowTLS(t *testing.T) {
|
||||
Fingerprint: tlsFingerprint,
|
||||
ShadowTLSOpts: outbound.ShadowTLSOptions{Password: password, Version: 3},
|
||||
}
|
||||
testInboundVMessShadowTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func testInboundVMessRestls(t *testing.T, inboundOptions inbound.VmessOption, outboundOptions outbound.VmessOption) {
|
||||
t.Parallel()
|
||||
t.Run("Conn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
testInboundVMess(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
t.Run("UConn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
outboundOptions.ClientFingerprint = "chrome"
|
||||
testInboundVMess(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
testInboundVMessUTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func TestInboundVMess_Restls(t *testing.T) {
|
||||
@@ -562,20 +549,7 @@ func TestInboundVMess_Restls(t *testing.T) {
|
||||
Fingerprint: tlsFingerprint,
|
||||
RestlsOpts: outbound.RestlsOptions{Password: password, VersionHint: "tls13"},
|
||||
}
|
||||
testInboundVMessRestls(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func testInboundVMessJLS(t *testing.T, inboundOptions inbound.VmessOption, outboundOptions outbound.VmessOption) {
|
||||
t.Parallel()
|
||||
t.Run("Conn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
testInboundVMess(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
t.Run("UConn", func(t *testing.T) {
|
||||
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||
outboundOptions.ClientFingerprint = "chrome"
|
||||
testInboundVMess(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
testInboundVMessUTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func TestInboundVMess_JLS(t *testing.T) {
|
||||
@@ -594,7 +568,7 @@ func TestInboundVMess_JLS(t *testing.T) {
|
||||
ServerName: realityDest,
|
||||
JLSOpts: outbound.JLSOptions{Username: username, Password: password},
|
||||
}
|
||||
testInboundVMessJLS(t, inboundOptions, outboundOptions)
|
||||
testInboundVMessUTLS(t, inboundOptions, outboundOptions)
|
||||
}
|
||||
|
||||
func TestInboundVMess_Reality(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user