mirror of https://github.com/docker/docs.git
Check port range. Add more unit tests for address format.
Signed-off-by: Dong Chen <dongluo.chen@docker.com>
This commit is contained in:
parent
bc27cedd8c
commit
bf5c744a49
|
@ -3,7 +3,7 @@ package cli
|
|||
import (
|
||||
"math/rand"
|
||||
"net"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
|
@ -17,8 +17,8 @@ func checkAddrFormat(addr string) bool {
|
|||
if err != nil {
|
||||
return false
|
||||
}
|
||||
m, _ := regexp.MatchString("^[0-9]{1,5}$", port)
|
||||
return m
|
||||
portNum, err := strconv.Atoi(port)
|
||||
return err == nil && portNum >= 0 && portNum <= 65535
|
||||
}
|
||||
|
||||
func join(c *cli.Context) {
|
||||
|
|
|
@ -24,6 +24,11 @@ func TestCheckAddrFormat(t *testing.T) {
|
|||
assert.True(t, checkAddrFormat("1.1.1.1:1111"))
|
||||
assert.True(t, checkAddrFormat("hostname:1111"))
|
||||
assert.True(t, checkAddrFormat("host-name_42:1111"))
|
||||
assert.False(t, checkAddrFormat("1.1.1.1:-1"))
|
||||
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"))
|
||||
assert.False(t, checkAddrFormat("1.1.1.1:m2"))
|
||||
assert.True(t, checkAddrFormat("[2001:db8:0:f101::3]:2375"))
|
||||
assert.False(t, checkAddrFormat("2001:db8:0:f101::3:2375"))
|
||||
assert.False(t, checkAddrFormat("[2001:db8:0:f101::3]:3:2375"))
|
||||
|
|
Loading…
Reference in New Issue