Merge pull request #859 from nathanleclaire/validate_hostname

Fix location of validating hostname functionality
This commit is contained in:
Evan Hazlett 2015-03-24 12:04:13 -07:00
commit aa031ec759
3 changed files with 12 additions and 15 deletions

View File

@ -92,11 +92,8 @@ func LoadHost(name string, StorePath string) (*Host, error) {
return host, nil return host, nil
} }
func ValidateHostName(name string) (string, error) { func ValidateHostName(name string) bool {
if !validHostNamePattern.MatchString(name) { return validHostNamePattern.MatchString(name)
return name, ErrInvalidHostname
}
return name, nil
} }
func (h *Host) Create(name string) error { func (h *Host) Create(name string) error {

View File

@ -122,13 +122,9 @@ func TestValidateHostnameValid(t *testing.T) {
} }
for _, v := range hosts { for _, v := range hosts {
h, err := ValidateHostName(v) isValid := ValidateHostName(v)
if err != nil { if !isValid {
t.Fatal("Invalid hostname") t.Fatal("Thought a valid hostname was invalid: %s", v)
}
if h != v {
t.Fatal("Hostname doesn't match")
} }
} }
} }
@ -141,9 +137,9 @@ func TestValidateHostnameInvalid(t *testing.T) {
} }
for _, v := range hosts { for _, v := range hosts {
_, err := ValidateHostName(v) isValid := ValidateHostName(v)
if err == nil { if isValid {
t.Fatal("No error returned") t.Fatal("Thought an invalid hostname was valid: %s", v)
} }
} }
} }

View File

@ -20,6 +20,10 @@ func New(store Store) (*Machine, error) {
} }
func (m *Machine) Create(name string, driverName string, hostOptions *HostOptions, driverConfig drivers.DriverOptions) (*Host, error) { func (m *Machine) Create(name string, driverName string, hostOptions *HostOptions, driverConfig drivers.DriverOptions) (*Host, error) {
validName := ValidateHostName(name)
if !validName {
return nil, ErrInvalidHostname
}
exists, err := m.store.Exists(name) exists, err := m.store.Exists(name)
if err != nil { if err != nil {
return nil, err return nil, err