make port 0 invalid in checkAddrFormat

Signed-off-by: Sun Hongliang <allen.sun@daocloud.io>
This commit is contained in:
Sun Hongliang 2016-03-30 19:43:29 +08:00
parent d2bbd6bc19
commit e60b93aef3
3 changed files with 10 additions and 1 deletions

View File

@ -18,7 +18,7 @@ func checkAddrFormat(addr string) bool {
return false
}
portNum, err := strconv.Atoi(port)
return err == nil && portNum >= 0 && portNum <= 65535
return err == nil && portNum > 0 && portNum <= 65535
}
func join(c *cli.Context) {

View File

@ -25,6 +25,7 @@ func TestCheckAddrFormat(t *testing.T) {
assert.True(t, checkAddrFormat("hostname:1111"))
assert.True(t, checkAddrFormat("host-name_42:1111"))
assert.False(t, checkAddrFormat("1.1.1.1:-1"))
assert.False(t, checkAddrFormat("1.1.1.1:0"))
assert.True(t, checkAddrFormat("1.1.1.1:65535"))
assert.False(t, checkAddrFormat("1.1.1.1:65536"))
assert.False(t, checkAddrFormat("1.1.1.1: 4000"))

View File

@ -15,6 +15,14 @@ DISCOVERY="consul://127.0.0.1:5555/test"
[ "$status" -ne 0 ]
[[ "${output}" == *"--advertise should be of the form ip:port or hostname:port"* ]]
run swarm join --heartbeat=1s --ttl=10s --delay=1s --advertise=127.0.0.1:0 "$DISCOVERY"
[ "$status" -ne 0 ]
[[ "${output}" == *"--advertise should be of the form ip:port or hostname:port"* ]]
run swarm join --heartbeat=1s --ttl=10s --delay=1s --advertise=127.0.0.1:65536 "$DISCOVERY"
[ "$status" -ne 0 ]
[[ "${output}" == *"--advertise should be of the form ip:port or hostname:port"* ]]
# --delay
run swarm join --heartbeat=1s --ttl=10s --delay=asdf --advertise=127.0.0.1:2376 "$DISCOVERY"
[ "$status" -ne 0 ]