foreman_host_extra_validator 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8eeec4fa6fadb2f03e751ad816c36fbdf8477f90
4
- data.tar.gz: 29490772cacbbe78288e887b8943a3b9138f0846
2
+ SHA256:
3
+ metadata.gz: 1d036c7bd2e21429b39a6167f5f978c1af7b38a0f36d59fdd2837ab4a6811960
4
+ data.tar.gz: 5c5c8dbc081a24a6f37fae3a81c15f6243e4188e143139c79731a5fef097e651
5
5
  SHA512:
6
- metadata.gz: 224a52d469474305ea6450d0fffc79853ce3c5b5a3e9ea2793c534e2295b8eaf7c4d744a815ca864c55792fa4bd15452143343f312fc012117b9743bfa571e66
7
- data.tar.gz: 532bd3b18dcc198903aaf5b798b4db106ec6a34a5de1b846098c40065e0e12a3494e4f10f13337dd0f5866afbde82d32e66fcecd7e4cb6a76de45f1be0a27b4e
6
+ metadata.gz: 274523920b8f3a7f6adcfaa5c17621a40cbcb10033c15f3abcd368a462e575ad49defd87c3dbe5dbd6dfa29d97cf02e36a8c8baf050cfab53c05c4eba0c6128a
7
+ data.tar.gz: 48f52bb0e608d559c6478051a6ee2e17557aaf9729eab1c07c7bd1ad431bf47e2cae9e027cae3070b35f1c474c597184a604c12e5f6f05a4f1781f8e36aead79
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
22
 
23
- APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
23
+ APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
24
24
 
25
25
  Bundler::GemHelper.install_tasks
26
26
 
@@ -6,12 +6,14 @@ module ForemanHostExtraValidator
6
6
  end
7
7
 
8
8
  def validate_name_by_regex
9
- return unless validate_name_regex
9
+ return unless validate_name_regex.present?
10
10
  errors.add(:name, _('must match regex /%s/') % validate_name_regex) unless shortname =~ /#{validate_name_regex}/
11
11
  end
12
12
 
13
+ private
14
+
13
15
  def validate_name_regex
14
- host_inherited_params['host_name_validation_regex'] || Setting[:host_name_validation_regex]
16
+ inherited_params_hash.dig('host_name_validation_regex', :value) || Setting[:host_name_validation_regex]
15
17
  end
16
18
  end
17
19
  end
@@ -6,7 +6,7 @@ class Setting
6
6
 
7
7
  self.transaction do
8
8
  [
9
- self.set('host_name_validation_regex', _('Default regex the name of a host is validated against'), '^[a-zA-Z0-9-_]+$')
9
+ self.set('host_name_validation_regex', _('Default regex the name of a host is validated against'), '^[a-zA-Z0-9\-_]+$')
10
10
  ].compact.each { |s| self.create! s.update(:category => 'Setting::ForemanHostExtraValidator') }
11
11
  end
12
12
 
@@ -5,7 +5,7 @@ module ForemanHostExtraValidator
5
5
  config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
6
6
 
7
7
  initializer 'foreman_host_extra_validator.load_default_settings', :before => :load_config_initializers do |_app|
8
- require_dependency File.expand_path('../../../app/models/setting/foreman_host_extra_validator.rb', __FILE__) if begin
8
+ require_dependency File.expand_path('../../app/models/setting/foreman_host_extra_validator.rb', __dir__) if begin
9
9
  Setting.table_exists?
10
10
  rescue
11
11
  (false)
@@ -14,6 +14,7 @@ module ForemanHostExtraValidator
14
14
 
15
15
  initializer 'foreman_host_extra_validator.register_plugin', :before => :finisher_hook do |_app|
16
16
  Foreman::Plugin.register :foreman_host_extra_validator do
17
+ requires_foreman '>= 1.18'
17
18
  end
18
19
  end
19
20
 
@@ -21,12 +22,12 @@ module ForemanHostExtraValidator
21
22
  begin
22
23
  Host::Managed.send(:include, ForemanHostExtraValidator::HostExtensions)
23
24
  rescue => e
24
- Rails.logger.warn "ForemanPluginTemplate: skipping engine hook (#{e})\n#{e.backtrace}"
25
+ Rails.logger.warn "ForemanHostExtraValidator: skipping engine hook (#{e})\n#{e.backtrace}"
25
26
  end
26
27
  end
27
28
 
28
29
  initializer 'foreman_host_extra_validator.register_gettext', after: :load_config_initializers do |_app|
29
- locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
30
+ locale_dir = File.join(File.expand_path('../..', __dir__), 'locale')
30
31
  locale_domain = 'foreman_host_extra_validator'
31
32
  Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
