Skip to content

Commit

Permalink
make port 0 invalid in checkAddrFormat
Browse files Browse the repository at this point in the history
Signed-off-by: Sun Hongliang <[email protected]>
  • Loading branch information
allencloud committed Mar 30, 2016
1 parent d2bbd6b commit e60b93a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cli/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions cli/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
8 changes: 8 additions & 0 deletions test/integration/cli_join.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down

0 comments on commit e60b93a

Please sign in to comment.