simp-cli 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. checksums.yaml +15 -0
  2. data/LICENSE +27 -0
  3. data/README.md +48 -0
  4. data/Rakefile +142 -0
  5. data/bin/simp +5 -0
  6. data/lib/simp/cli.rb +88 -0
  7. data/lib/simp/cli/commands/bootstrap.rb +275 -0
  8. data/lib/simp/cli/commands/check.rb +163 -0
  9. data/lib/simp/cli/commands/cleancerts.rb +114 -0
  10. data/lib/simp/cli/commands/config.rb +235 -0
  11. data/lib/simp/cli/commands/doc.rb +14 -0
  12. data/lib/simp/cli/commands/passgen.rb +128 -0
  13. data/lib/simp/cli/commands/puppeteval.rb +82 -0
  14. data/lib/simp/cli/commands/runpuppet.rb +95 -0
  15. data/lib/simp/cli/config/item.rb +456 -0
  16. data/lib/simp/cli/config/item/add_ldap_to_hiera.rb +43 -0
  17. data/lib/simp/cli/config/item/answers_yaml_file_writer.rb +58 -0
  18. data/lib/simp/cli/config/item/certificates.rb +39 -0
  19. data/lib/simp/cli/config/item/client_nets.rb +65 -0
  20. data/lib/simp/cli/config/item/common_runlevel_default.rb +32 -0
  21. data/lib/simp/cli/config/item/dns_search.rb +48 -0
  22. data/lib/simp/cli/config/item/dns_servers.rb +57 -0
  23. data/lib/simp/cli/config/item/failover_log_servers.rb +27 -0
  24. data/lib/simp/cli/config/item/gateway.rb +32 -0
  25. data/lib/simp/cli/config/item/grub_password.rb +51 -0
  26. data/lib/simp/cli/config/item/hostname.rb +24 -0
  27. data/lib/simp/cli/config/item/hostname_conf.rb +48 -0
  28. data/lib/simp/cli/config/item/ipaddress.rb +46 -0
  29. data/lib/simp/cli/config/item/is_master_yum_server.rb +23 -0
  30. data/lib/simp/cli/config/item/ldap_base_dn.rb +38 -0
  31. data/lib/simp/cli/config/item/ldap_bind_dn.rb +34 -0
  32. data/lib/simp/cli/config/item/ldap_bind_hash.rb +28 -0
  33. data/lib/simp/cli/config/item/ldap_bind_pw.rb +24 -0
  34. data/lib/simp/cli/config/item/ldap_master.rb +33 -0
  35. data/lib/simp/cli/config/item/ldap_root_dn.rb +42 -0
  36. data/lib/simp/cli/config/item/ldap_root_hash.rb +35 -0
  37. data/lib/simp/cli/config/item/ldap_sync_dn.rb +24 -0
  38. data/lib/simp/cli/config/item/ldap_sync_hash.rb +28 -0
  39. data/lib/simp/cli/config/item/ldap_sync_pw.rb +26 -0
  40. data/lib/simp/cli/config/item/ldap_uri.rb +43 -0
  41. data/lib/simp/cli/config/item/log_servers.rb +27 -0
  42. data/lib/simp/cli/config/item/netmask.rb +39 -0
  43. data/lib/simp/cli/config/item/network_conf.rb +63 -0
  44. data/lib/simp/cli/config/item/network_dhcp.rb +27 -0
  45. data/lib/simp/cli/config/item/network_interface.rb +41 -0
  46. data/lib/simp/cli/config/item/network_setup_nic.rb +28 -0
  47. data/lib/simp/cli/config/item/ntp_servers.rb +69 -0
  48. data/lib/simp/cli/config/item/puppet_autosign.rb +66 -0
  49. data/lib/simp/cli/config/item/puppet_ca.rb +31 -0
  50. data/lib/simp/cli/config/item/puppet_ca_port.rb +28 -0
  51. data/lib/simp/cli/config/item/puppet_conf.rb +98 -0
  52. data/lib/simp/cli/config/item/puppet_fileserver.rb +104 -0
  53. data/lib/simp/cli/config/item/puppet_hosts_entry.rb +44 -0
  54. data/lib/simp/cli/config/item/puppet_server.rb +30 -0
  55. data/lib/simp/cli/config/item/puppet_server_ip.rb +25 -0
  56. data/lib/simp/cli/config/item/puppetdb_port.rb +25 -0
  57. data/lib/simp/cli/config/item/puppetdb_server.rb +26 -0
  58. data/lib/simp/cli/config/item/remove_ldap_from_hiera.rb +47 -0
  59. data/lib/simp/cli/config/item/rename_fqdn_yaml.rb +40 -0
  60. data/lib/simp/cli/config/item/rsync_base.rb +37 -0
  61. data/lib/simp/cli/config/item/rsync_server.rb +44 -0
  62. data/lib/simp/cli/config/item/rsync_timeout.rb +26 -0
  63. data/lib/simp/cli/config/item/set_grub_password.rb +19 -0
  64. data/lib/simp/cli/config/item/simp_yum_servers.rb +30 -0
  65. data/lib/simp/cli/config/item/use_auditd.rb +19 -0
  66. data/lib/simp/cli/config/item/use_fips.rb +46 -0
  67. data/lib/simp/cli/config/item/use_iptables.rb +22 -0
  68. data/lib/simp/cli/config/item/use_ldap.rb +19 -0
  69. data/lib/simp/cli/config/item/use_selinux.rb +32 -0
  70. data/lib/simp/cli/config/item/yum_repositories.rb +75 -0
  71. data/lib/simp/cli/config/item_list_factory.rb +236 -0
  72. data/lib/simp/cli/config/questionnaire.rb +86 -0
  73. data/lib/simp/cli/config/utils.rb +128 -0
  74. data/lib/simp/cli/lib/utils.rb +114 -0
  75. data/lib/simp/simp.rb +77 -0
  76. data/spec/lib/simp/cli/commands/config_spec.rb +42 -0
  77. data/spec/lib/simp/cli/config/item/add_ldap_to_hiera_spec.rb +58 -0
  78. data/spec/lib/simp/cli/config/item/answers_yaml_file_writer_spec.rb +86 -0
  79. data/spec/lib/simp/cli/config/item/certificates_spec.rb +50 -0
  80. data/spec/lib/simp/cli/config/item/client_nets_spec.rb +66 -0
  81. data/spec/lib/simp/cli/config/item/common_runlevel_default_spec.rb +27 -0
  82. data/spec/lib/simp/cli/config/item/dns_search_spec.rb +74 -0
  83. data/spec/lib/simp/cli/config/item/dns_servers_spec.rb +76 -0
  84. data/spec/lib/simp/cli/config/item/failover_log_servers_spec.rb +49 -0
  85. data/spec/lib/simp/cli/config/item/files/FakeCA/cacertkey +1 -0
  86. data/spec/lib/simp/cli/config/item/files/FakeCA/gencerts_nopass.sh +10 -0
  87. data/spec/lib/simp/cli/config/item/files/autosign.conf.new +11 -0
  88. data/spec/lib/simp/cli/config/item/files/autosign.conf.used +15 -0
  89. data/spec/lib/simp/cli/config/item/files/fileserver.conf +41 -0
  90. data/spec/lib/simp/cli/config/item/files/hosts +2 -0
  91. data/spec/lib/simp/cli/config/item/files/hosts.old_puppet_entry +3 -0
  92. data/spec/lib/simp/cli/config/item/files/puppet.conf +25 -0
  93. data/spec/lib/simp/cli/config/item/files/puppet.your.domain.yaml +21 -0
  94. data/spec/lib/simp/cli/config/item/files/resolv.conf__multiple +10 -0
  95. data/spec/lib/simp/cli/config/item/files/resolv.conf__single +4 -0
  96. data/spec/lib/simp/cli/config/item/files/rsyncd.conf +225 -0
  97. data/spec/lib/simp/cli/config/item/gateway_spec.rb +23 -0
  98. data/spec/lib/simp/cli/config/item/grub_password_spec.rb +24 -0
  99. data/spec/lib/simp/cli/config/item/hostname_conf_spec.rb +27 -0
  100. data/spec/lib/simp/cli/config/item/hostname_spec.rb +22 -0
  101. data/spec/lib/simp/cli/config/item/ipaddress_spec.rb +40 -0
  102. data/spec/lib/simp/cli/config/item/is_master_yum_server_spec.rb +29 -0
  103. data/spec/lib/simp/cli/config/item/ldap_base_dn_spec.rb +23 -0
  104. data/spec/lib/simp/cli/config/item/ldap_bind_dn_spec.rb +23 -0
  105. data/spec/lib/simp/cli/config/item/ldap_bind_hash_spec.rb +23 -0
  106. data/spec/lib/simp/cli/config/item/ldap_bind_pw_spec.rb +21 -0
  107. data/spec/lib/simp/cli/config/item/ldap_master_spec.rb +37 -0
  108. data/spec/lib/simp/cli/config/item/ldap_root_dn_spec.rb +23 -0
  109. data/spec/lib/simp/cli/config/item/ldap_root_hash_spec.rb +23 -0
  110. data/spec/lib/simp/cli/config/item/ldap_sync_dn_spec.rb +22 -0
  111. data/spec/lib/simp/cli/config/item/ldap_sync_hash_spec.rb +23 -0
  112. data/spec/lib/simp/cli/config/item/ldap_sync_pw_spec.rb +21 -0
  113. data/spec/lib/simp/cli/config/item/ldap_uri_spec.rb +32 -0
  114. data/spec/lib/simp/cli/config/item/log_servers_spec.rb +49 -0
  115. data/spec/lib/simp/cli/config/item/netmask_spec.rb +28 -0
  116. data/spec/lib/simp/cli/config/item/network_conf_spec.rb +63 -0
  117. data/spec/lib/simp/cli/config/item/network_dhcp_spec.rb +11 -0
  118. data/spec/lib/simp/cli/config/item/network_interface_spec.rb +26 -0
  119. data/spec/lib/simp/cli/config/item/network_setup_nic_spec.rb +29 -0
  120. data/spec/lib/simp/cli/config/item/ntp_servers_spec.rb +43 -0
  121. data/spec/lib/simp/cli/config/item/puppet_autosign_spec.rb +55 -0
  122. data/spec/lib/simp/cli/config/item/puppet_ca_port_spec.rb +23 -0
  123. data/spec/lib/simp/cli/config/item/puppet_ca_spec.rb +22 -0
  124. data/spec/lib/simp/cli/config/item/puppet_conf_spec.rb +110 -0
  125. data/spec/lib/simp/cli/config/item/puppet_fileserver_spec.rb +53 -0
  126. data/spec/lib/simp/cli/config/item/puppet_hosts_entry_spec.rb +85 -0
  127. data/spec/lib/simp/cli/config/item/puppet_server_ip_spec.rb +24 -0
  128. data/spec/lib/simp/cli/config/item/puppet_server_spec.rb +22 -0
  129. data/spec/lib/simp/cli/config/item/puppetdb_port_spec.rb +25 -0
  130. data/spec/lib/simp/cli/config/item/puppetdb_server_spec.rb +25 -0
  131. data/spec/lib/simp/cli/config/item/remove_ldap_from_hiera_spec.rb +58 -0
  132. data/spec/lib/simp/cli/config/item/rename_fqdn_yaml_spec.rb +63 -0
  133. data/spec/lib/simp/cli/config/item/rsync_base_spec.rb +28 -0
  134. data/spec/lib/simp/cli/config/item/rsync_server_spec.rb +41 -0
  135. data/spec/lib/simp/cli/config/item/rsync_timeout_spec.rb +21 -0
  136. data/spec/lib/simp/cli/config/item/set_grub_password_spec.rb +29 -0
  137. data/spec/lib/simp/cli/config/item/simp_yum_servers_spec.rb +41 -0
  138. data/spec/lib/simp/cli/config/item/spec_helper.rb +22 -0
  139. data/spec/lib/simp/cli/config/item/use_auditd_spec.rb +29 -0
  140. data/spec/lib/simp/cli/config/item/use_fips_spec.rb +29 -0
  141. data/spec/lib/simp/cli/config/item/use_iptables_spec.rb +29 -0
  142. data/spec/lib/simp/cli/config/item/use_ldap_spec.rb +29 -0
  143. data/spec/lib/simp/cli/config/item/use_selinux_spec.rb +24 -0
  144. data/spec/lib/simp/cli/config/item/yum_repositories_spec.rb +94 -0
  145. data/spec/lib/simp/cli/config/item_spec.rb +106 -0
  146. data/spec/lib/simp/cli/config/spec_helper.rb +1 -0
  147. data/spec/lib/simp/cli/config/utils_spec.rb +131 -0
  148. data/spec/lib/simp/cli/spec_helper.rb +1 -0
  149. data/spec/spec_helper.rb +91 -0
  150. metadata +391 -0