32
33
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanHostExtraValidator
2
- VERSION = '0.0.4'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -6,7 +6,7 @@
6
6
  # make tx-update - download and merge translations from Transifex
7
7
  # make clean - clean everything
8
8
  #
9
- DOMAIN = foreman_plugin_template
9
+ DOMAIN = foreman_host_extra_validator
10
10
  VERSION = $(shell ruby -e 'require "rubygems";spec = Gem::Specification::load(Dir.glob("../*.gemspec")[0]);puts spec.version')
11
11
  POTFILE = $(DOMAIN).pot
12
12
  MOFILE = $(DOMAIN).mo
@@ -1,2 +1,2 @@
1
- # Matches foreman_plugin_template.gemspec
1
+ # Matches foreman_host_extra_validator.gemspec
2
2
  _('This plugin adds extra validations to a host.')
@@ -1,31 +1,42 @@
1
1
  require 'test_plugin_helper'
2
2
 
3
- class ForemanPluginTemplateTest < ActiveSupport::TestCase
3
+ class ForemanHostExtraValidatorTest < ActiveSupport::TestCase
4
4
  setup do
5
- Setting::HostValidation.load_defaults
5
+ Setting::ForemanHostExtraValidator.load_defaults
6
6
  disable_orchestration
7
- User.current = User.find_by_login 'admin'
7
+ User.current = FactoryBot.build(:user, :admin)
8
8
  end
9
9
 
10
- test '#validate_name_regex should return regex from setting when no regex is inherited' do
11
- regex = '^[0-9]+$'
12
- Setting[:host_name_validation_regex] = regex
13
- host = FactoryGirl.build(:host, :managed)
14
- assert_equal regex, host.validate_name_regex
15
- end
10
+ context 'with validation regex' do
11
+ setup do
12
+ Setting[:host_name_validation_regex] = '^[0-9]+$'
13
+ @host = FactoryBot.build(:host)
14
+ end
16
15
 
17
- test 'host should validate when host name matches regex' do
18
- regex = '^[0-9]+$'
19
- Setting[:host_name_validation_regex] = regex
20
- host = Host.new name: '054354'
21
- assert host.valid?
22
- end
16
+ test 'host should validate from settings' do
17
+ @host.name = '054354'
18
+ assert_valid @host
19
+ end
20
+
21
+ test 'host should not validate when host name does not match regex' do
22
+ @host.name = 'invalidhostname'
23
+ refute_valid @host
24
+ assert_includes @host.errors[:name], "must match regex /#{Setting[:host_name_validation_regex]}/"
25
+ end
26
+
27
+ test 'host should validate from hostgroup parameter' do
28
+ hostgroup = FactoryBot.create(:hostgroup)
29
+ @host.hostgroup = hostgroup
30
+ FactoryBot.create(:hostgroup_parameter, :name => 'host_name_validation_regex', :value => '^[a-z]+$', :hostgroup => hostgroup)
31
+
32
+ assert_equal '^[a-z]+$', @host.send(:validate_name_regex)
33
+ @host.hostname = 'abcdef'
34
+ assert_valid @host
35
+
36
+ @host.hostname = '1234'
37
+ refute_valid @host
38
+ assert_includes @host.errors[:name], "must match regex /^[a-z]+$/"
39
+ end
23
40
 
24
- test 'host should not validate when host name does not match regex' do
25
- regex = '^[0-9]+$'
26
- Setting[:host_name_validation_regex] = regex
27
- host = Host.new name: 'invalidhostname'
28
- refute host.valid?
29
- assert_includes host.errors[:name], "must match regex /#{regex}/"
30
41
  end
31
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_host_extra_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timo Goebel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-20 00:00:00.000000000 Z
11
+ date: 2018-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -61,8 +61,9 @@ files:
61
61
  - locale/gemspec.rb
62
62
  - test/test_plugin_helper.rb
63
63
  - test/unit/foreman_host_extra_validator_test.rb
64
- homepage: https://github.com/FILIADATAGmbH/
65
- licenses: []
64
+ homepage: https://github.com/theforeman/foreman_host_extra_validator
65
+ licenses:
66
+ - GPL-3.0
66
67
  metadata: {}
67
68
  post_install_message:
68
69
  rdoc_options: []
@@ -80,11 +81,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
81
  version: '0'
81
82
  requirements: []
82
83
  rubyforge_project:
83
- rubygems_version: 2.4.5
84
+ rubygems_version: 2.7.3
84
85
  signing_key:
85
86
  specification_version: 4
86
87
  summary: This plugin adds extra validations to a host.
87
88
  test_files:
88
- - test/test_plugin_helper.rb
89
89
  - test/unit/foreman_host_extra_validator_test.rb
90
- has_rdoc:
90
+ - test/test_plugin_helper.rb