-
Notifications
You must be signed in to change notification settings - Fork 4.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
auto-encrypt: Fix port resolution and fallback to default port #6205
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package consul | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
"log" | ||
"net" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestAutoEncrypt_resolveAddr(t *testing.T) { | ||
type args struct { | ||
rawHost string | ||
defaultPort int | ||
logger *log.Logger | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
ips []net.IP | ||
port int | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "host without port", | ||
args: args{ | ||
"127.0.0.1", | ||
8300, | ||
log.New(os.Stderr, "", log.LstdFlags), | ||
}, | ||
ips: []net.IP{net.IPv4(127, 0, 0, 1)}, | ||
port: 8300, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "host with port", | ||
args: args{ | ||
"127.0.0.1:1234", | ||
8300, | ||
log.New(os.Stderr, "", log.LstdFlags), | ||
}, | ||
ips: []net.IP{net.IPv4(127, 0, 0, 1)}, | ||
port: 1234, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "host with broken port", | ||
args: args{ | ||
"127.0.0.1:xyz", | ||
8300, | ||
log.New(os.Stderr, "", log.LstdFlags), | ||
}, | ||
ips: []net.IP{net.IPv4(127, 0, 0, 1)}, | ||
port: 8300, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "not an address", | ||
args: args{ | ||
"abc", | ||
8300, | ||
log.New(os.Stderr, "", log.LstdFlags), | ||
}, | ||
ips: nil, | ||
port: 8300, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ips, port, err := resolveAddr(tt.args.rawHost, tt.args.defaultPort, tt.args.logger) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("resolveAddr error: %v, wantErr: %v", err, tt.wantErr) | ||
return | ||
} | ||
require.Equal(t, tt.ips, ips) | ||
require.Equal(t, tt.port, port) | ||
}) | ||
} | ||
} |
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.
Heh not your code but the logic here seems odd - manually try TCP DNS first but then
net.LookupIP
will try it anyway if response is truncated? I guess in case TCP works and there are more IPs than fit in a UDP packet we save a UDP round trip first to discover that but that seems like a micro-optimization 😄.Ah well. No point changing it in this PR.