Skip to content

Commit

Permalink
Add Testing for meek, grpc, httpUpgrade Transport (#3160)
Browse files Browse the repository at this point in the history
* Add instance management based testing

* Add testing for meek transport

* Add testing for grpc, httpupgrade transport
  • Loading branch information
xiaokangwang authored Sep 16, 2024
1 parent 531b353 commit d9181ad
Show file tree
Hide file tree
Showing 16 changed files with 624 additions and 0 deletions.
11 changes: 11 additions & 0 deletions testing/scenarios/cert/self-signed_cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-----BEGIN CERTIFICATE-----
MIIBhDCCASmgAwIBAgIQOGW77bhKIQBVcKBkruQEjDAKBggqhkjOPQQDAjAoMRIw
EAYDVQQKEwlWMlJheSBJbmMxEjAQBgNVBAMTCVYyUmF5IEluYzAeFw0yNDA5MTUx
NjIyMjRaFw0yNDEyMTQxNzIyMjRaMCgxEjAQBgNVBAoTCVYyUmF5IEluYzESMBAG
A1UEAxMJVjJSYXkgSW5jMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEmKTCe3pJ
6qYR8JSt4LHurI9ukGQISTBBLrFw8fDsWTeJielnHZdqgKL9swcC+IF/ikjzbT5W
iP0EGUBGk6wbPKM1MDMwDgYDVR0PAQH/BAQDAgWgMBMGA1UdJQQMMAoGCCsGAQUF
BwMBMAwGA1UdEwEB/wQCMAAwCgYIKoZIzj0EAwIDSQAwRgIhAKIZM1xlaHwSHsZP
V6aN+AbWnoRgwVVJuY4I5q17FY0cAiEAiLr9NkHd9glFz0BzALygvo7gnNpgF69l
DdiZ4828MXY=
-----END CERTIFICATE-----
5 changes: 5 additions & 0 deletions testing/scenarios/cert/self-signed_key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-----BEGIN RSA PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgmkOATgwafiG4sDs/
J1xVZfimvgREFJy0mtZHeGM2O6ehRANCAASYpMJ7eknqphHwlK3gse6sj26QZAhJ
MEEusXDx8OxZN4mJ6Wcdl2qAov2zBwL4gX+KSPNtPlaI/QQZQEaTrBs8
-----END RSA PRIVATE KEY-----
21 changes: 21 additions & 0 deletions testing/scenarios/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"crypto/rand"
"fmt"
"golang.org/x/net/proxy"
"io"
"os"
"os/exec"
Expand Down Expand Up @@ -168,6 +169,26 @@ func withDefaultApps(config *core.Config) *core.Config {
return config
}

func testTCPConnViaSocks(socksPort, testPort net.Port, payloadSize int, timeout time.Duration) func() error {
return func() error {
socksDialer, err := proxy.SOCKS5("tcp", "127.0.0.1:"+socksPort.String(), nil, nil)
if err != nil {
return err
}
destAddr := &net.TCPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(testPort),
}
conn, err := socksDialer.Dial("tcp", destAddr.String())
if err != nil {
return err
}
defer conn.Close()

return testTCPConn2(conn, payloadSize, timeout)()
}
}

