puppet 2.7.14 → 2.7.16

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (111) hide show
  1. data/CHANGELOG +85 -0
  2. data/conf/redhat/puppet.spec +31 -4
  3. data/lib/puppet.rb +1 -1
  4. data/lib/puppet/defaults.rb +2 -3
  5. data/lib/puppet/face/module/install.rb +3 -3
  6. data/lib/puppet/face/module/search.rb +3 -3
  7. data/lib/puppet/indirector/face.rb +1 -1
  8. data/lib/puppet/network/http_pool.rb +17 -8
  9. data/lib/puppet/node/environment.rb +1 -3
  10. data/lib/puppet/parser/ast.rb +1 -1
  11. data/lib/puppet/parser/compiler.rb +2 -10
  12. data/lib/puppet/parser/functions/template.rb +2 -1
  13. data/lib/puppet/parser/lexer.rb +2 -2
  14. data/lib/puppet/parser/scope.rb +3 -2
  15. data/lib/puppet/provider/package/gem.rb +3 -1
  16. data/lib/puppet/provider/package/pkg.rb +18 -2
  17. data/lib/puppet/provider/service/gentoo.rb +5 -0
  18. data/lib/puppet/provider/service/init.rb +12 -14
  19. data/lib/puppet/provider/service/redhat.rb +1 -1
  20. data/lib/puppet/provider/service/upstart.rb +257 -7
  21. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +6 -9
  22. data/lib/puppet/reports/http.rb +1 -1
  23. data/lib/puppet/reports/tagmail.rb +1 -1
  24. data/lib/puppet/type/cron.rb +5 -0
  25. data/lib/puppet/type/filebucket.rb +12 -0
  26. data/lib/puppet/util.rb +15 -9
  27. data/lib/puppet/util/colors.rb +94 -64
  28. data/lib/puppet/util/platform.rb +15 -0
  29. data/man/man5/puppet.conf.5 +73 -27
  30. data/man/man8/filebucket.8 +1 -1
  31. data/man/man8/pi.8 +1 -1
  32. data/man/man8/puppet-agent.8 +17 -17
  33. data/man/man8/puppet-apply.8 +8 -3
  34. data/man/man8/puppet-ca.8 +183 -0
  35. data/man/man8/puppet-catalog.8 +17 -10
  36. data/man/man8/puppet-cert.8 +1 -1
  37. data/man/man8/puppet-certificate.8 +27 -11
  38. data/man/man8/puppet-certificate_request.8 +12 -11
  39. data/man/man8/puppet-certificate_revocation_list.8 +11 -10
  40. data/man/man8/puppet-config.8 +1 -1
  41. data/man/man8/puppet-describe.8 +1 -1
  42. data/man/man8/puppet-device.8 +2 -2
  43. data/man/man8/puppet-doc.8 +15 -3
  44. data/man/man8/puppet-facts.8 +18 -8
  45. data/man/man8/puppet-file.8 +13 -22
  46. data/man/man8/puppet-filebucket.8 +1 -1
  47. data/man/man8/puppet-help.8 +1 -1
  48. data/man/man8/puppet-inspect.8 +10 -2
  49. data/man/man8/puppet-instrumentation_data.8 +145 -0
  50. data/man/man8/puppet-instrumentation_listener.8 +222 -0
  51. data/man/man8/puppet-instrumentation_probe.8 +207 -0
  52. data/man/man8/puppet-key.8 +11 -7
  53. data/man/man8/puppet-kick.8 +35 -3
  54. data/man/man8/puppet-man.8 +1 -1
  55. data/man/man8/puppet-master.8 +1 -1
  56. data/man/man8/puppet-module.8 +451 -0
  57. data/man/man8/puppet-node.8 +64 -22
  58. data/man/man8/puppet-parser.8 +1 -1
  59. data/man/man8/puppet-plugin.8 +1 -1
  60. data/man/man8/puppet-queue.8 +1 -1
  61. data/man/man8/puppet-report.8 +12 -8
  62. data/man/man8/puppet-resource.8 +1 -1
  63. data/man/man8/puppet-resource_type.8 +11 -7
  64. data/man/man8/puppet-secret_agent.8 +1 -1
  65. data/man/man8/puppet-status.8 +11 -7
  66. data/man/man8/puppet.8 +1 -1
  67. data/man/man8/puppetca.8 +1 -1
  68. data/man/man8/puppetd.8 +17 -17
  69. data/man/man8/puppetdoc.8 +15 -3
  70. data/man/man8/puppetmasterd.8 +1 -1
  71. data/man/man8/puppetqd.8 +1 -1
  72. data/man/man8/puppetrun.8 +35 -3
  73. data/man/man8/ralsh.8 +1 -1
  74. data/spec/fixtures/unit/provider/package/gem/line-with-1.8.5-warning +14 -0
  75. data/spec/fixtures/unit/provider/package/pkg/{dummy → dummy_solaris10} +0 -0
  76. data/spec/fixtures/unit/provider/package/pkg/dummy_solaris11 +1 -0
  77. data/spec/fixtures/unit/provider/package/pkg/solaris11 +12 -0
  78. data/spec/fixtures/unit/provider/package/pkg/unknown_status +12 -0
  79. data/spec/fixtures/unit/provider/service/gentoo/rc_update_show +30 -0
  80. data/spec/integration/defaults_spec.rb +2 -7
  81. data/spec/integration/network/server/mongrel_spec.rb +16 -10
  82. data/spec/integration/network/server/webrick_spec.rb +16 -9
  83. data/spec/integration/provider/service/init_spec.rb +20 -4
  84. data/spec/integration/provider/ssh_authorized_key_spec.rb +119 -107
  85. data/spec/unit/face/module/install_spec.rb +16 -4
  86. data/spec/unit/network/http/api/v1_spec.rb +8 -0
  87. data/spec/unit/network/http_pool_spec.rb +80 -74
  88. data/spec/unit/node/environment_spec.rb +9 -4
  89. data/spec/unit/parser/ast/leaf_spec.rb +2 -2
  90. data/spec/unit/parser/ast_spec.rb +3 -3
  91. data/spec/unit/parser/compiler_spec.rb +0 -17
  92. data/spec/unit/parser/lexer_spec.rb +45 -2
  93. data/spec/unit/parser/scope_spec.rb +181 -14
  94. data/spec/unit/provider/package/gem_spec.rb +17 -1
  95. data/spec/unit/provider/package/pkg_spec.rb +70 -22
  96. data/spec/unit/provider/service/gentoo_spec.rb +237 -0
  97. data/spec/unit/provider/service/init_spec.rb +2 -2
  98. data/spec/unit/provider/service/redhat_spec.rb +2 -2
  99. data/spec/unit/provider/service/upstart_spec.rb +414 -5
  100. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +24 -0
  101. data/spec/unit/reports/tagmail_spec.rb +50 -0
  102. data/spec/unit/type/cron_spec.rb +21 -1
  103. data/spec/unit/type/filebucket_spec.rb +39 -9
  104. data/spec/unit/util/colors_spec.rb +69 -0
  105. data/spec/unit/util/log/destinations_spec.rb +17 -9
  106. data/spec/unit/util/log_spec.rb +2 -1
  107. data/spec/unit/util_spec.rb +11 -0
  108. data/tasks/rake/gem.rake +1 -1
  109. data/tasks/rake/manpages.rake +11 -3
  110. data/test/network/handler/fileserver.rb +7 -1
  111. metadata +22 -10
