-
Notifications
You must be signed in to change notification settings - Fork 868
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
Fix: Can't use Unix Sockets in Quick Tunnel mode #1367
Open
rhyswilliamsza
wants to merge
4
commits into
cloudflare:master
Choose a base branch
from
rhyswilliamsza:fix/unix-socket-quick-tunnel
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
package tunnel | ||
|
||
import ( | ||
"flag" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func TestHostnameFromURI(t *testing.T) { | ||
|
@@ -15,3 +18,74 @@ func TestHostnameFromURI(t *testing.T) { | |
assert.Equal(t, "", hostnameFromURI("trash")) | ||
assert.Equal(t, "", hostnameFromURI("https://awesomesauce.com")) | ||
} | ||
|
||
func TestShouldRunQuickTunnel(t *testing.T) { | ||
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. I've scoped this specifically to quick tunnels, so it won't test falling through to other tunnel types. |
||
tests := []struct { | ||
name string | ||
flags map[string]string | ||
expectError bool | ||
}{ | ||
{ | ||
name: "Quick tunnel with URL set", | ||
flags: map[string]string{"url": "http://127.0.0.1:8080", "quick-service": "https://fakeapi.trycloudflare.com"}, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "Quick tunnel with unix-socket set", | ||
flags: map[string]string{"unix-socket": "/tmp/socket", "quick-service": "https://fakeapi.trycloudflare.com"}, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "Quick tunnel with hello-world flag", | ||
flags: map[string]string{"hello-world": "true", "quick-service": "https://fakeapi.trycloudflare.com"}, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "Quick tunnel with proxy-dns (invalid combo)", | ||
flags: map[string]string{"url": "http://127.0.0.1:9090", "proxy-dns": "true", "quick-service": "https://fakeapi.trycloudflare.com"}, | ||
expectError: true, | ||
}, | ||
{ | ||
name: "No quick-service set", | ||
flags: map[string]string{"url": "http://127.0.0.1:9090"}, | ||
expectError: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
// Mock RunQuickTunnel Function | ||
mockCalled := false | ||
mockQuickTunnelRunner := func(sc *subcommandContext) error { | ||
mockCalled = true | ||
return nil | ||
} | ||
|
||
// Mock App Context | ||
app := &cli.App{} | ||
set := flagSetFromMap(tt.flags) | ||
context := cli.NewContext(app, set, nil) | ||
|
||
// Call TunnelCommand | ||
err := tunnelCommandImpl(context, mockQuickTunnelRunner) | ||
|
||
// Validate | ||
if tt.expectError { | ||
assert.False(t, mockCalled) | ||
require.Error(t, err) | ||
} else { | ||
assert.True(t, mockCalled) | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func flagSetFromMap(flags map[string]string) *flag.FlagSet { | ||
set := flag.NewFlagSet("test", 0) | ||
for key, value := range flags { | ||
set.String(key, "", "") | ||
set.Set(key, value) | ||
} | ||
return set | ||
} |
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.
I haven't done any side-effect analysis to check whether anyone could be relying on
--unix-socket
forcing a trapdoor toproxy-dns
, but that seems unlikely so it should be okay.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.
I tried going through the code.
In
TunnelCommand
function in cmd.go, if--name
is not specified, only two non failure scenarios exists - quick tunnel or proxy dns.And in case of proxy-dns, I did not found a possible use of
--unix-socket
anywhere, as much I could understand the code flow.So, looks good.