mirror of
https://github.com/docker/cli.git
synced 2026-01-19 21:41:31 +03:00
Add validate the input mac address on docker run command
Signed-off-by: Lei Jitang <leijitang@huawei.com>
Upstream-commit: 8972795de7
Component: cli
This commit is contained in:
committed by
Vincent Demeester
parent
2c7c95805c
commit
ccc7b1dd83
@@ -188,6 +188,15 @@ func ValidateIPAddress(val string) (string, error) {
|
||||
return "", fmt.Errorf("%s is not an ip address", val)
|
||||
}
|
||||
|
||||
func ValidateMACAddress(val string) (string, error) {
|
||||
_, err := net.ParseMAC(strings.TrimSpace(val))
|
||||
if err != nil {
|
||||
return "", err
|
||||
} else {
|
||||
return val, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Validates domain for resolvconf search configuration.
|
||||
// A zero length domain is represented by .
|
||||
func ValidateDnsSearch(val string) (string, error) {
|
||||
|
||||
@@ -28,6 +28,20 @@ func TestValidateIPAddress(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestValidateMACAddress(t *testing.T) {
|
||||
if _, err := ValidateMACAddress(`92:d0:c6:0a:29:33`); err != nil {
|
||||
t.Fatalf("ValidateMACAddress(`92:d0:c6:0a:29:33`) got %s", err)
|
||||
}
|
||||
|
||||
if _, err := ValidateMACAddress(`92:d0:c6:0a:33`); err == nil {
|
||||
t.Fatalf("ValidateMACAddress(`92:d0:c6:0a:33`) succeeded; expected failure on invalid MAC")
|
||||
}
|
||||
|
||||
if _, err := ValidateMACAddress(`random invalid string`); err == nil {
|
||||
t.Fatalf("ValidateMACAddress(`random invalid string`) succeeded; expected failure on invalid MAC")
|
||||
}
|
||||
}
|
||||
|
||||
func TestListOpts(t *testing.T) {
|
||||
o := NewListOpts(nil)
|
||||
o.Set("foo")
|
||||
|
||||
Reference in New Issue
Block a user