1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Revert "validate network and endpoint name more strictly"

This reverts commit 761722395d.

Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
Madhu Venugopal 2017-02-01 18:17:29 -08:00
parent 4d1334c9ee
commit 8e2ca0471c
5 changed files with 13 additions and 25 deletions

View file

@ -1,8 +1,6 @@
package config
import (
"fmt"
"regexp"
"strings"
"github.com/BurntSushi/toml"
@ -17,12 +15,6 @@ import (
"github.com/docker/libnetwork/osl"
)
// RestrictedNameChars collects the characters allowed to represent a network or endpoint name.
const restrictedNameChars = `[a-zA-Z0-9][a-zA-Z0-9_.-]`
// RestrictedNamePattern is a regular expression to validate names against the collection of restricted characters.
var restrictedNamePattern = regexp.MustCompile(`^/?` + restrictedNameChars + `+$`)
// Config encapsulates configurations of various Libnetwork components
type Config struct {
Daemon DaemonCfg
@ -240,12 +232,12 @@ func (c *Config) ProcessOptions(options ...Option) {
}
}
// ValidateName validates configuration objects supported by libnetwork
func ValidateName(name string) error {
if !restrictedNamePattern.MatchString(name) {
return fmt.Errorf("%s includes invalid characters, only %q are allowed", name, restrictedNameChars)
// IsValidName validates configuration objects supported by libnetwork
func IsValidName(name string) bool {
if strings.TrimSpace(name) == "" {
return false
}
return nil
return true
}
// OptionLocalKVProvider function returns an option setter for kvstore provider

View file

@ -46,16 +46,13 @@ func TestOptionsLabels(t *testing.T) {
}
func TestValidName(t *testing.T) {
if err := ValidateName("test"); err != nil {
if !IsValidName("test") {
t.Fatal("Name validation fails for a name that must be accepted")
}
if err := ValidateName(""); err == nil {
if IsValidName("") {
t.Fatal("Name validation succeeds for a case when it is expected to fail")
}
if err := ValidateName(" "); err == nil {
t.Fatal("Name validation succeeds for a case when it is expected to fail")
}
if err := ValidateName("<>$$^"); err == nil {
if IsValidName(" ") {
t.Fatal("Name validation succeeds for a case when it is expected to fail")
}
}

View file

@ -647,8 +647,8 @@ func (c *controller) NewNetwork(networkType, name string, id string, options ...
}
}
if err := config.ValidateName(name); err != nil {
return nil, ErrInvalidName(err.Error())
if !config.IsValidName(name) {
return nil, ErrInvalidName(name)
}
if id == "" {

View file

@ -69,7 +69,7 @@ func (ii ErrInvalidID) Error() string {
func (ii ErrInvalidID) BadRequest() {}
// ErrInvalidName is returned when a query-by-name or resource create method is
// invoked with an invalid name parameter
// invoked with an empty name parameter
type ErrInvalidName string
func (in ErrInvalidName) Error() string {

View file

@ -879,9 +879,8 @@ func (n *network) addEndpoint(ep *endpoint) error {
func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoint, error) {
var err error
if err = config.ValidateName(name); err != nil {
return nil, ErrInvalidName(err.Error())
if !config.IsValidName(name) {
return nil, ErrInvalidName(name)
}
if _, err = n.EndpointByName(name); err == nil {