github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/node/parser/shadowsocksr_test.go (about)

     1  package parser
     2  
     3  import (
     4  	"context"
     5  	"io"
     6  	"net"
     7  	"net/http"
     8  	"net/url"
     9  	"testing"
    10  
    11  	"github.com/Asutorufa/yuhaiin/pkg/net/dns"
    12  	"github.com/Asutorufa/yuhaiin/pkg/net/netapi"
    13  	pdns "github.com/Asutorufa/yuhaiin/pkg/protos/config/dns"
    14  	"github.com/Asutorufa/yuhaiin/pkg/protos/node/point"
    15  	"github.com/Asutorufa/yuhaiin/pkg/protos/node/protocol"
    16  	"github.com/Asutorufa/yuhaiin/pkg/protos/node/subscribe"
    17  	"github.com/Asutorufa/yuhaiin/pkg/utils/assert"
    18  	"google.golang.org/protobuf/encoding/protojson"
    19  )
    20  
    21  func TestSsrParse(t *testing.T) {
    22  	ssr := []string{
    23  		"ssr://MS4xLjEuMTo1MzphdXRoX2NoYWluX2E6bm9uZTpodHRwX3NpbXBsZTo2YUtkNW9HcDZMcXIvP29iZnNwYXJhbT02YUtkNW9HcDZMcXImcHJvdG9wYXJhbT02YUtkNW9HcDZMcXImcmVtYXJrcz02YUtkNW9HcDZMcXImZ3JvdXA9NmFLZDVvR3A2THFy",
    24  		"ssr://MS4xLjEuMTo1MzphdXRoX2NoYWluX2E6bm9uZTpodHRwX3NpbXBsZTo2YUtkNW9HcDZMcXIvP29iZnNwYXJhbT02YUtkNW9HcDZMcXImcHJvdG9wYXJhbT02YUtkNW9HcDZMcXImcmVtYXJrcz1jMlZqYjI1ayZncm91cD02YUtkNW9HcDZMcXIK",
    25  		"ssr://MS4xLjEuMTo1MzphdXRoX2NoYWluX2E6bm9uZTpodHRwX3NpbXBsZTo2YUtkNW9HcDZMcXIvP29iZnNwYXJhbT02YUtkNW9HcDZMcXImcHJvdG9wYXJhbT02YUtkNW9HcDZMcXImcmVtYXJrcz1jM056YzNOeiZncm91cD1jM056YzNOego",
    26  		"ssr://MjIyLjIyMi4yMjIuMjIyOjQ0MzphdXRoX2FlczEyOF9tZDU6Y2hhY2hhMjAtaWV0ZjpodHRwX3Bvc3Q6ZEdWemRBby8_b2Jmc3BhcmFtPWRHVnpkQW8mcHJvdG9wYXJhbT1kR1Z6ZEFvJnJlbWFya3M9ZEdWemRBbyZncm91cD1kR1Z6ZEFv",
    27  	}
    28  
    29  	for x := range ssr {
    30  		t.Log(Parse(subscribe.Type_shadowsocksr, []byte(ssr[x])))
    31  	}
    32  }
    33  
    34  func TestConnectionSsr(t *testing.T) {
    35  	p := &point.Point{
    36  		Protocols: []*protocol.Protocol{},
    37  	}
    38  
    39  	err := protojson.Unmarshal([]byte(``), p)
    40  	assert.NoError(t, err)
    41  	z, err := point.Dialer(p)
    42  	assert.NoError(t, err)
    43  
    44  	tt := &http.Client{
    45  		Transport: &http.Transport{
    46  			DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
    47  				ad, err := netapi.ParseAddress(netapi.PaseNetwork(network), addr)
    48  				assert.NoError(t, err)
    49  				return z.Conn(ctx, ad)
    50  			},
    51  		},
    52  	}
    53  
    54  	dns, err := dns.New(dns.Config{
    55  		Type: pdns.Type_udp,
    56  		Host: "1.1.1.1:53", Dialer: z})
    57  	assert.NoError(t, err)
    58  
    59  	t.Log(dns.LookupIP(context.TODO(), "www.google.com"))
    60  
    61  	req := http.Request{
    62  		Method: "GET",
    63  		URL: &url.URL{
    64  			Scheme: "http",
    65  			Host:   "ip.sb",
    66  		},
    67  		Header: make(http.Header),
    68  	}
    69  	req.Header.Set("User-Agent", "curl/v2.4.1")
    70  	resp, err := tt.Do(&req)
    71  	if err != nil {
    72  		t.Error(err)
    73  		t.FailNow()
    74  	}
    75  	assert.NoError(t, err)
    76  	defer resp.Body.Close()
    77  	data, err := io.ReadAll(resp.Body)
    78  	assert.NoError(t, err)
    79  	t.Log(string(data))
    80  }