41 lines
1.5 KiB
Go
41 lines
1.5 KiB
Go
package xray
|
|
|
|
import "testing"
|
|
|
|
func TestParseVLESS(t *testing.T) {
|
|
raw := "vless://11111111-1111-1111-1111-111111111111@example.com:443?encryption=none&flow=xtls-rprx-vision&security=reality&sni=www.cloudflare.com&fp=chrome&pbk=PUBLIC&sid=abcd&type=tcp#EU"
|
|
link, err := Parse(raw)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if link.Protocol != "vless" || link.Address != "example.com" || link.Port != 443 {
|
|
t.Fatalf("%+v", link)
|
|
}
|
|
if link.TLS != "reality" || link.PBK != "PUBLIC" || link.Flow != "xtls-rprx-vision" {
|
|
t.Fatalf("%+v", link)
|
|
}
|
|
}
|
|
|
|
func TestParseTrojan(t *testing.T) {
|
|
raw := "trojan://secret@1.2.3.4:443?security=tls&sni=example.com&type=ws&path=%2Fws&host=example.com#tr"
|
|
link, err := Parse(raw)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if link.UUID != "secret" || link.Network != "ws" || link.Path != "/ws" {
|
|
t.Fatalf("%+v", link)
|
|
}
|
|
}
|
|
|
|
func TestParseVMess(t *testing.T) {
|
|
// {"v":"2","ps":"n","add":"1.2.3.4","port":"443","id":"11111111-1111-1111-1111-111111111111","aid":"0","scy":"auto","net":"tcp","type":"none","host":"","path":"","tls":"tls","sni":"example.com"}
|
|
b64 := "eyJ2IjoiMiIsInBzIjoibiIsImFkZCI6IjEuMi4zLjQiLCJwb3J0IjoiNDQzIiwiaWQiOiIxMTExMTExMS0xMTExLTExMTEtMTExMS0xMTExMTExMTExMTEiLCJhaWQiOiIwIiwic2N5IjoiYXV0byIsIm5ldCI6InRjcCIsInR5cGUiOiJub25lIiwiaG9zdCI6IiIsInBhdGgiOiIiLCJ0bHMiOiJ0bHMiLCJzbmkiOiJleGFtcGxlLmNvbSJ9"
|
|
link, err := Parse("vmess://" + b64)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if link.Address != "1.2.3.4" || link.Port != 443 || link.TLS != "tls" {
|
|
t.Fatalf("%+v", link)
|
|
}
|
|
}
|