@@ -4,25 +4,41 @@ require 'spec_helper'
4
4
  provider = Puppet::Type.type(:service).provider(:init)
5
5
 
6
6
  describe provider, :'fails_on_ruby_1.9.2' => true do
7
- describe "when running on FreeBSD", :if => (Facter.value(:operatingsystem) == "FreeBSD") do
7
+ describe "when running on FreeBSD" do
8
+ before :each do
9
+ Facter.stubs(:value).with(:operatingsystem).returns 'FreeBSD'
10
+ end
11
+
8
12
  it "should set its default path to include /etc/rc.d and /usr/local/etc/rc.d" do
9
13
  provider.defpath.should == ["/etc/rc.d", "/usr/local/etc/rc.d"]
10
14
  end
11
15
  end
12
16
 
13
- describe "when running on HP-UX", :if => (Facter.value(:operatingsystem) == "HP-UX") do
17
+ describe "when running on HP-UX" do
18
+ before :each do
19
+ Facter.stubs(:value).with(:operatingsystem).returns 'HP-UX'
20
+ end
21
+
14
22
  it "should set its default path to include /sbin/init.d" do
15
23
  provider.defpath.should == "/sbin/init.d"
16
24
  end
17
25
  end
18
26
 
19
- describe "when running on Archlinux", :if => (Facter.value(:operatingsystem) == "Archlinux") do
27
+ describe "when running on Archlinux" do
28
+ before :each do
29
+ Facter.stubs(:value).with(:operatingsystem).returns 'Archlinux'
30
+ end
31
+
20
32
  it "should set its default path to include /etc/rc.d" do
21
33
  provider.defpath.should == "/etc/rc.d"
22
34
  end
23
35
  end
24
36
 
25
- describe "when not running on FreeBSD, HP-UX or Archlinux", :if => (! %w{HP-UX FreeBSD Archlinux}.include?(Facter.value(:operatingsystem))) do
37
+ describe "when not running on FreeBSD, HP-UX or Archlinux" do
38
+ before :each do
39
+ Facter.stubs(:value).with(:operatingsystem).returns 'RedHat'
40
+ end
41
+
26
42
  it "should set its default path to include /etc/init.d" do
27
43
  provider.defpath.should == "/etc/init.d"
28
44
  end
@@ -1,39 +1,63 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env rspec
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'puppet/file_bucket/dipper'
5
5
 
6
- describe "ssh_authorized_key provider (integration)", :unless => Puppet.features.microsoft_windows? do
6
+ describe Puppet::Type.type(:ssh_authorized_key).provider(:parsed), '(integration)', :unless => Puppet.features.microsoft_windows? do
7
7
  include PuppetSpec::Files
8
8
 
9
- before :each do
10
- @fake_userfile = tmpfile('authorized_keys.user')
11
- @fake_rootfile = tmpfile('authorized_keys.root')
9
+ let :fake_userfile do
10
+ tmpfile('authorized_keys.user')
11
+ end
12
+
13
+ let :fake_rootfile do
14
+ tmpfile('authorized_keys.root')
15
+ end
12
16
 
