-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(client): introduce extensible YAML config in Go #2306
Open
fortuna
wants to merge
49
commits into
master
Choose a base branch
from
fortuna-ws-config
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 40 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
c615901
Initial Implementation
fortuna a4c894d
Add DialEndpoint
fortuna 0d1b9ec
Wire new config
fortuna e81cb45
Add URL
fortuna 455a2ad
Wire Endpoint
fortuna 5a85e73
Cleanup
fortuna 87eaa89
Tweaks
fortuna fbddc57
Merge branch 'master' into fortuna-ws-config
fortuna 131e564
Progress
fortuna a26708c
Make it work
fortuna 1f89c98
Simplify
fortuna 0aa3dbc
More simplification
fortuna e3738e7
Merge branch 'master' into fortuna-ws-config
fortuna bc20623
Revert Go version
fortuna cde35c5
Progress
fortuna 0128549
Fixes
fortuna e05542f
Fix tests
fortuna 6c199bf
Fix
fortuna dbaf0a2
Add test
fortuna cffd70a
Add default provider
fortuna d46455e
Clean up
fortuna f63d2b9
Update tests
fortuna 8df547f
Revamp config
fortuna 52dcd84
Clean up and TODOs
fortuna 5b80741
Naming
fortuna abcbb42
Clean up test
fortuna 70a4a28
More tests
fortuna 5ed3701
Better test
fortuna 6141ff2
Add tcpudp
fortuna 3962502
More tests
fortuna cacf818
Add Websocket support
fortuna 2c59ed5
Fix
fortuna 7304fdc
Lint fixes
fortuna b3f7dd6
It works!
fortuna 5b0de18
Fix display
fortuna fa05c42
Try Coder
fortuna 79c0a73
Comment
fortuna 24f0544
Remove Websocket
fortuna 777da9b
Merge branch 'master' into fortuna-ws-config
fortuna 612d5db
Fix Android
fortuna ebb993f
Add net
fortuna 01d95d2
Fix Electron
fortuna 486aabb
Review changes
fortuna fdd54d5
Merge branch 'master' into fortuna-ws-config
fortuna 5ab7ea9
fixes
fortuna d18deae
Fix Linux
fortuna b4a6e1f
Fixes
fortuna 025f102
Tests
fortuna 3334519
Lint
fortuna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,204 @@ | |
|
||
package outline | ||
|
||
import "testing" | ||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_NewTransport_SS_URL(t *testing.T) { | ||
config := "ss://[email protected]:4321/" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might want to test multiple new-line separated ss keys, too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't support multiple keys yet. |
||
firstHop := "example.com:4321" | ||
|
||
result := NewClient(config) | ||
require.Nil(t, result.Error, "Got %v", result.Error) | ||
require.Equal(t, firstHop, result.Client.Dialer.FirstHop) | ||
require.Equal(t, firstHop, result.Client.PacketListener.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.Dialer.FirstHop) | ||
require.Equal(t, firstHop, result.Client.PacketListener.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.Dialer.FirstHop) | ||
require.Equal(t, firstHop, result.Client.PacketListener.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.Dialer.FirstHop) | ||
require.Equal(t, firstHop, result.Client.PacketListener.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.Dialer.FirstHop) | ||
require.Equal(t, firstHop, result.Client.PacketListener.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.Dialer.FirstHop) | ||
require.Equal(t, firstHop, result.Client.PacketListener.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.Dialer.FirstHop) | ||
require.Equal(t, firstHop, result.Client.PacketListener.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.Dialer.FirstHop) | ||
require.Equal(t, "example.com:53", result.Client.PacketListener.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.Dialer.FirstHop) | ||
require.Equal(t, firstHop, result.Client.PacketListener.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.Dialer.FirstHop) | ||
require.Equal(t, "example.com:53", result.Client.PacketListener.FirstHop) | ||
} | ||
|
||
/* | ||
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.Dialer.FirstHop) | ||
require.Equal(t, firstHop, result.Client.PacketListener.FirstHop) | ||
} | ||
*/ | ||
|
||
func Test_NewClientFromJSON_Errors(t *testing.T) { | ||
tests := []struct { | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we still accepting the old JSON format here? Existing dynamic keys are still using JSON.