-
Notifications
You must be signed in to change notification settings - Fork 5.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
Validate gateway arguments #4376
Validate gateway arguments #4376
Conversation
@krishnasrinivas, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balamurugana, @krisis and @donatello to be potential reviewers. |
As I mentioned in the issue, it is test setup, not some user is going to use it that way. I am OK if such kind of test setup is not allowed. |
|
why @balamurugana ? I am unable to see what I am missing. |
the case is |
But if myhostname resolves to localhost then anis' patch already takes care of not allowing the setup. |
Looks like its doing, but no unit tests show that. That needs to be added. |
Can you fix the commit message typo @krishnasrinivas |
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.
Tested (on linux)
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.
- Please fix the typo in title of the PR.
- PR's description looks more like a comment. You could record it as a comment here. The description should describe the changes and how it fixes the issue.
cmd/gateway-main.go
Outdated
if runtime.GOOS == "darwin" { | ||
host, port := mustSplitHostPort(serverAddr) | ||
// On macOS, if a process already listens on LOCALIPADDR:PORT, net.Listen() falls back | ||
// to IPv6 address ie minio will start listening on IPv6 address whereas another |
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.
s/ie/i.e
cmd/gateway-main.go
Outdated
// On macOS, if a process already listens on LOCALIPADDR:PORT, net.Listen() falls back | ||
// to IPv6 address ie minio will start listening on IPv6 address whereas another | ||
// (non-)minio process is listening on IPv4 of given port. | ||
// To avoid this error sutiation we check for port availability only for macOS. |
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.
s/sutiation/situation
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.
Needs to add unit test to address case
minio gateway --address=localhost:9000 http://mylocalhostname:9000
where localhost
and mylocalhostname
point different IPs of local hosts.
Oops, I don't know how it ended up in the description. It was intended to be a comment in the issue. |
Codecov Report
@@ Coverage Diff @@
## master #4376 +/- ##
==========================================
+ Coverage 66.49% 66.51% +0.01%
==========================================
Files 178 178
Lines 25470 25491 +21
==========================================
+ Hits 16937 16956 +19
+ Misses 7395 7394 -1
- Partials 1138 1141 +3
Continue to review full report at Codecov.
|
@balamurugana @krisis please check now |
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.
Test cases need a fix.
cmd/gateway-main_test.go
Outdated
{":9000", "http://localhost:9001", true}, | ||
{"123.123.123.123:9000", "http://localhost:9000", false}, | ||
{":9000", "http://localhost:9000", false}, | ||
{":9000", nonLoopBackIP + ":9000", false}, |
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 would recommend to validate error messages than valid
bool.
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.
we had a discussion here about this bala with @harshavardhana , the problem with doing string comparison is the code becomes brittle, i.e if we change the error message string the test case breaks. So I have kept it as "valid bool" for now. But we can have a discussion in one of the meetings so that we can consistently follow one method
endpointAddr string | ||
valid bool | ||
}{ | ||
{":9000", "http://localhost:9001", true}, |
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.
you could add a case where endpointAddr
is a remote host. you could use example.org
domains.
cmd/gateway-main_test.go
Outdated
testCases := []struct { | ||
serverAddr string | ||
endpointAddr string | ||
valid bool | ||
errMsg stringB |
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.
stringB
is invalid, compilation issue here.
cmd/gateway-main_test.go
Outdated
@@ -62,23 +62,24 @@ func TestValidateGatewayArguments(t *testing.T) { | |||
} | |||
nonLoopBackIP := nonLoopBackIPs.ToSlice()[0] | |||
|
|||
errMsg := "endpoint points to the local gateway" |
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.
You can re-purpose the message like errEndpointLoop
? which is returned by the actual function and you are just using errEndpointLoop.Error() to compare. Naked strings like this can invite issues like typo etc avoids changing at multiple places.
7d3cd07
to
64a9faf
Compare
@balamurugana had a discussion here about this with @harshavardhana , the problem with doing string comparison is the code becomes brittle, i.e if we change the error message string the test case breaks. So I have kept it as "valid bool" for now. But we can have a discussion in one of the meetings so that we can consistently follow it everywhere in our code. |
cmd/gateway-main.go
Outdated
} | ||
} | ||
err := validateGatewayArguments(serverAddr, endpointAddr) | ||
fatalIf(err, "Unable to validate") |
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.
"Unable to validate" is not correct. We did validate and found the arguments invalid. We could say something like "Invalid arguments: custom endpoint and gateway addresses are identical."
cmd/gateway-main_test.go
Outdated
for i, test := range testCases { | ||
err := validateGatewayArguments(test.serverAddr, test.endpointAddr) | ||
if test.valid && err != nil { | ||
t.Errorf("Test %d expected not to return erro but got %s", i+1, err) |
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.
typo: s/erro/error
64a9faf
to
9d431b4
Compare
@@ -179,6 +180,36 @@ func parseGatewayEndpoint(arg string) (endPoint string, secure bool, err error) | |||
} | |||
} | |||
|
|||
// Validate gateway arguments. | |||
func validateGatewayArguments(serverAddr, endpointAddr string) error { | |||
if err := CheckLocalServerAddr(serverAddr); err != nil { |
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.
@krisis can you take a look.. ?
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.
@harshavardhana yes, this addresses the problem my PR fixes. You can close my PR in favour.
Description
gateway endpoints validation.
Motivation and Context
fixes #4355
How Has This Been Tested?
manually
Types of changes
Checklist: