simp-cli 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
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,22 @@
1
+ shared_examples 'a child of Simp::Cli::Config::Item' do
2
+ describe '#to_yaml_s' do
3
+ it 'does not contain FIXME' do
4
+ expect( @ci.to_yaml_s ).not_to match(/FIXME/)
5
+ end
6
+ end
7
+
8
+ describe '#key' do
9
+ it 'returns a String' do
10
+ expect( @ci.key ).to be_a_kind_of(String)
11
+ end
12
+ end
13
+ end
14
+
15
+
16
+ shared_examples "an Item that doesn't output YAML" do
17
+ describe "#to_yaml_s" do
18
+ it "is empty" do
19
+ expect( @ci.to_yaml_s.to_s ).to be_empty
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ require 'simp/cli/config/item/use_auditd'
2
+ require 'rspec/its'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::UseAuditd do
6
+ before :each do
7
+ @ci = Simp::Cli::Config::Item::UseAuditd.new
8
+ end
9
+
10
+ describe "#validate" do
11
+ it "validates yes/no" do
12
+ expect( @ci.validate 'yes' ).to eq true
13
+ expect( @ci.validate 'y' ).to eq true
14
+ expect( @ci.validate 'Y' ).to eq true
15
+ expect( @ci.validate 'no' ).to eq true
16
+ expect( @ci.validate 'n' ).to eq true
17
+ expect( @ci.validate 'NO' ).to eq true
18
+ expect( @ci.validate true ).to eq true
19
+ expect( @ci.validate false ).to eq true
20
+ end
21
+
22
+ it "doesn't validate other things" do
23
+ expect( @ci.validate 'ydd' ).to eq false
24
+ expect( @ci.validate 'gsdg' ).to eq false
25
+ end
26
+ end
27
+
28
+ it_behaves_like "a child of Simp::Cli::Config::Item"
29
+ end
@@ -0,0 +1,29 @@
1
+ require 'simp/cli/config/item/use_fips'
2
+ require 'rspec/its'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::UseFips do
6
+ before :each do
7
+ @ci = Simp::Cli::Config::Item::UseFips.new
8
+ end
9
+
10
+ describe "#validate" do
11
+ it "validates yes/no" do
12
+ expect( @ci.validate 'yes' ).to eq true
13
+ expect( @ci.validate 'y' ).to eq true
14
+ expect( @ci.validate 'Y' ).to eq true
15
+ expect( @ci.validate 'no' ).to eq true
16
+ expect( @ci.validate 'n' ).to eq true
17
+ expect( @ci.validate 'NO' ).to eq true
18
+ expect( @ci.validate true ).to eq true
19
+ expect( @ci.validate false ).to eq true
20
+ end
21
+
22
+ it "doesn't validate other things" do
23
+ expect( @ci.validate 'ydd' ).to eq false
24
+ expect( @ci.validate 'gsdg' ).to eq false
25
+ end
26
+ end
27
+
28
+ it_behaves_like "a child of Simp::Cli::Config::Item"
29
+ end
@@ -0,0 +1,29 @@
1
+ require 'simp/cli/config/item/use_iptables'
2
+ require 'rspec/its'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::UseIPtables do
6
+ before :each do
7
+ @ci = Simp::Cli::Config::Item::UseIPtables.new
8
+ end
9
+
10
+ describe "#validate" do
11
+ it "validates yes/no" do
12
+ expect( @ci.validate 'yes' ).to eq true
13
+ expect( @ci.validate 'y' ).to eq true
14
+ expect( @ci.validate 'Y' ).to eq true
15
+ expect( @ci.validate 'no' ).to eq true
16
+ expect( @ci.validate 'n' ).to eq true
17
+ expect( @ci.validate 'NO' ).to eq true
18
+ expect( @ci.validate true ).to eq true
19
+ expect( @ci.validate false ).to eq true
20
+ end
21
+
22
+ it "doesn't validate other things" do
23
+ expect( @ci.validate 'ydd' ).to eq false
24
+ expect( @ci.validate 'gsdg' ).to eq false
25
+ end
26
+ end
27
+
28
+ it_behaves_like "a child of Simp::Cli::Config::Item"
29
+ end
@@ -0,0 +1,29 @@
1
+ require 'simp/cli/config/item/use_ldap'
2
+ require 'rspec/its'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::UseLdap do
6
+ before :each do
7
+ @ci = Simp::Cli::Config::Item::UseLdap.new
8
+ end
9
+
10
+ describe "#validate" do
11
+ it "validates yes/no" do
12
+ expect( @ci.validate 'yes' ).to eq true
13
+ expect( @ci.validate 'y' ).to eq true
14
+ expect( @ci.validate 'Y' ).to eq true
15
+ expect( @ci.validate 'no' ).to eq true
16
+ expect( @ci.validate 'n' ).to eq true
17
+ expect( @ci.validate 'NO' ).to eq true
18
+ expect( @ci.validate true ).to eq true
19
+ expect( @ci.validate false ).to eq true
20
+ end
21
+
22
+ it "doesn't validate other things" do
23
+ expect( @ci.validate 'ydd' ).to eq false
24
+ expect( @ci.validate 'gsdg' ).to eq false
25
+ end
26
+ end
27
+
28
+ it_behaves_like "a child of Simp::Cli::Config::Item"
29
+ end
@@ -0,0 +1,24 @@
1
+ require 'simp/cli/config/item/use_selinux'
2
+ require 'rspec/its'
3
+ require_relative( 'spec_helper' )
4
+
5
+ describe Simp::Cli::Config::Item::UseSELinux do
6
+ before :each do
7
+ @ci = Simp::Cli::Config::Item::UseSELinux.new
8
+ end
9
+
10
+ describe "#validate" do
11
+ it "validates valid values" do
12
+ expect( @ci.validate 'enforcing' ).to eq true
13
+ expect( @ci.validate 'permissive' ).to eq true
14
+ expect( @ci.validate 'disabled' ).to eq true
15
+ end
16
+
17
+ it "doesn't validate other things" do
18
+ expect( @ci.validate 'ydd' ).to eq false
19
+ expect( @ci.validate nil ).to eq false
20
+ end
21
+ end
22
+
23
+ it_behaves_like "a child of Simp::Cli::Config::Item"
24
+ end
@@ -0,0 +1,94 @@
1
+ require 'simp/cli/config/item/yum_repositories'
2
+ require 'simp/cli/config/item/is_master_yum_server'
3
+ require 'rspec/its'
4
+ require 'tmpdir'
5
+ require_relative( 'spec_helper' )
6
+
7
+ describe Simp::Cli::Config::Item::YumRepositories do
8
+ context "in a SIMP directory structure"
9
+ before :each do
10
+ @files_dir = File.expand_path( 'files', File.dirname( __FILE__ ) )
11
+ @tmp_dir = Dir.mktmpdir( File.basename( __FILE__ ) )
12
+ @tmp_yum_dir = File.expand_path( 'yum', @tmp_dir )
13
+ @tmp_repos_d = File.expand_path( 'yum.repos.d', @tmp_dir )
14
+ yaml_file = File.join( @files_dir, 'puppet.your.domain.yaml' )
15
+ @tmp_yaml_file = File.join( @tmp_dir, 'puppet.your.domain.yaml__YumRepositories' )
16
+ FileUtils.cp( yaml_file, @tmp_yaml_file )
17
+
18
+ FileUtils.mkdir_p @tmp_yum_dir
19
+ FileUtils.mkdir_p @tmp_repos_d
20
+
21
+ @ci = Simp::Cli::Config::Item::YumRepositories.new
22
+ @ci.www_yum_dir = @tmp_yum_dir
23
+ @ci.yum_repos_d = @tmp_repos_d
24
+ @ci.yaml_file = @tmp_yaml_file
25
+ @ci.silent = true
26
+ end
27
+
28
+ describe '#apply' do
29
+ before :each do
30
+ @fake_facts = {
31
+ 'operatingsystem' => 'TrevOS',
32
+ 'operatingsystemrelease' => '9.9',
33
+ 'architecture' => 'ia64'
34
+ }
35
+ @fake_facts.each{ |k,v| ENV["FACTER_#{k}"] = v }
36
+ @yum_dist_dir = File.join(
37
+ @tmp_yum_dir,
38
+ @fake_facts['operatingsystem'],
39
+ @fake_facts['operatingsystemrelease'],
40
+ @fake_facts['architecture']
41
+ )
42
+ FileUtils.remove_entry_secure @yum_dist_dir if File.exists? @yum_dist_dir
43
+ FileUtils.mkdir_p @yum_dist_dir
44
+ item = Simp::Cli::Config::Item::IsMasterYumServer.new
45
+ item.value = true
46
+ @ci.config_items[item.key] = item
47
+ end
48
+
49
+ it 'creates the yum Updates directory' do
50
+ result = @ci.apply
51
+ expect( File.directory?( File.join( @yum_dist_dir, 'Updates') ) ).to eq( true )
52
+ end
53
+
54
+ it 'generates the yum Updates repo metadata' do
55
+ result = @ci.apply
56
+ file = File.join( @yum_dist_dir, 'Updates', 'repodata', 'repomd.xml' )
57
+
58
+ if (value = ENV['SIMP_SKIP_NON_SIMPOS_TESTS'])
59
+ skip "skipping because env var SIMP_SKIP_NON_SIMPOS_TESTS is set to #{value}"
60
+ else
61
+ expect( File.exists?( file )).to eq( true )
62
+ expect( File.size?( file ) ).to be_truthy
63
+ end
64
+ end
65
+
66
+ it 'enables simp::yum::enable_simp_repos in hiera' do
67
+ result = @ci.apply
68
+ lines = File.readlines( @tmp_yaml_file ).join( "\n" )
69
+ expect( lines ).to match(%r{^simp::yum::enable_simp_repos\s*:\s*true})
70
+ end
71
+
72
+ it 'does not enable simp::yum::enable_simp_repos in hiera when IsMasterYumServer is false' do
73
+ item = Simp::Cli::Config::Item::IsMasterYumServer.new
74
+ item.value = false
75
+ @ci.config_items[item.key] = item
76
+ result = @ci.apply
77
+ lines = File.readlines( @tmp_yaml_file ).join( "\n" )
78
+ expect( lines ).to_not match(%r{^simp::yum::enable_simp_repos\s*:\s*true})
79
+ end
80
+
81
+ it 'returns true' do
82
+ result = @ci.apply
83
+ expect( result ).to eq true
84
+ end
85
+
86
+ it_behaves_like "an Item that doesn't output YAML"
87
+ it_behaves_like 'a child of Simp::Cli::Config::Item'
88
+
89
+ after :each do
90
+ @fake_facts.each{ |k,v| ENV.delete "FACTER_#{k}" }
91
+ FileUtils.remove_entry_secure @tmp_dir
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,106 @@
1
+ require 'simp/cli/config/item'
2
+ require 'rspec/its'
3
+ require_relative 'spec_helper'
4
+
5
+ describe Simp::Cli::Config::Item do
6
+ before :each do
7
+ @ci = Simp::Cli::Config::Item.new
8
+ end
9
+
10
+ describe "#initialize" do
11
+ it "has no value when initialized" do
12
+ expect( @ci.value ).to eq nil
13
+ end
14
+
15
+ it "has nil values when initialized" do
16
+ expect( @ci.os_value ).to be_nil
17
+ end
18
+ end
19
+
20
+ describe "#print_summary" do
21
+ it "raises a RuntimeError on nil @key" do
22
+ @ci.key = nil
23
+ expect{ @ci.print_summary }.to raise_error( RuntimeError )
24
+ end
25
+
26
+ it "raises a RuntimeError on empty @key" do
27
+ @ci.key = ""
28
+ expect{ @ci.print_summary }.to raise_error( RuntimeError )
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ describe Simp::Cli::Config::ListItem do
35
+ before :each do
36
+ @ci = Simp::Cli::Config::ListItem.new
37
+ end
38
+
39
+ context "when @allow_empty_list = true" do
40
+ before :each do
41
+ @ci.allow_empty_list = false
42
+ @ci.value = []
43
+ end
44
+
45
+ describe "#validate" do
46
+ it "doesn't validate an empty array" do
47
+ expect( @ci.validate [] ).to eq false
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ describe Simp::Cli::Config::ActionItem do
54
+ before :each do
55
+ @ci = Simp::Cli::Config::ActionItem.new
56
+ @ci.key = "action::item"
57
+ # @ci.silent = true
58
+ end
59
+
60
+ describe "#apply" do
61
+ before :all do
62
+ @user ||= ENV.fetch('USER')
63
+ ENV['USER'] = 'root' # fake user as root
64
+ end
65
+ context "(when @skip_apply = true)" do
66
+ before :each do; @ci.skip_apply = true ; end
67
+
68
+ it "does blah" do
69
+ skip 'TODO: how shall we test generic safe_apply?'
70
+ @ci.safe_apply
71
+ end
72
+ end
73
+
74
+ context "(when @skip_apply = false)" do
75
+ before :each do; @ci.skip_apply = false ; end
76
+
77
+ it "does blah" do
78
+ skip 'TODO: how shall we test generic safe_apply?'
79
+ @ci.safe_apply
80
+ end
81
+ end
82
+
83
+ after :all do
84
+ ENV['USER']=@user
85
+ end
86
+ end
87
+ end
88
+
89
+
90
+
91
+ describe Simp::Cli::Config::PasswordItem do
92
+ before :each do
93
+ @ci = Simp::Cli::Config::PasswordItem.new
94
+ @ci.silent = true
95
+ end
96
+
97
+ it "validates good passwords" do
98
+ expect( @ci.validate( 'duP3rP@ssw0r!' ) ).to eq true
99
+ end
100
+
101
+ it "doesn't validate bad passwords" do
102
+ expect( @ci.validate( 'short' ) ).to eq false
103
+ expect( @ci.validate( '' ) ).to eq false
104
+ expect( @ci.validate( '123456789' ) ).to eq false
105
+ end
106
+ end
@@ -0,0 +1 @@
1
+ require_relative 'item/spec_helper' #TODO: remove after moving all child tests into items/
@@ -0,0 +1,131 @@
1
+ require 'simp/cli/config/utils'
2
+ require 'rspec/its'
3
+ require_relative 'spec_helper'
4
+
5
+ describe Simp::Cli::Config::Utils do
6
+ describe ".validate_fqdn" do
7
+ it "validates good FQDNs" do
8
+ expect( Simp::Cli::Config::Utils.validate_fqdn 'simp.dev' ).to eq true
9
+ expect( Simp::Cli::Config::Utils.validate_fqdn 'si-mp.dev' ).to eq true
10
+
11
+ # RFC 1123 permits hostname labels to start with digits (overriding RFC 952)
12
+ expect( Simp::Cli::Config::Utils.validate_fqdn '0simp.dev' ).to eq true
13
+ end
14
+
15
+ it "doesn't validate bad FQDNS" do
16
+ expect( Simp::Cli::Config::Utils.validate_fqdn '.simp.dev' ).to eq false
17
+ expect( Simp::Cli::Config::Utils.validate_fqdn 'simp.dev.' ).to eq false
18
+ expect( Simp::Cli::Config::Utils.validate_fqdn '-simp.dev' ).to eq false
19
+ expect( Simp::Cli::Config::Utils.validate_fqdn 'simp.dev-' ).to eq false
20
+ end
21
+ end
22
+
23
+
24
+ describe ".validate_ip" do
25
+ it "validates good IPs" do
26
+ expect( Simp::Cli::Config::Utils.validate_ip '192.168.1.1' ).to eq true
27
+ end
28
+
29
+ it "doesn't validate bad IPS" do
30
+ expect( Simp::Cli::Config::Utils.validate_ip 0 ).to eq false
31
+ expect( Simp::Cli::Config::Utils.validate_ip false ).to eq false
32
+ expect( Simp::Cli::Config::Utils.validate_ip nil ).to eq false
33
+ expect( Simp::Cli::Config::Utils.validate_ip 'zombo.com' ).to eq false
34
+ expect( Simp::Cli::Config::Utils.validate_ip '1.2.3' ).to eq false
35
+ expect( Simp::Cli::Config::Utils.validate_ip '1.2.3.999' ).to eq false
36
+ expect( Simp::Cli::Config::Utils.validate_ip '8.8.8.8.' ).to eq false
37
+ expect( Simp::Cli::Config::Utils.validate_ip '1.2.3.4.5' ).to eq false
38
+ expect( Simp::Cli::Config::Utils.validate_ip '1.2.3.4/24' ).to eq false
39
+ end
40
+ end
41
+
42
+
43
+ describe ".validate_hostname" do
44
+ it "validates good hostnames" do
45
+ expect( Simp::Cli::Config::Utils.validate_hostname 'log' ).to eq true
46
+ expect( Simp::Cli::Config::Utils.validate_hostname 'log-server' ).to eq true
47
+
48
+ # RFC 1123 permits hostname labels to start with digits (overriding RFC 952)
49
+ expect( Simp::Cli::Config::Utils.validate_hostname '0log' ).to eq true
50
+ end
51
+
52
+ it "doesn't validate bad hostnames" do
53
+ expect( Simp::Cli::Config::Utils.validate_hostname 'log-' ).to eq false
54
+ expect( Simp::Cli::Config::Utils.validate_hostname 'log.' ).to eq false
55
+ expect( Simp::Cli::Config::Utils.validate_hostname '-log' ).to eq false
56
+
57
+ # longer than 63 chars
58
+ expect( Simp::Cli::Config::Utils.validate_hostname \
59
+ 'log0234567891234567890223456789323456789423456789523456789623459'
60
+ ).to eq false
61
+ end
62
+ end
63
+
64
+
65
+ describe ".validate_hiera_lookup" do
66
+ it "validates correct hiera lookup syntax" do
67
+ expect( Simp::Cli::Config::Utils.validate_hiera_lookup "%{hiera('puppet::ca')}" ).to eq true
68
+ expect( Simp::Cli::Config::Utils.validate_hiera_lookup "%{::domain}" ).to eq true
69
+ end
70
+
71
+ it "validates correct hiera lookup syntax" do
72
+ expect( Simp::Cli::Config::Utils.validate_hiera_lookup "%[hiera('puppet::ca')]" ).to eq false
73
+ expect( Simp::Cli::Config::Utils.validate_hiera_lookup '' ).to eq false
74
+ expect( Simp::Cli::Config::Utils.validate_hiera_lookup 'foo' ).to eq false
75
+ expect( Simp::Cli::Config::Utils.validate_hiera_lookup nil).to eq false
76
+ end
77
+ end
78
+
79
+
80
+ describe ".validate_password" do
81
+ it "validates good passwords" do
82
+ expect( Simp::Cli::Config::Utils.validate_password 'dup3rP@ssw0r!x' ).to eq true
83
+ end
84
+
85
+ it "raises an PasswordError on short passwords" do
86
+ expect{ Simp::Cli::Config::Utils.validate_password 'a@1X' }.to raise_error( Simp::Cli::Config::PasswordError )
87
+ end
88
+
89
+ it "raises an PasswordError on simple passwords" do
90
+ expect{ Simp::Cli::Config::Utils.validate_password 'aaaaaaaaaaaaaaa' }.to raise_error( Simp::Cli::Config::PasswordError )
91
+ end
92
+ end
93
+
94
+
95
+ describe ".generate_password" do
96
+ it "is the correct length" do
97
+ expect( Simp::Cli::Config::Utils.generate_password.size ).to eq 32
98
+ expect( Simp::Cli::Config::Utils.generate_password( 73 ).size ).to eq 73
99
+ end
100
+
101
+ it "does not start or end with a special character" do
102
+ expect( Simp::Cli::Config::Utils.generate_password ).to_not match /^[#%&_.:@-]|[#%&_.:@-]$/
103
+ end
104
+ end
105
+
106
+
107
+ describe ".encrypt_openldap_hash" do
108
+ it "encrypts a known password and salt to the correct SHA-1 password hash" do
109
+ expect( Simp::Cli::Config::Utils.encrypt_openldap_hash \
110
+ 'foo', "\xef\xb2\x2e\xac"
111
+ ).to eq '{SSHA}zxOLQEdncCJTMObl5s+y1N/Ydh3vsi6s'
112
+ end
113
+ end
114
+
115
+
116
+ describe ".validate_openldap_hash" do
117
+ it "validates OpenLDAP-format SHA-1 algorithm (FIPS 160-1) password hash" do
118
+ expect( Simp::Cli::Config::Utils.validate_openldap_hash \
119
+ '{SSHA}Y6x92VpatHf9G6yMiktUYTrA/3SxUFm'
120
+ ).to eq true
121
+ end
122
+ end
123
+
124
+
125
+ describe ".generate_certificates" do
126
+ it "runs './gencerts_nopass.sh auto' in the FakeCA dir" do
127
+ # TODO: scaffold a FakeCA dir, cacertkey, and ./gencerts_nopass.sh?
128
+ skip 'How should we test this?'
129
+ end
130
+ end
131
+ end