Project

General

Profile

« Previous | Next » 

Revision 06b10bee

Added by Ondřej Pražák about 9 years ago

Fixes #5649 - unattended_url validation fix

View differences:

app/models/setting.rb
class UriValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors.add attribute, _("must be a valid URI") unless URI.parse(value).present?
record.errors.add attribute, _("must be a valid URI") unless %w(http https).include? URI(value).scheme
rescue URI::InvalidURIError
record.errors.add attribute, _("must be a valid URI")
end
test/unit/setting_test.rb
assert_equal "must be a valid URI", setting.errors[:value].first
end
test "foreman_url must have proper URI format" do
assert Setting.find_or_create_by_name(:name => "foreman_url", :default => "http://foo.com")
setting = Setting.find_by_name("foreman_url")
setting.value = "random_string"
assert !setting.save
assert_equal "must be a valid URI", setting.errors[:value].first
end
test "unattended_url must be a URI" do
assert Setting.find_or_create_by_name(:name => "unattended_url", :default => "http://foo.com")
setting = Setting.find_by_name("unattended_url")
......
assert_equal "must be a valid URI", setting.errors[:value].first
end
test "unattended_url must have proper URI format" do
assert Setting.find_or_create_by_name(:name => "foreman_url", :default => "http://foo.com")
setting = Setting.find_by_name("foreman_url")
setting.value = "random_string"
assert !setting.save
assert_equal "must be a valid URI", setting.errors[:value].first
end
test "integers in setting cannot be more then 8 characters" do
check_length_must_be_under_8 'entries_per_page'
end

Also available in: Unified diff