@@ -0,0 +1,58 @@
1
+ require 'simp/cli/config/item/add_ldap_to_hiera'
2
+ require 'simp/cli/config/item/hostname'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::AddLdapToHiera do
6
+ before :each do
7
+ @ci = Simp::Cli::Config::Item::AddLdapToHiera.new
8
+ @ci.silent = true
9
+ end
10
+
11
+ # describe "#contains_ldap?" do
12
+ # it 'decides to strip ::ldap and openldap:: classes' do
13
+ # expect(@ci.contains_ldap?(' - simp::ldap_server')).to be true
14
+ # expect(@ci.contains_ldap?(%q{ - 'simp::ldap_server'})).to be true
15
+ # expect(@ci.contains_ldap?(' - openldap')).to be true
16
+ # expect(@ci.contains_ldap?(' - openldap::server')).to be true
17
+ # end
18
+ #
19
+ # it 'rejects false positives' do
20
+ # expect(@ci.contains_ldap?( '# - simp::ldap_server')).to be false
21
+ # expect(@ci.contains_ldap?(' - randomldap::foo')).to be false
22
+ # end
23
+ # end
24
+
25
+ describe "#apply" do
26
+ context "with a valid fqdn" do
27
+ before :each do
28
+ @fqdn = 'hostname.domain.tld'
29
+ @files_dir = File.expand_path( 'files', File.dirname( __FILE__ ) )
30
+ @tmp_dir = File.expand_path( 'tmp', File.dirname( __FILE__ ) )
31
+ @file = File.join( @files_dir,'puppet.your.domain.yaml')
32
+ @tmp_file = File.join( @tmp_dir, "#{@fqdn}.yaml" )
33
+ @ci.dir = @tmp_dir
34
+
35
+ item = Simp::Cli::Config::Item::Hostname.new
36
+ item.value = @fqdn
37
+ @ci.config_items[item.key] = item
38
+ @new_file = File.join( @tmp_dir, "#{@fqdn}.yaml" )
39
+
40
+ [@tmp_file, @new_file].each do |file|
41
+ FileUtils.rm file if File.exists? file
42
+ end
43
+
44
+ FileUtils.mkdir_p @tmp_dir
45
+ FileUtils.copy_file @file, @tmp_file
46
+
47
+ @result = @ci.apply
48
+ end
49
+
50
+ it "file will contain the simp::ldap_server class" do
51
+ expect( File.open(@tmp_file).readlines.join("\n") ).to match(/simp::ldap_server/)
52
+ end
53
+ end
54
+ end
55
+
56
+ it_behaves_like "an Item that doesn't output YAML"
57
+ it_behaves_like 'a child of Simp::Cli::Config::Item'
58
+ end
@@ -0,0 +1,86 @@
1
+ require 'simp/cli/config/item/answers_yaml_file_writer'
2
+ require 'simp/cli/config/item/puppet_server'
3
+ require 'simp/cli/config/item/puppet_server_ip'
4
+ require 'rspec/its'
5
+ require_relative( 'spec_helper' )
6
+
7
+ describe Simp::Cli::Config::Item::AnswersYAMLFileWriter do
8
+ before :all do
9
+ @ci = Simp::Cli::Config::Item::AnswersYAMLFileWriter.new
10
+ @ci.silent = true # turn off command line summary on stdout
11
+ @tmp_dir = File.expand_path( 'tmp', File.dirname( __FILE__ ) )
12
+ end
13
+
14
+
15
+ describe "#print_answers_yaml" do
16
+ before :each do
17
+ ci = Simp::Cli::Config::Item.new
18
+ ci.key = 'item'
19
+ ci.value = 'foo'
20
+ ci.description = 'A simple item'
21
+ list = { foo: ci }
22
+
23
+ ci = Simp::Cli::Config::ListItem.new
24
+ ci.key = 'list'
25
+ ci.value = ['one','two','three']
26
+ ci.description = 'A simple list'
27
+ list[ci.key] = ci
28
+
29
+ ci = Simp::Cli::Config::YesNoItem.new
30
+ ci.key = 'yesno'
31
+ ci.value = true
32
+ ci.description = 'A simple yes/no item'
33
+ list[ci.key] = ci
34
+
35
+ @simple_item_list = list
36
+ end
37
+
38
+ it "prints parseable yaml" do
39
+ io = StringIO.new
40
+ @ci.print_answers_yaml( io, @simple_item_list )
41
+ y = YAML.load( io.string )
42
+
43
+ expect( y ).to be_kind_of Hash
44
+ expect( y ).not_to be_empty
45
+ expect( y['item'] ).to eq('foo')
46
+ expect( y['list'] ).to eq(['one','two','three'])
47
+ expect( y['yesno'] ).to eq(true)
48
+ end
49
+ end
50
+
51
+
52
+ context "when writing a yaml file" do
53
+ before :context do
54
+ item = Simp::Cli::Config::Item::PuppetServerIP.new
55
+ item.value = '1.2.3.4'
56
+ @ci.config_items[item.key] = item
57
+
58
+ item = Simp::Cli::Config::Item::PuppetServer.new
59
+ item.value = 'puppet.domain.tld'
60
+ @ci.config_items[item.key] = item
61
+
62
+ @tmp_file = File.expand_path( 'answers_yaml_file_writer.yaml', @tmp_dir )
63
+ FileUtils.mkdir_p @tmp_dir
64
+ @ci.file = @tmp_file
65
+ @ci.apply
66
+ end
67
+
68
+ it "writes a file" do
69
+ expect( File.exists?( @tmp_file ) ).to be true
70
+ end
71
+
72
+ it "writes the correct values" do
73
+ lines = File.readlines( @tmp_file ).join( "\n" )
74
+ expect( lines ).to match(%r{^\W*puppet::server\W*:\W*puppet.domain.tld\b})
75
+ expect( lines ).to match(%r{^\W*puppet::server::ip\W*:\W*1.2.3.4\b})
76
+ end
77
+
78
+ after :context do
79
+ FileUtils.rm @tmp_file
80
+ end
81
+ end
82
+
83
+ it_behaves_like "an Item that doesn't output YAML"
84
+ it_behaves_like "a child of Simp::Cli::Config::Item"
85
+ end
86
+
@@ -0,0 +1,50 @@
1
+ require 'simp/cli/config/item/certificates'
2
+ require 'simp/cli/config/item/hostname'
3
+ require 'rspec/its'
4
+ require_relative( 'spec_helper' )
5
+
6
+ describe Simp::Cli::Config::Item::Certificates do
7
+ before :each do
8
+ @ci = Simp::Cli::Config::Item::Certificates.new
9
+ @ci.silent = true
10
+ @hostname = 'puppet.testing.fqdn'
11
+ item = Simp::Cli::Config::Item::Hostname.new
12
+ item.value = @hostname
13
+ @ci.config_items[ item.key ] = item
14
+
15
+ @files_dir = File.expand_path( 'files', File.dirname( __FILE__ ) )
16
+ end
17
+
18
+
19
+ describe "#apply" do
20
+ context 'using external files,' do
21
+ before :each do
22
+ @tmp_dir = Dir.mktmpdir( File.basename(__FILE__),
23
+ File.expand_path('tmp', File.dirname( __FILE__ )) )
24
+ @tmp_dirs = {
25
+ :keydist => File.join( @tmp_dir, 'keydist'),
26
+ :fake_ca => File.join( @tmp_dir, 'FakeCA'),
27
+ }
28
+ FileUtils.mkdir @tmp_dirs.values
29
+ src_dir = File.join(@files_dir,'FakeCA')
30
+ FileUtils.cp_r( Dir["#{src_dir}/*"], @tmp_dirs[:fake_ca] )
31
+
32
+ @ci.dirs = @tmp_dirs
33
+ @ci.apply
34
+ end
35
+
36
+ it 'runs gencerts_nopass.sh auto' do
37
+ dir = File.join( @tmp_dirs[:keydist], @hostname )
38
+ expect( File.exists? dir ).to be true
39
+ end
40
+
41
+ after :each do
42
+ FileUtils.remove_entry_secure @tmp_dir
43
+ end
44
+ end
45
+ end
46
+
47
+ it_behaves_like "an Item that doesn't output YAML"
48
+ it_behaves_like 'a child of Simp::Cli::Config::Item'
49
+ end
50
+
@@ -0,0 +1,66 @@
1
+ require 'simp/cli/config/item/client_nets'
2
+
3
+ require 'simp/cli/config/item/ipaddress'
4
+ require 'simp/cli/config/item/netmask'
5
+ require_relative( 'spec_helper' )
6
+
7
+ describe Simp::Cli::Config::Item::ClientNets do
8
+ before :each do
9
+ @ci = Simp::Cli::Config::Item::ClientNets.new
10
+ @ci.silent = true
11
+ end
12
+
13
+
14
+ describe "#recommended_value" do
15
+ it "recommends no CIDR notation when IP + netmask are unavailable" do
16
+ expect( @ci.recommended_value ).to be_nil
17
+ end
18
+
19
+ it "recommends correct CIDR notation for a given IP + netmask" do
20
+ @ci.config_items = create_prior_items( '10.10.6.227', '255.255.255.0' )
21
+ expect( @ci.recommended_value ).to eq ['10.10.6.0/24']
22
+
23
+ @ci.config_items = create_prior_items( '10.10.10.99', '255.255.255.224' )
24
+ expect( @ci.recommended_value ).to eq ['10.10.10.96/27']
25
+ end
26
+ end
27
+
28
+
29
+ describe "#validate" do
30
+ it "validates array of good cidr nets" do
31
+ expect( @ci.validate ['10.0.71.0/24'] ).to eq true
32
+ expect( @ci.validate ['1.2.3.0/24'] ).to eq true
33
+ expect( @ci.validate ['10.10.10.0/16', '192.168.1.0/23'] ).to eq true
34
+ # crazy, but valid CIDR (equiv to 33,554,432 class C networks!)
35
+ expect( @ci.validate ['1.2.3.0/0'] ).to eq true
36
+ end
37
+
38
+ it "doesn't validate array with bad cidr nets" do
39
+ expect( @ci.validate 0 ).to eq false
40
+ expect( @ci.validate nil ).to eq false
41
+ expect( @ci.validate false ).to eq false
42
+ expect( @ci.validate [nil] ).to eq false
43
+ expect( @ci.validate ['1.2.3.999/24'] ).to eq false
44
+ expect( @ci.validate ['1.2.3.999/24/24'] ).to eq false
45
+ expect( @ci.validate ['1.2.3.999/z'] ).to eq false
46
+ expect( @ci.validate ['1.2.3.0/24', '192.168.1.0/99'] ).to eq false
47
+ end
48
+
49
+ it "doesn't validate an empty array" do
50
+ expect( @ci.validate [] ).to eq false
51
+ end
52
+ end
53
+
54
+ def create_prior_items ip, netmask
55
+ items = {}
56
+ _ip = Simp::Cli::Config::Item::IPAddress.new
57
+ _ip.value = ip
58
+ items[ _ip.key ] = _ip
59
+ _netmask = Simp::Cli::Config::Item::Netmask.new
60
+ _netmask.value = netmask
61
+ items[ _netmask.key ] = _netmask
62
+ items
63
+ end
64
+
65
+ it_behaves_like "a child of Simp::Cli::Config::Item"
66
+ end
@@ -0,0 +1,27 @@
1
+ require 'simp/cli/config/item/common_runlevel_default'
2
+ require 'rspec/its'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::CommonRunLevelDefault do
6
+ before :each do
7
+ @ci = Simp::Cli::Config::Item::CommonRunLevelDefault.new
8
+ end
9
+
10
+ describe "#validate" do
11
+ it "validates common_runlevel_defaults" do
12
+ expect( @ci.validate '1' ).to eq true
13
+ expect( @ci.validate '3' ).to eq true
14
+ expect( @ci.validate '5' ).to eq true
15
+ end
16
+
17
+ it "doesn't validate bad common_runlevel_defaults" do
18
+ expect( @ci.validate '' ).to eq false
19
+ expect( @ci.validate '0' ).to eq false
20
+ expect( @ci.validate '7' ).to eq false
21
+ expect( @ci.validate nil ).to eq false
22
+ expect( @ci.validate false ).to eq false
23
+ end
24
+ end
25
+
26
+ it_behaves_like "a child of Simp::Cli::Config::Item"
27
+ end
@@ -0,0 +1,74 @@
1
+ require 'simp/cli/config/item/dns_search'
2
+ require 'simp/cli/config/item/hostname'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::DNSSearch do
6
+ before :all do
7
+ @files_dir = File.expand_path( 'files', File.dirname( __FILE__ ) )
8
+ end
9
+
10
+ before :each do
11
+ @ci = Simp::Cli::Config::Item::DNSSearch.new
12
+ end
13
+
14
+
15
+ describe '#recommended_value' do
16
+ context 'when /etc/resolv.conf is populated' do
17
+ it 'handles a single domain' do
18
+ @ci.file = File.join(@files_dir,'resolv.conf__single')
19
+ expect( @ci.recommended_value).to eq ['tasty.bacon']
20
+ end
21
+
22
+ it 'handles multiple domains' do
23
+ @ci.file = File.join(@files_dir,'resolv.conf__multiple')
24
+ expect( @ci.recommended_value).to eq ['tasty.bacon', 'yucky.bacon', 'instant.bacon']
25
+ end
26
+ end
27
+
28
+ context 'when /etc/resolv.conf is empty' do
29
+ before :each do
30
+ @ci.file = '/dev/null'
31
+ end
32
+
33
+ it 'recommends ipaddress (when available)' do
34
+ fqdn = Simp::Cli::Config::Item::Hostname.new
35
+ fqdn.value = 'puppet.snazzy.domain'
36
+ @ci.config_items[ fqdn.key ] = fqdn
37
+
38
+ expect( @ci.recommended_value.size ).to eq 1
39
+ expect( @ci.recommended_value ).to eq ['snazzy.domain']
40
+ end
41
+
42
+ it 'recommends a must-change value (when ipaddress is not available)' do
43
+ expect( @ci.recommended_value.size ).to eq 1
44
+ expect( @ci.recommended_value.first ).to match( /change/ )
45
+ end
46
+ end
47
+ end
48
+
49
+
50
+ describe "#validate" do
51
+ it "validates array with domains" do
52
+ expect( @ci.validate ['simp.dev', 'google.com', '0simp.dev'] ).to eq true
53
+ end
54
+
55
+ it "doesn't validate array with bad domains" do
56
+ expect( @ci.validate [nil] ).to eq false
57
+ expect( @ci.validate ['simp.dev.'] ).to eq false
58
+ expect( @ci.validate ['.simp.dev'] ).to eq false
59
+ end
60
+
61
+ it "doesn't validate empty array" do
62
+ expect( @ci.validate [] ).to eq false
63
+ end
64
+
65
+ it "doesn't validate nonsense" do
66
+ expect( @ci.validate 0 ).to eq false
67
+ expect( @ci.validate nil ).to eq false
68
+ expect( @ci.validate false ).to eq false
69
+ end
70
+ end
71
+
72
+ it_behaves_like "a child of Simp::Cli::Config::Item"
73
+ end
74
+
@@ -0,0 +1,76 @@
1
+ require 'simp/cli/config/item/dns_servers'
2
+ require 'simp/cli/config/item/ipaddress'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::DNSServers do
6
+ before :all do
7
+ @files_dir = File.expand_path( 'files', File.dirname( __FILE__ ) )
8
+ end
9
+
10
+ before :each do
11
+ @ci = Simp::Cli::Config::Item::DNSServers.new
12
+ end
13
+
14
+ describe '#recommended_value' do
15
+ context 'when /etc/resolv.conf is populated' do
16
+ it 'handles a single nameserver' do
17
+ @ci.file = File.join(@files_dir,'resolv.conf__single')
18
+ expect( @ci.recommended_value.size).to eq 1
19
+ expect( @ci.recommended_value).to eq ['10.0.0.1']
20
+ end
21
+
22
+ it 'handles multiple nameservers' do
23
+ @ci.file = File.join(@files_dir,'resolv.conf__multiple')
24
+ expect( @ci.recommended_value.size).to eq 3
25
+ expect( @ci.recommended_value).to eq ['10.0.0.1', '10.0.0.2', '10.0.0.3']
26
+ end
27
+ end
28
+
29
+ context 'when /etc/resolv.conf is empty' do
30
+ before :each do
31
+ @ci.file = '/dev/null'
32
+ end
33
+
34
+ it 'recommends ipaddress (when available)' do
35
+ ip = Simp::Cli::Config::Item::IPAddress.new
36
+ ip.value = '1.2.3.4'
37
+ @ci.config_items[ ip.key ] = ip
38
+
39
+ expect( @ci.recommended_value ).to eq ['1.2.3.4']
40
+ end
41
+
42
+ it 'recommends a must-change value (when ipaddress is not available)' do
43
+ expect( @ci.recommended_value.first ).to match( /change/ )
44
+ end
45
+ end
46
+ end
47
+
48
+ describe '#validate' do
49
+ it 'validates array with good IPs' do
50
+ expect( @ci.validate ['10.0.71.1'] ).to eq true
51
+ expect( @ci.validate ['192.168.1.1', '8.8.8.8'] ).to eq true
52
+ end
53
+
54
+ it "doesn't validate array with bad IPs" do
55
+ expect( @ci.validate [nil] ).to eq false
56
+ expect( @ci.validate ['1.2.3'] ).to eq false
57
+ expect( @ci.validate ['1.2.3.999'] ).to eq false
58
+ expect( @ci.validate ['8.8.8.8.'] ).to eq false
59
+ expect( @ci.validate ['1.2.3.4.5'] ).to eq false
60
+ expect( @ci.validate ['1.2.3.4/24'] ).to eq false
61
+ end
62
+
63
+ it "doesn't validate empty array" do
64
+ expect( @ci.validate [] ).to eq false
65
+ end
66
+
67
+ it "doesn't validate nonsense" do
68
+ expect( @ci.validate 0 ).to eq false
69
+ expect( @ci.validate nil ).to eq false
70
+ expect( @ci.validate false ).to eq false
71
+ end
72
+ end
73
+
74
+ it_behaves_like 'a child of Simp::Cli::Config::Item'
75
+ end
76
+
@@ -0,0 +1,49 @@
1
+ require 'simp/cli/config/item/failover_log_servers'
2
+ require 'rspec/its'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::FailoverLogServers do
6
+ before :each do
7
+ @ci = Simp::Cli::Config::Item::FailoverLogServers.new
8
+ end
9
+
10
+ describe "#recommended_value" do
11
+ it "recommends nil when gateway is unavailable" do
12
+ expect( @ci.recommended_value ).to be_nil
13
+ end
14
+ end
15
+
16
+ describe "#validate" do
17
+ it "validates array with good hosts" do
18
+ expect( @ci.validate ['log'] ).to eq true
19
+ expect( @ci.validate ['log-server'] ).to eq true
20
+ expect( @ci.validate ['log.loggitylog.org'] ).to eq true
21
+ expect( @ci.validate ['192.168.1.1'] ).to eq true
22
+ expect( @ci.validate ['192.168.1.1', 'log.loggitylog.org'] ).to eq true
23
+
24
+ # failover_log_servers is optional and can be empty
25
+ expect( @ci.validate nil ).to eq true
26
+ expect( @ci.validate '' ).to eq true
27
+ expect( @ci.validate ' ' ).to eq true
28
+ end
29
+
30
+ it "doesn't validate array with bad hosts" do
31
+ expect( @ci.validate 0 ).to eq false
32
+ expect( @ci.validate false ).to eq false
33
+ expect( @ci.validate [nil] ).to eq false
34
+ expect( @ci.validate ['log-'] ).to eq false
35
+ expect( @ci.validate ['-log'] ).to eq false
36
+ expect( @ci.validate ['log.loggitylog.org.'] ).to eq false
37
+ expect( @ci.validate ['.log.loggitylog.org'] ).to eq false
38
+
39
+ end
40
+
41
+ it "accepts an empty list" do
42
+ expect( @ci.validate [] ).to eq true
43
+ expect( @ci.validate "" ).to eq true
44
+ end
45
+ end
46
+
47
+ it_behaves_like "a child of Simp::Cli::Config::Item"
48
+ end
49
+