13
- # few testkeys generated with ssh-keygen
14
- @sample_rsa_keys = [
17
+ let :sample_rsa_keys do
18
+ [
15
19
  'AAAAB3NzaC1yc2EAAAADAQABAAAAgQCi18JBZOq10X3w4f67nVhO0O3s5Y1vHH4UgMSM3ZnQwbC5hjGyYSi9UULOoQQoQynI/a0I9NL423/Xk/XJVIKCHcS8q6V2Wmjd+fLNelOjxxoW6mbIytEt9rDvwgq3Mof3/m21L3t2byvegR00a+ikKbmInPmKwjeWZpexCIsHzQ==', # 1024 bit
16
20
  'AAAAB3NzaC1yc2EAAAADAQABAAAAgQDLClyvi3CsJw5Id6khZs2/+s11qOH4Gdp6iDioDsrIp0m8kSiPr71VGyQYAfPzzvHemHS7Xg0NkG1Kc8u9tRqBQfTvz7ubq0AT/g01+4P2hQ/soFkuwlUG/HVnnaYb6N0Qp5SHWvD5vBE2nFFQVpP5GrSctPtHSjzJq/i+6LYhmQ==', # 1024 bit
17
21
  'AAAAB3NzaC1yc2EAAAADAQABAAABAQDLygAO6txXkh9FNV8xSsBkATeqLbHzS7sFjGI3gt0Dx6q3LjyKwbhQ1RLf28kd5G6VWiXmClU/RtiPdUz8nrGuun++2mrxzrXrvpR9dq1lygLQ2wn2cI35dN5bjRMtXy3decs6HUhFo9MoNwX250rUWfdCyNPhGIp6OOfmjdy+UeLGNxq9wDx6i4bT5tVVSqVRtsEfw9+ICXchzl85QudjneVVpP+thriPZXfXA5eaGwAo/dmoKOIhUwF96gpdLqzNtrGQuxPbV80PTbGv9ZtAtTictxaDz8muXO7he9pXmchUpxUKtMFjHkL0FAZ9tRPmv3RA30sEr2fZ8+LKvnE50w0' #2048 Bit
18
22
  ]
19
- @sample_dsa_keys = [
23
+ end
24
+
25
+ let :sample_dsa_keys do
26
+ [
20
27
  'AAAAB3NzaC1kc3MAAACBAOPck2O8MIDSqxPSnvENt6tzRrKJ5oOhB6Nc6oEcWm+VEH1gvuxdiRqwoMgRwyEf1yUd+UAcLw3a6Jn+EtFyEBN/5WF+4Tt4xTxZ0Pfik2Wc5uqHbQ2dkmOoXiAOYPiD3JUQ1Xwm/J0CgetjitoLfzAGdCNhMqguqAuHcVJ78ZZbAAAAFQCIBKFYZ+I18I+dtgteirXh+VVEEwAAAIEAs1yvQ/wnLLrRCM660pF4kBiw3D6dJfMdCXWQpn0hZmkBQSIzZv4Wuk3giei5luxscDxNc+y3CTXtnyG4Kt1Yi2sOdvhRI3rX8tD+ejn8GHazM05l5VIo9uu4AQPIE32iV63IqgApSBbJ6vDJW91oDH0J492WdLCar4BS/KE3cRwAAACBAN0uSDyJqYLRsfYcFn4HyVf6TJxQm1IcwEt6GcJVzgjri9VtW7FqY5iBqa9B9Zdh5XXAYJ0XLsWQCcrmMHM2XGHGpA4gL9VlCJ/0QvOcXxD2uK7IXwAVUA7g4V4bw8EVnFv2Flufozhsp+4soo1xiYc5jiFVHwVlk21sMhAtKAeF' # 1024 Bit
21
28
  ]
29
+ end
22
30
 
23
- @sample_lines = [
24
- "ssh-rsa #{@sample_rsa_keys[1]} root@someotherhost",
25
- "ssh-dss #{@sample_dsa_keys[0]} root@anywhere",
26
- "ssh-rsa #{@sample_rsa_keys[2]} paul"
31
+ let :sample_lines do
32
+ [
33
+ "ssh-rsa #{sample_rsa_keys[1]} root@someotherhost",
34
+ "ssh-dss #{sample_dsa_keys[0]} root@anywhere",
35
+ "ssh-rsa #{sample_rsa_keys[2]} paul",
36
+ "ssh-rsa #{sample_rsa_keys[2]} dummy"
27
37
  ]
38
+ end
28
39
 
40
+ let :dummy do
41
+ Puppet::Type.type(:ssh_authorized_key).new(
42
+ :name => 'dummy',
43
+ :target => fake_userfile,
44
+ :user => 'nobody',
45
+ :ensure => :absent
46
+ )
47
+ end
48
+
49
+ before :each do
50
+ File.stubs(:chown)
51
+ File.stubs(:chmod)
52
+ Puppet::Util::SUIDManager.stubs(:asuser).yields
29
53
  end
30
54
 
31
55
  after :each do
32
- Puppet::Type::Ssh_authorized_key::ProviderParsed.clear # Work around bug #6628
56
+ described_class.clear # Work around bug #6628
33
57
  end
34
58
 
35
59
  def create_fake_key(username, content)
36
- filename = (username == :root ? @fake_rootfile : @fake_userfile )
60
+ filename = (username == :root ? fake_rootfile : fake_userfile )
37
61
  File.open(filename, 'w') do |f|
38
62
  content.each do |line|
39
63
  f.puts line
@@ -42,8 +66,8 @@ describe "ssh_authorized_key provider (integration)", :unless => Puppet.features
42
66
  end
43
67
 
44
68
  def check_fake_key(username, expected_content)
45
- filename = (username == :root ? @fake_rootfile : @fake_userfile )
46
- content = File.readlines(filename).map(&:chomp).sort.reject{ |x| x =~ /^#|^$/ }
69
+ filename = (username == :root ? fake_rootfile : fake_userfile )
70
+ content = File.readlines(filename).map(&:chomp).sort.reject{ |x| x =~ /^# HEADER:/ }
47
71
  content.join("\n").should == expected_content.sort.join("\n")
48
72
  end
49
73
 
@@ -58,150 +82,138 @@ describe "ssh_authorized_key provider (integration)", :unless => Puppet.features
58
82
  catalog.apply
59
83
  end
60
84
 
61
- describe "when managing one resource" do
85
+ it "should not complain about empty lines and comments" do
86
+ described_class.expects(:flush).never
87
+ sample = ['',sample_lines[0],' ',sample_lines[1],'# just a comment','#and another']
88
+ create_fake_key(:user,sample)
89
+ run_in_catalog(dummy)
90
+ check_fake_key(:user, sample)
91
+ end
62
92
 
63
- before :each do
64
- # We are not running as root so chown/chmod is not possible
65
- File.stubs(:chown)
66
- File.stubs(:chmod)
67
- Puppet::Util::SUIDManager.stubs(:asuser).yields
68
- end
93
+ it "should keep empty lines and comments when modifying a file" do
94
+ create_fake_key(:user, ['',sample_lines[0],' ',sample_lines[3],'# just a comment','#and another'])
95
+ run_in_catalog(dummy)
96
+ check_fake_key(:user, ['',sample_lines[0],' ','# just a comment','#and another'])
97
+ end
69
98
 
70
- describe "with ensure set to absent" do
99
+ describe "when managing one resource" do
71
100
 
72
- before :each do
73
- @example = Puppet::Type.type(:ssh_authorized_key).new(
101
+ describe "with ensure set to absent" do
102
+ let :example do
103
+ Puppet::Type.type(:ssh_authorized_key).new(
74
104
  :name => 'root@hostname',
75
105
  :type => :rsa,
76
- :key => @sample_rsa_keys[0],
77
- :target => @fake_rootfile,
106
+ :key => sample_rsa_keys[0],
107
+ :target => fake_rootfile,
78
108
  :user => 'root',
79
109
  :ensure => :absent
80
110
  )
81
111
  end
82
112
 
83
113
  it "should not modify root's keyfile if resource is currently not present" do
84
- create_fake_key(:root, @sample_lines)
85
- run_in_catalog(@example)
86
- check_fake_key(:root, @sample_lines)
114
+ create_fake_key(:root, sample_lines)
115
+ run_in_catalog(example)
116
+ check_fake_key(:root, sample_lines)
87
117
  end
88
118
 
89
119
  it "remove the key from root's keyfile if resource is currently present" do
90
- create_fake_key(:root, @sample_lines + ["ssh-rsa #{@sample_rsa_keys[0]} root@hostname"])
91
- run_in_catalog(@example)
92
- check_fake_key(:root, @sample_lines)
120
+ create_fake_key(:root, sample_lines + ["ssh-rsa #{sample_rsa_keys[0]} root@hostname"])
121
+ run_in_catalog(example)
122
+ check_fake_key(:root, sample_lines)
93
123
  end
94
-
95
124
  end
96
125
 
97
126
  describe "when ensure is present" do
98
-
99
- before :each do
100
- @example = Puppet::Type.type(:ssh_authorized_key).new(
127
+ let :example do
128
+ Puppet::Type.type(:ssh_authorized_key).new(
101
129
  :name => 'root@hostname',
102
130
  :type => :rsa,
103
- :key => @sample_rsa_keys[0],
104
- :target => @fake_rootfile,
131
+ :key => sample_rsa_keys[0],
132
+ :target => fake_rootfile,
105
133
  :user => 'root',
106
134
  :ensure => :present
107
135
  )
108
-
109
- # just a dummy so the parsedfile provider is aware
110
- # of the user's authorized_keys file
111
- @dummy = Puppet::Type.type(:ssh_authorized_key).new(
112
- :name => 'dummy',
113
- :target => @fake_userfile,
114
- :user => 'nobody',
115
- :ensure => :absent
116
- )
117
136
  end
118
137
 
138
+ # just a dummy so the parsedfile provider is aware
139
+ # of the user's authorized_keys file
140
+
119
141
  it "should add the key if it is not present" do
120
- create_fake_key(:root, @sample_lines)
121
- run_in_catalog(@example)
122
- check_fake_key(:root, @sample_lines + ["ssh-rsa #{@sample_rsa_keys[0]} root@hostname" ])
142
+ create_fake_key(:root, sample_lines)
143
+ run_in_catalog(example)
144
+ check_fake_key(:root, sample_lines + ["ssh-rsa #{sample_rsa_keys[0]} root@hostname" ])
123
145
  end
124
146
 
125
147
  it "should modify the type if type is out of sync" do
126
- create_fake_key(:root,@sample_lines + [ "ssh-dss #{@sample_rsa_keys[0]} root@hostname" ])
127
- run_in_catalog(@example)
128
- check_fake_key(:root, @sample_lines + [ "ssh-rsa #{@sample_rsa_keys[0]} root@hostname" ])
148
+ create_fake_key(:root,sample_lines + [ "ssh-dss #{sample_rsa_keys[0]} root@hostname" ])
149
+ run_in_catalog(example)
150
+ check_fake_key(:root, sample_lines + [ "ssh-rsa #{sample_rsa_keys[0]} root@hostname" ])
129
151
  end
130
152
 
131
153
  it "should modify the key if key is out of sync" do
132
- create_fake_key(:root,@sample_lines + [ "ssh-rsa #{@sample_rsa_keys[1]} root@hostname" ])
133
- run_in_catalog(@example)
134
- check_fake_key(:root, @sample_lines + [ "ssh-rsa #{@sample_rsa_keys[0]} root@hostname" ])
154
+ create_fake_key(:root,sample_lines + [ "ssh-rsa #{sample_rsa_keys[1]} root@hostname" ])
155
+ run_in_catalog(example)
156
+ check_fake_key(:root, sample_lines + [ "ssh-rsa #{sample_rsa_keys[0]} root@hostname" ])
135
157
  end
136
158
 
137
159
  it "should remove the key from old file if target is out of sync" do
138
- create_fake_key(:user, [ @sample_lines[0], "ssh-rsa #{@sample_rsa_keys[0]} root@hostname" ])
139
- create_fake_key(:root, [ @sample_lines[1], @sample_lines[2] ])
140
- run_in_catalog(@example, @dummy)
141
- check_fake_key(:user, [ @sample_lines[0] ])
142
- #check_fake_key(:root, [ @sample_lines[1], @sample_lines[2], "ssh-rsa #{@sample_rsa_keys[0]} root@hostname" ])
160
+ create_fake_key(:user, [ sample_lines[0], "ssh-rsa #{sample_rsa_keys[0]} root@hostname" ])
161
+ create_fake_key(:root, [ sample_lines[1], sample_lines[2] ])
162
+ run_in_catalog(example, dummy)
163
+ check_fake_key(:user, [ sample_lines[0] ])
164
+ #check_fake_key(:root, [ sample_lines[1], sample_lines[2], "ssh-rsa #{sample_rsa_keys[0]} root@hostname" ])
143
165
  end
144
166
 
145
167
  it "should add the key to new file if target is out of sync" do
146
- create_fake_key(:user, [ @sample_lines[0], "ssh-rsa #{@sample_rsa_keys[0]} root@hostname" ])
147
- create_fake_key(:root, [ @sample_lines[1], @sample_lines[2] ])
148
- run_in_catalog(@example, @dummy)
149
- #check_fake_key(:user, [ @sample_lines[0] ])
150
- check_fake_key(:root, [ @sample_lines[1], @sample_lines[2], "ssh-rsa #{@sample_rsa_keys[0]} root@hostname" ])
168
+ create_fake_key(:user, [ sample_lines[0], "ssh-rsa #{sample_rsa_keys[0]} root@hostname" ])
169
+ create_fake_key(:root, [ sample_lines[1], sample_lines[2] ])
170
+ run_in_catalog(example, dummy)
171
+ #check_fake_key(:user, [ sample_lines[0] ])
172
+ check_fake_key(:root, [ sample_lines[1], sample_lines[2], "ssh-rsa #{sample_rsa_keys[0]} root@hostname" ])
151
173
  end
152
174
 
153
175
  it "should modify options if options are out of sync" do
154
- @example[:options]=[ 'from="*.domain1,host1.domain2"', 'no-port-forwarding', 'no-pty' ]
155
- create_fake_key(:root, @sample_lines + [ "from=\"*.false,*.false2\",no-port-forwarding,no-pty ssh-rsa #{@sample_rsa_keys[0]} root@hostname"])
156
- run_in_catalog(@example)
157
- check_fake_key(:root, @sample_lines + [ "from=\"*.domain1,host1.domain2\",no-port-forwarding,no-pty ssh-rsa #{@sample_rsa_keys[0]} root@hostname"] )
176
+ example[:options]=[ 'from="*.domain1,host1.domain2"', 'no-port-forwarding', 'no-pty' ]
177
+ create_fake_key(:root, sample_lines + [ "from=\"*.false,*.false2\",no-port-forwarding,no-pty ssh-rsa #{sample_rsa_keys[0]} root@hostname"])
178
+ run_in_catalog(example)
179
+ check_fake_key(:root, sample_lines + [ "from=\"*.domain1,host1.domain2\",no-port-forwarding,no-pty ssh-rsa #{sample_rsa_keys[0]} root@hostname"] )
158
180
  end
159
-
160
181
  end
161
-
162
182
  end
163
183
 
164
184
  describe "when managing two resource" do
165
-
166
- before :each do
167
- # We are not running as root so chown/chmod is not possible
168
- File.stubs(:chown)
169
- File.stubs(:chmod)
170
- Puppet::Util::SUIDManager.stubs(:asuser).yields
171
- @example_one = Puppet::Type.type(:ssh_authorized_key).new(
172
- :name => 'root@hostname',
173
- :type => :rsa,
174
- :key => @sample_rsa_keys[0],
175
- :target => @fake_rootfile,
176
- :user => 'root',
177
- :ensure => :present
178
- )
179
-
180
- @example_two = Puppet::Type.type(:ssh_authorized_key).new(
181
- :name => 'user@hostname',
182
- :key => @sample_rsa_keys[1],
183
- :type => :rsa,
184
- :target => @fake_userfile,
185
- :user => 'nobody',
186
- :ensure => :present
187
- )
188
- end
185
+ let :examples do
186
+ resources = []
187
+ resources << Puppet::Type.type(:ssh_authorized_key).new(
188
+ :name => 'root@hostname',
189
+ :type => :rsa,
190
+ :key => sample_rsa_keys[0],
191
+ :target => fake_rootfile,
192
+ :user => 'root',
193
+ :ensure => :present
194
+ )
195
+ resources << Puppet::Type.type(:ssh_authorized_key).new(
196
+ :name => 'user@hostname',
197
+ :key => sample_rsa_keys[1],
198
+ :type => :rsa,
199
+ :target => fake_userfile,
200
+ :user => 'nobody',
201
+ :ensure => :present
202
+ )
203
+ resources
204
+ end
189
205
 
190
206
  describe "and both keys are absent" do
191
-
192
207
  before :each do
193
- create_fake_key(:root, @sample_lines)
194
- create_fake_key(:user, @sample_lines)
208
+ create_fake_key(:root, sample_lines)
209
+ create_fake_key(:user, sample_lines)
195
210
  end
196
211
 
197
212
  it "should add both keys" do
198
- run_in_catalog(@example_one, @example_two)
199
- check_fake_key(:root, @sample_lines + [ "ssh-rsa #{@sample_rsa_keys[0]} root@hostname" ])
200
- check_fake_key(:user, @sample_lines + [ "ssh-rsa #{@sample_rsa_keys[1]} user@hostname" ])
213
+ run_in_catalog(*examples)
214
+ check_fake_key(:root, sample_lines + [ "ssh-rsa #{sample_rsa_keys[0]} root@hostname" ])
215
+ check_fake_key(:user, sample_lines + [ "ssh-rsa #{sample_rsa_keys[1]} user@hostname" ])
201
216
  end
202
-
203
217
  end
204
-
205
218
  end
206
-
207
219
  end
@@ -3,6 +3,7 @@ require 'puppet/face'
3
3
  require 'puppet/module_tool'
4
4
 
5
5
  describe "puppet module install" do
6
+ include PuppetSpec::Files
6
7
 
7
8
  subject { Puppet::Face[:module, :current] }
8
9
 
@@ -24,10 +25,10 @@ describe "puppet module install" do
24
25
  end
25
26
 
26
27
  let(:sep) { File::PATH_SEPARATOR }
27
- let(:fakefirstpath) { "/my/fake/modpath" }
28
- let(:fakesecondpath) { "/other/fake/path" }
28
+ let(:fakefirstpath) { make_absolute("/my/fake/modpath") }
29
+ let(:fakesecondpath) { make_absolute("/other/fake/path") }
29
30
  let(:fakemodpath) { "#{fakefirstpath}#{sep}#{fakesecondpath}" }
30
- let(:fakedirpath) { "/my/fake/path" }
31
+ let(:fakedirpath) { make_absolute("/my/fake/path") }
31
32
 
32
33
  context "without any options" do
33
34
  it "should require a name" do
@@ -49,7 +50,7 @@ describe "puppet module install" do
49
50
  end
50
51
 
51
52
  it "should accept the --target-dir option" do
52
- options[:target_dir] = "/foo/puppet/modules"
53
+ options[:target_dir] = make_absolute("/foo/puppet/modules")
53
54
  expected_options.merge!(options)
54
55
  expected_options[:modulepath] = "#{options[:target_dir]}#{sep}#{fakemodpath}"
55
56
 
@@ -90,6 +91,17 @@ describe "puppet module install" do
90
91
  end
91
92
 
92
93
  describe "when target-dir option is passed" do
94
+ it "should expand the target directory" do
95
+ options[:target_dir] = "modules"
96
+ expanded_path = File.expand_path("modules")
97
+ expected_options.merge!(options)
98
+ expected_options[:target_dir] = expanded_path
99
+ expected_options[:modulepath] = "#{expanded_path}#{sep}#{fakemodpath}"
100
+
101
+ Puppet::ModuleTool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
102
+ subject.install("puppetlabs-apache", options)
103
+ end
104
+
93
105
  it "should set target-dir to be first path of modulepath" do
94
106
  options[:target_dir] = fakedirpath
95
107
  expected_options[:target_dir] = fakedirpath
@@ -54,6 +54,14 @@ describe Puppet::Network::HTTP::API::V1 do
54
54
  @tester.uri2indirection("GET", "/env/foo/bar", {})[3][:environment].should be_a Puppet::Node::Environment
55
55
  end
56
56
 
57
+ it "should not pass a buck_path parameter through (See Bugs #13553, #13518, #13511)" do
58
+ @tester.uri2indirection("GET", "/env/foo/bar", { :bucket_path => "/malicious/path" })[3].should_not include({ :bucket_path => "/malicious/path" })
59
+ end
60
+
61
+ it "should pass allowed parameters through" do
62
+ @tester.uri2indirection("GET", "/env/foo/bar", { :allowed_param => "value" })[3].should include({ :allowed_param => "value" })
63
+ end
64
+
57
65
  it "should use the second field of the URI as the indirection name" do
58
66
  @tester.uri2indirection("GET", "/env/foo/bar", {})[0].should == "foo"
59
67
  end
@@ -14,122 +14,128 @@ describe Puppet::Network::HttpPool do
14
14
  end
15
15
 
16
16
  describe "when managing http instances" do
17
- def stub_settings(settings)
18
- settings.each do |param, value|
19
- Puppet.settings.stubs(:value).with(param).returns(value)
20
- end
21
- end
22
-
23
- before do
17
+ before :each do
24
18
  # All of the cert stuff is tested elsewhere
25
19
  Puppet::Network::HttpPool.stubs(:cert_setup)
26
20
  end
27
21
 
28
22
  it "should return an http instance created with the passed host and port" do
29
- http = stub 'http', :use_ssl= => nil, :read_timeout= => nil, :open_timeout= => nil, :started? => false
30
- Net::HTTP.expects(:new).with("me", 54321, nil, nil).returns(http)
31
- Puppet::Network::HttpPool.http_instance("me", 54321).should equal(http)
23
+ http = Puppet::Network::HttpPool.http_instance("me", 54321)
24
+ http.should be_an_instance_of Net::HTTP
25
+ http.address.should == 'me'
26
+ http.port.should == 54321
32
27
  end
33
28
 
34
29
  it "should enable ssl on the http instance" do
35
- Puppet::Network::HttpPool.http_instance("me", 54321).instance_variable_get("@use_ssl").should be_true
30
+ Puppet::Network::HttpPool.http_instance("me", 54321).should be_use_ssl
36
31
  end
37
32
 
38
- it "should set the read timeout" do
39
- Puppet::Network::HttpPool.http_instance("me", 54321).read_timeout.should == 120
40
- end
33
+ context "proxy and timeout settings should propagate" do
34
+ subject { Puppet::Network::HttpPool.http_instance("me", 54321) }
35
+ before :each do
36
+ Puppet[:http_proxy_host] = "myhost"
37
+ Puppet[:http_proxy_port] = 432
38
+ Puppet[:configtimeout] = 120
39
+ end
41
40
 
42
- it "should set the open timeout" do
43
- Puppet::Network::HttpPool.http_instance("me", 54321).open_timeout.should == 120
41
+ its(:open_timeout) { should == Puppet[:configtimeout] }
42
+ its(:read_timeout) { should == Puppet[:configtimeout] }
43
+ its(:proxy_address) { should == Puppet[:http_proxy_host] }
44
+ its(:proxy_port) { should == Puppet[:http_proxy_port] }
44
45
  end
45
46
 
46
- it "should create the http instance with the proxy host and port set if the http_proxy is not set to 'none'" do
47
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
48
- Puppet::Network::HttpPool.http_instance("me", 54321).open_timeout.should == 120
47
+ it "should not set a proxy if the value is 'none'" do
48
+ Puppet[:http_proxy_host] = 'none'
49
+ Puppet::Network::HttpPool.http_instance("me", 54321).proxy_address.should be_nil
49
50
  end
50
51
 
51
52
  it "should not cache http instances" do
52
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
53
- old = Puppet::Network::HttpPool.http_instance("me", 54321)
54
- Puppet::Network::HttpPool.http_instance("me", 54321).should_not equal(old)
53
+ Puppet::Network::HttpPool.http_instance("me", 54321).
54
+ should_not equal Puppet::Network::HttpPool.http_instance("me", 54321)
55
55
  end
56
56
  end
57
57
 
58
- describe "when adding certificate information to http instances" do
59
- before do
60
- @http = mock 'http'
61
- [:cert_store=, :verify_mode=, :ca_file=, :cert=, :key=].each { |m| @http.stubs(m) }
62
- @store = stub 'store'
63
-
64
- @cert = stub 'cert', :content => "real_cert"
65
- @key = stub 'key', :content => "real_key"
66
- @host = stub 'host', :certificate => @cert, :key => @key, :ssl_store => @store
67
-
68
- Puppet[:confdir] = "/sometthing/else"
69
- Puppet.settings.stubs(:value).returns "/some/file"
70
- Puppet.settings.stubs(:value).with(:hostcert).returns "/host/cert"
71
- Puppet.settings.stubs(:value).with(:localcacert).returns "/local/ca/cert"
72
-
73
- FileTest.stubs(:exist?).with("/host/cert").returns true
74
- FileTest.stubs(:exist?).with("/local/ca/cert").returns true
75
-
76
- Puppet::Network::HttpPool.stubs(:ssl_host).returns @host
58
+ describe "when doing SSL setup for http instances" do
59
+ let :http do
60
+ http = Net::HTTP.new('localhost', 443)
61
+ http.use_ssl = true
62
+ http
77
63
  end
78
64
 
79
- after do
80
- Puppet.settings.clear
81
- end
65
+ let :store do stub('store') end
82
66
 
83
- it "should do nothing if no host certificate is on disk" do
84
- FileTest.expects(:exist?).with("/host/cert").returns false
85
- @http.expects(:cert=).never
86
- Puppet::Network::HttpPool.cert_setup(@http)
87
- end
67
+ before :each do
68
+ Puppet[:hostcert] = '/host/cert'
69
+ Puppet[:localcacert] = '/local/ca/cert'
88
70
 
89
- it "should do nothing if no local certificate is on disk" do
90
- FileTest.expects(:exist?).with("/local/ca/cert").returns false
91
- @http.expects(:cert=).never
92
- Puppet::Network::HttpPool.cert_setup(@http)
71
+ cert = stub 'cert', :content => 'real_cert'
72
+ key = stub 'key', :content => 'real_key'
73
+ host = stub 'host', :certificate => cert, :key => key, :ssl_store => store
74
+ Puppet::Network::HttpPool.stubs(:ssl_host).returns(host)
93
75
  end
94
76
 
95
- it "should add a certificate store from the ssl host" do
96
- @http.expects(:cert_store=).with(@store)
77
+ shared_examples "HTTPS setup without all certificates" do
78
+ subject { Puppet::Network::HttpPool.cert_setup(http); http }
97
79
 
98
- Puppet::Network::HttpPool.cert_setup(@http)
80
+ it { should be_use_ssl }
81
+ its(:cert) { should be_nil }
82
+ its(:cert_store) { should be_nil }
83
+ its(:ca_file) { should be_nil }
84
+ its(:key) { should be_nil }
85
+ its(:verify_mode) { should == OpenSSL::SSL::VERIFY_NONE }
99
86
  end
100
87
 
101
- it "should add the client certificate" do
102
- @http.expects(:cert=).with("real_cert")
88
+ context "with neither a host cert or a local CA cert" do
89
+ before :each do
90
+ FileTest.stubs(:exist?).with(Puppet[:hostcert]).returns(false)
91
+ FileTest.stubs(:exist?).with(Puppet[:localcacert]).returns(false)
92
+ end
103
93
 
104
- Puppet::Network::HttpPool.cert_setup(@http)
94
+ include_examples "HTTPS setup without all certificates"
105
95
  end
106
96
 
107
- it "should add the client key" do
108
- @http.expects(:key=).with("real_key")
97
+ context "with there is no host certificate" do
98
+ before :each do
99
+ FileTest.stubs(:exist?).with(Puppet[:hostcert]).returns(false)
100
+ FileTest.stubs(:exist?).with(Puppet[:localcacert]).returns(true)
101
+ end
109
102
 
110
- Puppet::Network::HttpPool.cert_setup(@http)
103
+ include_examples "HTTPS setup without all certificates"
111
104
  end
112
105
 
113
- it "should set the verify mode to OpenSSL::SSL::VERIFY_PEER" do
114
- @http.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
106
+ context "with there is no local CA certificate" do
107
+ before :each do
108
+ FileTest.stubs(:exist?).with(Puppet[:hostcert]).returns(true)
109
+ FileTest.stubs(:exist?).with(Puppet[:localcacert]).returns(false)
110
+ end
115
111
 
116
- Puppet::Network::HttpPool.cert_setup(@http)
112
+ include_examples "HTTPS setup without all certificates"
117
113
  end
118
114
 
119
- it "should set the ca file" do
120
- Puppet.settings.stubs(:value).returns "/some/file"
121
- FileTest.stubs(:exist?).with(Puppet[:hostcert]).returns true
115
+ context "with both the host and CA cert" do
116
+ subject { Puppet::Network::HttpPool.cert_setup(http); http }
122
117
 
123
- Puppet.settings.stubs(:value).with(:localcacert).returns "/ca/cert/file"
124
- FileTest.stubs(:exist?).with("/ca/cert/file").returns true
125
- @http.expects(:ca_file=).with("/ca/cert/file")
118
+ before :each do
119
+ FileTest.expects(:exist?).with(Puppet[:hostcert]).returns(true)
120
+ FileTest.expects(:exist?).with(Puppet[:localcacert]).returns(true)
121
+ end
126
122
 
127
- Puppet::Network::HttpPool.cert_setup(@http)
123
+ it { should be_use_ssl }
124
+ its(:cert_store) { should equal store }
125
+ its(:cert) { should == "real_cert" }
126
+ its(:key) { should == "real_key" }
127
+ its(:verify_mode) { should == OpenSSL::SSL::VERIFY_PEER }
128
+ its(:ca_file) { should == Puppet[:localcacert] }
128
129
  end
129
130
 
130
131
  it "should set up certificate information when creating http instances" do
131
- Puppet::Network::HttpPool.expects(:cert_setup).with { |i| i.is_a?(Net::HTTP) }
132
- Puppet::Network::HttpPool.http_instance("one", "two")
132
+ Puppet::Network::HttpPool.expects(:cert_setup).with do |http|
133
+ http.should be_an_instance_of Net::HTTP
134
+ http.address.should == "one"
135
+ http.port.should == 2
136
+ end
137
+
138
+ Puppet::Network::HttpPool.http_instance("one", 2)
133
139
  end
134
140
  end
135
141
  end