8000 Fix docker run --expose with an invalid port does not error out by coolljt0725 · Pull Request #10856 · moby/moby · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix docker run --expose with an invalid port does not error out #10856

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

Merged
merged 2 commits into from
Feb 20, 2015

Conversation

coolljt0725
Copy link
Contributor

Signed-off-by: Lei Jitang leijitang@huawei.com

Fixes #10836

when docker run --expose with an invalid port, there is no error out.
This patch fix this and have some refactor to previous code to make the code
more simplified. Since function parsers.ParsePortRange will do
strings.Contains(e, "-") and if the port is not a range but a specified one, the return
start port and end port are the same. So there is no need to do if strings.Contains(e, "-")
in parse.go

Signed-off-by: Lei Jitang <leijitang@huawei.com>
@coolljt0725
Copy link
Contributor Author

Shoud I add test for this?

@estesp
Copy link
Contributor
estesp commented Feb 17, 2015

Nice simplification! A test to validate error on invalid port would be great.

@jessfraz
Copy link
Contributor

We ❤️ tests :D

@coolljt0725
Copy link
Contributor Author

update, add a test for expose a invalid port @jfrazelle

if err != nil && !strings.Contains(out, "Invalid range format for --expose") {
t.Fatalf("failed to run container, output: %q", out)
}
if !strings.Contains(out, "Invalid range format for --expose") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failing test would never reach this point since you are testing for this above @ 2726.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpuguy83 I think there may be some other reasons will cause to run container failed not only the invalid port, @2726 is to exclude this situation. If there is no other reason case to run container failed, @2729 will ensure that run container failed is because of the invalid port.

@coolljt0725 coolljt0725 force-pushed the fix_expose branch 2 times, most recently from 052e3bc to 234fd5e Compare February 19, 2015 04:28
@coolljt0725
Copy link
Contributor Author

@cpuguy83 @jfrazelle the test has updated

// test docker run expose a invalid port
func TestRunExposePort(t *testing.T) {
runCmd := exec.Command(dockerBinary, "run", "--expose", "80000", "busybox")
_, _, err := runCommandWithOutput(runCmd)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it's often extremely helpful to get the actual output text here as part of the test's error message, and then we can do a !strings.Contains(<some error string here>) to make sure we go the error we thought we should.

@cpuguy83
Copy link
Member

LGTM after nits with the test.

@jessfraz
Copy link
Contributor

thanks for the test! looks good ping me after the changes for the merge :D

Signed-off-by: Lei Jitang <leijitang@huawei.com>
@coolljt0725
Copy link
Contributor Author

update the test, ping @jfrazelle

@jessfraz
Copy link
Contributor

LGTM

@jessfraz
Copy link
Contributor

thanks @coolljt0725

jessfraz pushed a commit that referenced this pull request Feb 20, 2015
Fix docker run --expose with an invalid port does not error out
@jessfraz jessfraz merged commit 1402937 into moby:master Feb 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docker run with invalid --expose does not error out
6 participants
0