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
}
func ValidateHostName(name string) (string, error) {
if !validHostNamePattern.MatchString(name) {
return name, ErrInvalidHostname
}
return name, nil
func ValidateHostName(name string) bool {
return validHostNamePattern.MatchString(name)
}
func (h *Host) Create(name string) error {

View File

@ -122,13 +122,9 @@ func TestValidateHostnameValid(t *testing.T) {
}
for _, v := range hosts {
h, err := ValidateHostName(v)
if err != nil {
t.Fatal("Invalid hostname")
}
if h != v {
t.Fatal("Hostname doesn't match")
isValid := ValidateHostName(v)
if !isValid {
t.Fatal("Thought a valid hostname was invalid: %s", v)
}
}
}
@ -141,9 +137,9 @@ func TestValidateHostnameInvalid(t *testing.T) {
}
for _, v := range hosts {
_, err := ValidateHostName(v)
if err == nil {
t.Fatal("No error returned")
isValid := ValidateHostName(v)
if isValid {
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) {
validName := ValidateHostName(name)
if !validName {
return nil, ErrInvalidHostname
}
exists, err := m.store.Exists(name)
if err != nil {
return nil, err