Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Dec 20, 2024
1 parent d46455e commit f63d2b9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 36 deletions.
60 changes: 31 additions & 29 deletions client/go/outline/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,67 +20,70 @@ import (
"github.com/stretchr/testify/require"
)


func Test_NewClientFromJSON_Success(t *testing.T) {
tests := []struct {
name string
input string
name string
input string
firstHop string
}{
{
name: "SS URL",
input: "ss://[email protected]:4321/",
name: "SS URL",
input: "ss://[email protected]:4321/",
firstHop: "example.com:4321",
}, {
name: "Legacy JSON",
input:
`{
name: "Legacy JSON",
input: `{
"server": "example.com",
"server_port": 4321,
"method": "chacha20-ietf-poly1305",
"password": "SECRET"
}`,
},{
name: "Flexible JSON",
input:
`{
firstHop: "example.com:4321",
}, {
name: "Flexible JSON",
input: `{
# Comment
server: example.com,
server_port: 4321,
method: chacha20-ietf-poly1305,
password: SECRET
}`,
},{
name: "YAML",
input:
`# Comment
firstHop: "example.com:4321",
}, {
name: "YAML",
input: `# Comment
server: example.com
server_port: 4321
method: chacha20-ietf-poly1305
password: SECRET`,
},{
name: "Explicit endpoint",
input:
`$type: ss
firstHop: "example.com:4321",
}, {
name: "Explicit endpoint",
input: `$type: ss
endpoint:
$type: dial
address: canary.getoutline.org:443
address: example.com:4321
cipher: chacha20-ietf-poly1305
secret: SECRET`,
},{
name: "Explicit endpoint",
input:
`$type: ss
firstHop: "example.com:4321",
}, {
name: "Multi-hop",
input: `$type: ss
endpoint:
$type: dial
address: example.com:4321
dialer: ss://[email protected]:4321/
address: exit.example.com:4321
dialer: ss://Y2hhY2hhMjAtaWV0Zi1wb2x5MTMwNTpTRUNSRVQ@entry.example.com:4321/
cipher: chacha20-ietf-poly1305
secret: SECRET`,
},
firstHop: "entry.example.com:4321",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := NewClient(tt.input)
require.Nil(t, result.Error)
require.Equal(t, tt.firstHop, result.Client.Dialer.FirstHop)
require.Equal(t, tt.firstHop, result.Client.PacketListener.FirstHop)
})
}
}
Expand Down Expand Up @@ -145,4 +148,3 @@ func Test_NewClientFromJSON_Errors(t *testing.T) {
})
}
}

2 changes: 1 addition & 1 deletion client/go/outline/config/shadowsocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func parseShadowsocksLegacyBase64URL(url url.URL) (*ShadowsocksConfig, error) {
return nil, errors.New("invalid cipher info: no ':' separator")
}
return &ShadowsocksConfig{
Endpoint: DialEndpointConfig{Address: newURL.Host},
Endpoint: newURL.Host,
Cipher: cipherName,
Secret: secret,
Prefix: newURL.Query().Get("prefix"),
Expand Down
12 changes: 6 additions & 6 deletions client/go/outline/config/shadowsocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,38 @@ func TestParseShadowsocksURLFullyEncoded(t *testing.T) {
encoded := base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString([]byte("aes-256-gcm:[email protected]:1234?prefix=HTTP%2F1.1%20"))
config, err := parseShadowsocksConfig("ss://" + string(encoded) + "#outline-123")
require.NoError(t, err)
require.Equal(t, "example.com:1234", config.Endpoint.(DialEndpointConfig).Address)
require.Equal(t, "example.com:1234", config.Endpoint)
require.Equal(t, "HTTP/1.1 ", config.Prefix)
}

func TestParseShadowsocksURLUserInfoEncoded(t *testing.T) {
encoded := base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString([]byte("aes-256-gcm:1234567"))
config, err := parseShadowsocksConfig("ss://" + string(encoded) + "@example.com:1234?prefix=HTTP%2F1.1%20" + "#outline-123")
require.NoError(t, err)
require.Equal(t, "example.com:1234", config.Endpoint.(DialEndpointConfig).Address)
require.Equal(t, "example.com:1234", config.Endpoint)
require.Equal(t, "HTTP/1.1 ", config.Prefix)
}

func TestParseShadowsocksURLUserInfoLegacyEncoded(t *testing.T) {
encoded := base64.StdEncoding.EncodeToString([]byte("aes-256-gcm:shadowsocks"))
config, err := parseShadowsocksConfig("ss://" + string(encoded) + "@example.com:1234?prefix=HTTP%2F1.1%20" + "#outline-123")
require.NoError(t, err)
require.Equal(t, "example.com:1234", config.Endpoint.(DialEndpointConfig).Address)
require.Equal(t, "example.com:1234", config.Endpoint)
require.Equal(t, "HTTP/1.1 ", config.Prefix)
}

func TestLegacyEncodedShadowsocksURL(t *testing.T) {
configString := "ss://[email protected]:1234"
config, err := parseShadowsocksConfig(configString)
require.NoError(t, err)
require.Equal(t, "example.com:1234", config.Endpoint.(DialEndpointConfig).Address)
require.Equal(t, "example.com:1234", config.Endpoint)
}

func TestParseShadowsocksURLNoEncoding(t *testing.T) {
configString := "ss://aes-256-gcm:[email protected]:1234"
config, err := parseShadowsocksConfig(configString)
require.NoError(t, err)
require.Equal(t, "example.com:1234", config.Endpoint.(DialEndpointConfig).Address)
require.Equal(t, "example.com:1234", config.Endpoint)
}

func TestParseShadowsocksURLInvalidCipherInfoFails(t *testing.T) {
Expand All @@ -75,6 +75,6 @@ func TestParseShadowsocksLegacyBase64URL(t *testing.T) {
encoded := base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString([]byte("aes-256-gcm:[email protected]:1234?prefix=HTTP%2F1.1%20"))
config, err := parseShadowsocksConfig("ss://" + string(encoded) + "#outline-123")
require.NoError(t, err)
require.Equal(t, "example.com:1234", config.Endpoint.(DialEndpointConfig).Address)
require.Equal(t, "example.com:1234", config.Endpoint)
require.Equal(t, "HTTP/1.1 ", config.Prefix)
}

0 comments on commit f63d2b9

Please sign in to comment.