Skip to content

Commit

Permalink
Fixes #10479 - prevent validation error on host creation when domain …
Browse files Browse the repository at this point in the history
…contains capital letters
  • Loading branch information
tbrisker committed May 21, 2015
1 parent 1a282cb commit dda16f2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/nic/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def name=(*args)
end

def shortname
domain.nil? ? name : name.to_s.chomp("." + domain.name)
domain.nil? ? name : name.sub(/\.#{Regexp.escape domain.name}/i, '')
end

def validated?
Expand Down
2 changes: 1 addition & 1 deletion app/models/nic/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def normalize_name
# A managed host we should know the domain for; and the shortname shouldn't include a period
# This only applies for unattended=true, as otherwise the name field includes the domain
errors.add(:name, _("must not include periods")) if ( host && host.managed? && managed? && shortname.include?(".") && SETTINGS[:unattended] )
self.name = Net::Validations.normalize_hostname(name) if self.name.present?
self.name = Net::Validations.normalize_hostname(name)
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions test/unit/nics/managed_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class ManagedTest < ActiveSupport::TestCase
assert_nil nic.domain
end

test "#normalize_hostname accepts domain even if it contains capital letters" do
domain = FactoryGirl.create(:domain, :name => "CAPITAL.com")
nic = setup_primary_nic_with_name(" Host.#{domain.name}", :domain => nil)
nic.send(:normalize_name)
assert_equal "host.#{domain.name.downcase}", nic.name
assert_equal domain, nic.domain
end

test "#normalize_hostname keeps domain nil if it can't find such domain based on name" do
nic = setup_primary_nic_with_name(" Host", :domain => nil)
nic.send(:normalize_name)
Expand Down

0 comments on commit dda16f2

Please sign in to comment.