func testTCPConn(port net.Port, payloadSize int, timeout time.Duration) func() error {
return func() error {
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
Expand Down
27 changes: 27 additions & 0 deletions testing/scenarios/common_instanceMgr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package scenarios

import (
core "github.com/v2fly/v2ray-core/v5"
"github.com/v2fly/v2ray-core/v5/app/instman"
"github.com/v2fly/v2ray-core/v5/common"
"github.com/v2fly/v2ray-core/v5/common/serial"
"github.com/v2fly/v2ray-core/v5/features/extension"
)

func NewInstanceManagerInstanceConfig() *core.Config {
config := &core.Config{}
config.App = append(config.App, serial.ToTypedMessage(&instman.Config{}))
return config
}

func NewInstanceManagerCoreInstance() (*core.Instance, extension.InstanceManagement) {
coreConfig := NewInstanceManagerInstanceConfig()
instance, err := core.New(coreConfig)
if err != nil {
panic(err)
}
common.Must(instance.Start())
instanceMgr := instance.GetFeature(extension.InstanceManagementType())
InstanceMgrIfce := instanceMgr.(extension.InstanceManagement)
return instance, InstanceMgrIfce
}
7 changes: 7 additions & 0 deletions testing/scenarios/common_instanceMgr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package scenarios

import "testing"

func TestInstanceMgrInit(t *testing.T) {
NewInstanceManagerCoreInstance()
}
45 changes: 45 additions & 0 deletions testing/scenarios/config/grpc_client.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"log": {
"error": {
"level": "Debug",
"type": "Console"
},
"access": {
"type": "None"
}
},
"outbounds": [
{
"protocol": "vmess",
"settings": {
"address": "127.0.0.1",
"port": 17783,
"uuid": "bcc71618-e552-42c2-a2a3-d4c17a9df764"
},
"streamSettings": {
"transport": "grpc",
"transportSettings": {
},
"security": "tls",
"securitySettings": {
"pinnedPeerCertificateChainSha256": [
"kqHyvea27Pn+JiSqA72lhu9IKAKeGR+3yCyA8JR1mug="
],
"allowInsecureIfPinnedPeerCertificate": true
}
}
}
],
"inbounds": [
{
"protocol": "socks",
"settings": {
"udpEnabled": false,
"address": "127.0.0.1",
"packetEncoding": "Packet"
},
"port": 17784,
"listen": "127.0.0.1"
}
]
}
43 changes: 43 additions & 0 deletions testing/scenarios/config/grpc_server.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"log": {
"error": {
"level": "Debug",
"type": "Console"
},
"access": {
"type": "None"
}
},
"outbounds": [
{
"protocol": "freedom"
}
],
"inbounds": [
{
"listen": "127.0.0.1",
"port": 17783,
"protocol": "vmess",
"settings": {
"users": [
"bcc71618-e552-42c2-a2a3-d4c17a9df764"
]
},
"streamSettings": {
"transport": "grpc",
"transportSettings": {
},
"security": "tls",
"securitySettings": {
"certificate": [
{
"usage": "ENCIPHERMENT",
"certificateFile": "cert/self-signed_cert.pem",
"keyFile": "cert/self-signed_key.pem"
}
]
}
}
}
]
}
46 changes: 46 additions & 0 deletions testing/scenarios/config/grpc_servicename_client.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"log": {
"error": {
"level": "Debug",
"type": "Console"
},
"access": {
"type": "None"
}
},
"outbounds": [
{
"protocol": "vmess",
"settings": {
"address": "127.0.0.1",
"port": 17793,
"uuid": "bcc71618-e552-42c2-a2a3-d4c17a9df764"
},
"streamSettings": {
"transport": "grpc",
"transportSettings": {
"serviceName": "0eae44595474"
},
"security": "tls",
"securitySettings": {
"pinnedPeerCertificateChainSha256": [
"kqHyvea27Pn+JiSqA72lhu9IKAKeGR+3yCyA8JR1mug="
],
"allowInsecureIfPinnedPeerCertificate": true
}
}
}
],
"inbounds": [
{
"protocol": "socks",
"settings": {
"udpEnabled": false,
"address": "127.0.0.1",
"packetEncoding": "Packet"
},
"port": 17794,
"listen": "127.0.0.1"
}
]
}
44 changes: 44 additions & 0 deletions testing/scenarios/config/grpc_servicename_server.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"log": {
"error": {
"level": "Debug",
"type": "Console"
},
"access": {
"type": "None"
}
},
"outbounds": [
{
"protocol": "freedom"
}
],
"inbounds": [
{
"listen": "127.0.0.1",
"port": 17793,
"protocol": "vmess",
"settings": {
"users": [
"bcc71618-e552-42c2-a2a3-d4c17a9df764"
]
},
"streamSettings": {
"transport": "grpc",
"transportSettings": {
"serviceName": "0eae44595474"
},
"security": "tls",
"securitySettings": {
"certificate": [
{
"usage": "ENCIPHERMENT",
"certificateFile": "cert/self-signed_cert.pem",
"keyFile": "cert/self-signed_key.pem"
}
]
}
}
}
]
}
46 changes: 46 additions & 0 deletions testing/scenarios/config/httpupgrade_client.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"log": {
"error": {
"level": "Debug",
"type": "Console"
},
"access": {
"type": "None"
}
},
"outbounds": [
{
"protocol": "vmess",
"settings": {
"address": "127.0.0.1",
"port": 17793,
"uuid": "bcc71618-e552-42c2-a2a3-d4c17a9df764"
},
"streamSettings": {
"transport": "httpupgrade",
"transportSettings": {
"path": "b66efc0c7752"
},
"security": "tls",
"securitySettings": {
"pinnedPeerCertificateChainSha256": [
"kqHyvea27Pn+JiSqA72lhu9IKAKeGR+3yCyA8JR1mug="
],
"allowInsecureIfPinnedPeerCertificate": true
}
}
}
],
"inbounds": [
{
"protocol": "socks",
"settings": {
"udpEnabled": false,
"address": "127.0.0.1",
"packetEncoding": "Packet"
},
"port": 17794,
"listen": "127.0.0.1"
}
]
}
44 changes: 44 additions & 0 deletions testing/scenarios/config/httpupgrade_server.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"log": {
"error": {
"level": "Debug",
"type": "Console"
},
"access": {
"type": "None"
}
},
"outbounds": [
{
"protocol": "freedom"
}
],
"inbounds": [
{
"listen": "127.0.0.1",
"port": 17793,
"protocol": "vmess",
"settings": {
"users": [
"bcc71618-e552-42c2-a2a3-d4c17a9df764"
]
},
"streamSettings": {
"transport": "httpupgrade",
"transportSettings": {
"path": "b66efc0c7752"
},
"security": "tls",
"securitySettings": {
"certificate": [
{
"usage": "ENCIPHERMENT",
"certificateFile": "cert/self-signed_cert.pem",
"keyFile": "cert/self-signed_key.pem"
}
]
}
}
}
]
}
Loading

0 comments on commit d9181ad

Please sign in to comment.