-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,403 additions
and
570 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,211 @@ | |
|
||
package outline | ||
|
||
import "testing" | ||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_NewTransport_SS_URL(t *testing.T) { | ||
config := "ss://[email protected]:4321/" | ||
firstHop := "example.com:4321" | ||
|
||
result := NewClient(config) | ||
require.Nil(t, result.Error, "Got %v", result.Error) | ||
require.Equal(t, firstHop, result.Client.sd.FirstHop) | ||
require.Equal(t, firstHop, result.Client.pl.FirstHop) | ||
} | ||
|
||
func Test_NewTransport_Legacy_JSON(t *testing.T) { | ||
config := `{ | ||
"server": "example.com", | ||
"server_port": 4321, | ||
"method": "chacha20-ietf-poly1305", | ||
"password": "SECRET" | ||
}` | ||
firstHop := "example.com:4321" | ||
|
||
result := NewClient(config) | ||
require.Nil(t, result.Error, "Got %v", result.Error) | ||
require.Equal(t, firstHop, result.Client.sd.FirstHop) | ||
require.Equal(t, firstHop, result.Client.pl.FirstHop) | ||
} | ||
|
||
func Test_NewTransport_Flexible_JSON(t *testing.T) { | ||
config := `{ | ||
# Comment | ||
server: example.com, | ||
server_port: 4321, | ||
method: chacha20-ietf-poly1305, | ||
password: SECRET | ||
}` | ||
firstHop := "example.com:4321" | ||
|
||
result := NewClient(config) | ||
require.Nil(t, result.Error, "Got %v", result.Error) | ||
require.Equal(t, firstHop, result.Client.sd.FirstHop) | ||
require.Equal(t, firstHop, result.Client.pl.FirstHop) | ||
} | ||
|
||
func Test_NewTransport_YAML(t *testing.T) { | ||
config := `# Comment | ||
server: example.com | ||
server_port: 4321 | ||
method: chacha20-ietf-poly1305 | ||
password: SECRET` | ||
firstHop := "example.com:4321" | ||
|
||
result := NewClient(config) | ||
require.Nil(t, result.Error, "Got %v", result.Error) | ||
require.Equal(t, firstHop, result.Client.sd.FirstHop) | ||
require.Equal(t, firstHop, result.Client.pl.FirstHop) | ||
} | ||
|
||
func Test_NewTransport_Explicit_endpoint(t *testing.T) { | ||
config := ` | ||
endpoint: | ||
$parser: dial | ||
address: example.com:4321 | ||
cipher: chacha20-ietf-poly1305 | ||
secret: SECRET` | ||
firstHop := "example.com:4321" | ||
|
||
result := NewClient(config) | ||
require.Nil(t, result.Error, "Got %v", result.Error) | ||
require.Equal(t, firstHop, result.Client.sd.FirstHop) | ||
require.Equal(t, firstHop, result.Client.pl.FirstHop) | ||
} | ||
|
||
func Test_NewTransport_Multihop_URL(t *testing.T) { | ||
config := ` | ||
endpoint: | ||
$parser: dial | ||
address: exit.example.com:4321 | ||
dialer: ss://[email protected]:4321/ | ||
cipher: chacha20-ietf-poly1305 | ||
secret: SECRET` | ||
firstHop := "entry.example.com:4321" | ||
|
||
result := NewClient(config) | ||
require.Nil(t, result.Error, "Got %v", result.Error) | ||
require.Equal(t, firstHop, result.Client.sd.FirstHop) | ||
require.Equal(t, firstHop, result.Client.pl.FirstHop) | ||
} | ||
|
||
func Test_NewTransport_Multihop_Explicit(t *testing.T) { | ||
config := ` | ||
endpoint: | ||
$parser: dial | ||
address: exit.example.com:4321 | ||
dialer: | ||
$parser: shadowsocks | ||
endpoint: entry.example.com:4321 | ||
cipher: chacha20-ietf-poly1305 | ||
secret: ENTRY_SECRET | ||
cipher: chacha20-ietf-poly1305 | ||
secret: EXIT_SECRET` | ||
firstHop := "entry.example.com:4321" | ||
|
||
result := NewClient(config) | ||
require.Nil(t, result.Error, "Got %v", result.Error) | ||
require.Equal(t, firstHop, result.Client.sd.FirstHop) | ||
require.Equal(t, firstHop, result.Client.pl.FirstHop) | ||
} | ||
|
||
func Test_NewTransport_Explicit_TCPUDP(t *testing.T) { | ||
config := ` | ||
$parser: tcpudp | ||
tcp: | ||
$parser: shadowsocks | ||
endpoint: example.com:80 | ||
cipher: chacha20-ietf-poly1305 | ||
secret: SECRET | ||
prefix: "POST " | ||
udp: | ||
$parser: shadowsocks | ||
endpoint: example.com:53 | ||
cipher: chacha20-ietf-poly1305 | ||
secret: SECRET` | ||
|
||
result := NewClient(config) | ||
require.Nil(t, result.Error, "Got %v", result.Error) | ||
require.Equal(t, "example.com:80", result.Client.sd.FirstHop) | ||
require.Equal(t, "example.com:53", result.Client.pl.FirstHop) | ||
} | ||
|
||
func Test_NewTransport_YAML_Reuse(t *testing.T) { | ||
config := ` | ||
$parser: tcpudp | ||
udp: &base | ||
$parser: shadowsocks | ||
endpoint: example.com:4321 | ||
cipher: chacha20-ietf-poly1305 | ||
secret: SECRET | ||
tcp: | ||
<<: *base | ||
prefix: "POST "` | ||
firstHop := "example.com:4321" | ||
|
||
result := NewClient(config) | ||
require.Nil(t, result.Error, "Got %v", result.Error) | ||
require.Equal(t, firstHop, result.Client.sd.FirstHop) | ||
require.Equal(t, firstHop, result.Client.pl.FirstHop) | ||
} | ||
|
||
func Test_NewTransport_YAML_Partial_Reuse(t *testing.T) { | ||
config := ` | ||
$parser: tcpudp | ||
tcp: | ||
$parser: shadowsocks | ||
endpoint: example.com:80 | ||
<<: &cipher | ||
cipher: chacha20-ietf-poly1305 | ||
secret: SECRET | ||
prefix: "POST " | ||
udp: | ||
$parser: shadowsocks | ||
endpoint: example.com:53 | ||
<<: *cipher` | ||
|
||
result := NewClient(config) | ||
require.Nil(t, result.Error, "Got %v", result.Error) | ||
require.Equal(t, "example.com:80", result.Client.sd.FirstHop) | ||
require.Equal(t, "example.com:53", result.Client.pl.FirstHop) | ||
} | ||
|
||
func Test_NewTransport_Unsupported(t *testing.T) { | ||
config := `$parser: unsupported` | ||
result := NewClient(config) | ||
require.Error(t, result.Error, "Got %v", result.Error) | ||
require.Equal(t, "unsupported config", result.Error.Message) | ||
} | ||
|
||
/* | ||
TODO: Add Websocket support | ||
func Test_NewTransport_Websocket(t *testing.T) { | ||
config := ` | ||
$parser: tcpudp | ||
tcp: &base | ||
$parser: shadowsocks | ||
endpoint: | ||
$parser: websocket | ||
url: https://entrypoint.cdn.example.com/tcp | ||
cipher: chacha20-ietf-poly1305 | ||
secret: SECRET | ||
udp: | ||
<<: *base | ||
endpoint: | ||
$parser: websocket | ||
url: https://entrypoint.cdn.example.com/udp` | ||
firstHop := "entrypoint.cdn.example.com:443" | ||
result := NewClient(config) | ||
require.Nil(t, result.Error, "Got %v", result.Error) | ||
require.Equal(t, firstHop, result.Client.sd.FirstHop) | ||
require.Equal(t, firstHop, result.Client.pl.FirstHop) | ||
} | ||
*/ | ||
|
||
func Test_NewClientFromJSON_Errors(t *testing.T) { | ||
tests := []struct { | ||
|
Oops, something went wrong.