puppet 2.6.17 → 2.6.18

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 (43) hide show
  1. data/CHANGELOG +25 -0
  2. data/conf/auth.conf +3 -3
  3. data/conf/redhat/puppet.spec +5 -2
  4. data/lib/puppet.rb +1 -1
  5. data/lib/puppet/indirector/catalog/compiler.rb +13 -2
  6. data/lib/puppet/indirector/errors.rb +5 -0
  7. data/lib/puppet/indirector/file_bucket_file/file.rb +4 -0
  8. data/lib/puppet/indirector/file_bucket_file/selector.rb +4 -0
  9. data/lib/puppet/indirector/indirection.rb +1 -0
  10. data/lib/puppet/indirector/request.rb +4 -0
  11. data/lib/puppet/indirector/resource/ral.rb +4 -0
  12. data/lib/puppet/indirector/resource/validator.rb +8 -0
  13. data/lib/puppet/indirector/rest.rb +4 -0
  14. data/lib/puppet/indirector/run/local.rb +4 -0
  15. data/lib/puppet/indirector/terminus.rb +20 -0
  16. data/lib/puppet/network/http/handler.rb +9 -0
  17. data/lib/puppet/network/http/rack/rest.rb +7 -2
  18. data/lib/puppet/network/http/webrick.rb +1 -0
  19. data/lib/puppet/network/http_pool.rb +17 -8
  20. data/lib/puppet/network/rest_authconfig.rb +1 -1
  21. data/lib/puppet/parser/templatewrapper.rb +13 -12
  22. data/lib/puppet/util/monkey_patches.rb +43 -0
  23. data/spec/integration/indirector/bucket_file/rest_spec.rb +1 -1
  24. data/spec/integration/indirector/catalog/compiler_spec.rb +1 -0
  25. data/spec/integration/indirector/catalog/queue_spec.rb +1 -1
  26. data/spec/integration/indirector/certificate_request/rest_spec.rb +1 -1
  27. data/spec/integration/indirector/report/rest_spec.rb +1 -1
  28. data/spec/integration/resource/catalog_spec.rb +1 -0
  29. data/spec/unit/indirector/catalog/compiler_spec.rb +30 -3
  30. data/spec/unit/indirector/indirection_spec.rb +18 -1
  31. data/spec/unit/indirector/request_spec.rb +22 -0
  32. data/spec/unit/indirector/terminus_spec.rb +186 -174
  33. data/spec/unit/network/http/handler_spec.rb +1 -0
  34. data/spec/unit/network/http/rack/rest_spec.rb +17 -0
  35. data/spec/unit/network/http/webrick_spec.rb +4 -0
  36. data/spec/unit/network/http_pool_spec.rb +93 -80
  37. data/spec/unit/network/rest_authconfig_spec.rb +16 -3
  38. data/spec/unit/parser/functions/inline_template_spec.rb +14 -1
  39. data/spec/unit/parser/functions/template_spec.rb +18 -1
  40. data/spec/unit/parser/templatewrapper_spec.rb +24 -9
  41. data/spec/unit/util/monkey_patches_spec.rb +11 -1
  42. data/test/language/snippets.rb +1 -1
  43. metadata +7 -5
@@ -417,6 +417,7 @@ describe Puppet::Network::HTTP::Handler do
417
417
 
418
418
  @model_instance = stub('indirected model instance', :save => true)
419
419
  @model_class.stubs(:convert_from).returns(@model_instance)
420
+ @model_class.stubs(:===).with(@model_instance).returns(true)
420
421
 
421
422
  @format = stub 'format', :suitable? => true, :name => "format", :mime => "text/format"
422
423
  Puppet::Network::FormatHandler.stubs(:format).returns @format
@@ -92,6 +92,23 @@ describe "Puppet::Network::HTTP::RackREST", :if => Puppet.features.rack? do
92
92
  @handler.set_response(@response, @file, 200)
93
93
  end
94
94
  end
95
+
96
+ it "should ensure the body has been read on success" do
97
+ req = mk_req('/production/report/foo', :method => 'PUT')
98
+ req.body.expects(:read).at_least_once
99
+
100
+ Puppet::Transaction::Report.stubs(:save)
101
+
102
+ @handler.process(req, @response)
103
+ end
104
+
105
+ it "should ensure the body has been partially read on failure" do
106
+ req = mk_req('/production/report/foo')
107
+ req.body.expects(:read).with(1)
108
+ req.stubs(:check_authorization).raises(Exception)
109
+
110
+ @handler.process(req, @response)
111
+ end
95
112
  end
96
113
 
97
114
  describe "and determining the request parameters" do
@@ -320,6 +320,10 @@ describe Puppet::Network::HTTP::WEBrick do
320
320
  @server.setup_ssl[:SSLEnable].should be_true
321
321
  end
322
322
 
323
+ it "should reject SSLv2" do
324
+ @server.setup_ssl[:SSLOptions].should == OpenSSL::SSL::OP_NO_SSLv2
325
+ end
326
+
323
327
  it "should configure the verification method as 'OpenSSL::SSL::VERIFY_PEER'" do
324
328
  @server.setup_ssl[:SSLVerifyClient].should == OpenSSL::SSL::VERIFY_PEER
325
329
  end
@@ -24,38 +24,34 @@ describe Puppet::Network::HttpPool do
24
24
  end
25
25
 
26
26
  describe "when managing http instances" do
27
- def stub_settings(settings)
28
- settings.each do |param, value|
29
- Puppet.settings.stubs(:value).with(param).returns(value)
30
- end
31
- end
32
-
33
- before do
27
+ before :each do
34
28
  # All of the cert stuff is tested elsewhere
35
29
  Puppet::Network::HttpPool.stubs(:cert_setup)
36
30
  end
37
31
 
38
32
  it "should return an http instance created with the passed host and port" do
39
- http = stub 'http', :use_ssl= => nil, :read_timeout= => nil, :open_timeout= => nil, :started? => false
40
- Net::HTTP.expects(:new).with("me", 54321, nil, nil).returns(http)
41
- Puppet::Network::HttpPool.http_instance("me", 54321).should equal(http)
33
+ http = Puppet::Network::HttpPool.http_instance("me", 54321)
34
+ http.should be_an_instance_of Net::HTTP
35
+ http.address.should == 'me'
36
+ http.port.should == 54321
42
37
  end
43
38
 
44
39
  it "should enable ssl on the http instance" do
45
- Puppet::Network::HttpPool.http_instance("me", 54321).instance_variable_get("@use_ssl").should be_true
40
+ Puppet::Network::HttpPool.http_instance("me", 54321).should be_use_ssl
46
41
  end
47
42
 
48
- it "should set the read timeout" do
49
- Puppet::Network::HttpPool.http_instance("me", 54321).read_timeout.should == 120
50
- end
51
-
52
- it "should set the open timeout" do
53
- Puppet::Network::HttpPool.http_instance("me", 54321).open_timeout.should == 120
43
+ context "proxy and timeout settings should propagate" do
44
+ subject { Puppet::Network::HttpPool.http_instance("me", 54321) }
45
+ before :each do
46
+ Puppet[:http_proxy_host] = "myhost"
47
+ Puppet[:http_proxy_port] = 432
48
+ Puppet[:configtimeout] = 120
49
+ end
54
50
  end
55
51
 
56
- it "should create the http instance with the proxy host and port set if the http_proxy is not set to 'none'" do
57
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
58
- Puppet::Network::HttpPool.http_instance("me", 54321).open_timeout.should == 120
52
+ it "should not set a proxy if the value is 'none'" do
53
+ Puppet[:http_proxy_host] = 'none'
54
+ Puppet::Network::HttpPool.http_instance("me", 54321).proxy_address.should be_nil
59
55
  end
60
56
 
61
57
  describe "and http keep-alive is enabled" do
@@ -64,19 +60,24 @@ describe Puppet::Network::HttpPool do
64
60
  end
65
61
 
66
62
  it "should cache http instances" do
67
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
68
63
  old = Puppet::Network::HttpPool.http_instance("me", 54321)
69
64
  Puppet::Network::HttpPool.http_instance("me", 54321).should equal(old)
70
65
  end
71
66
 
72
67
  it "should have a mechanism for getting a new http instance instead of the cached instance" do
73
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
68
+ Puppet[:http_proxy_host] = "myhost"
69
+ Puppet[:http_proxy_port] = 432
70
+ Puppet[:configtimeout] = 120
71
+
74
72
  old = Puppet::Network::HttpPool.http_instance("me", 54321)
75
73
  Puppet::Network::HttpPool.http_instance("me", 54321, true).should_not equal(old)
76
74
  end
77
75
 
78
76
  it "should close existing, open connections when requesting a new connection" do
79
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
77
+ Puppet[:http_proxy_host] = "myhost"
78
+ Puppet[:http_proxy_port] = 432
79
+ Puppet[:configtimeout] = 120
80
+
80
81
  old = Puppet::Network::HttpPool.http_instance("me", 54321)
81
82
  old.expects(:started?).returns(true)
82
83
  old.expects(:finish)
@@ -84,7 +85,9 @@ describe Puppet::Network::HttpPool do
84
85
  end
85
86
 
86
87
  it "should have a mechanism for clearing the http cache" do
87
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
88
+ Puppet[:http_proxy_host] = "myhost"
89
+ Puppet[:http_proxy_port] = 432
90
+ Puppet[:configtimeout] = 120
88
91
  old = Puppet::Network::HttpPool.http_instance("me", 54321)
89
92
  Puppet::Network::HttpPool.http_instance("me", 54321).should equal(old)
90
93
  old = Puppet::Network::HttpPool.http_instance("me", 54321)
@@ -93,7 +96,9 @@ describe Puppet::Network::HttpPool do
93
96
  end
94
97
 
95
98
  it "should close open http connections when clearing the cache" do
96
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
99
+ Puppet[:http_proxy_host] = "myhost"
100
+ Puppet[:http_proxy_port] = 432
101
+ Puppet[:configtimeout] = 120
97
102
  one = Puppet::Network::HttpPool.http_instance("me", 54321)
98
103
  one.expects(:started?).returns(true)
99
104
  one.expects(:finish).returns(true)
@@ -101,7 +106,9 @@ describe Puppet::Network::HttpPool do
101
106
  end
102
107
 
103
108
  it "should not close unopened http connections when clearing the cache" do
104
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
109
+ Puppet[:http_proxy_host] = "myhost"
110
+ Puppet[:http_proxy_port] = 432
111
+ Puppet[:configtimeout] = 120
105
112
  one = Puppet::Network::HttpPool.http_instance("me", 54321)
106
113
  one.expects(:started?).returns(false)
107
114
  one.expects(:finish).never
@@ -115,7 +122,9 @@ describe Puppet::Network::HttpPool do
115
122
  end
116
123
 
117
124
  it "should not cache http instances" do
118
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
125
+ Puppet[:http_proxy_host] = "myhost"
126
+ Puppet[:http_proxy_port] = 432
127
+ Puppet[:configtimeout] = 120
119
128
  old = Puppet::Network::HttpPool.http_instance("me", 54321)
120
129
  Puppet::Network::HttpPool.http_instance("me", 54321).should_not equal(old)
121
130
  end
@@ -126,81 +135,85 @@ describe Puppet::Network::HttpPool do
126
135
  end
127
136
  end
128
137
 
129
- describe "when adding certificate information to http instances" do
130
- before do
131
- @http = mock 'http'
132
- [:cert_store=, :verify_mode=, :ca_file=, :cert=, :key=].each { |m| @http.stubs(m) }
133
- @store = stub 'store'
134
-
135
- @cert = stub 'cert', :content => "real_cert"
136
- @key = stub 'key', :content => "real_key"
137
- @host = stub 'host', :certificate => @cert, :key => @key, :ssl_store => @store
138
-
139
- Puppet[:confdir] = "/sometthing/else"
140
- Puppet.settings.stubs(:value).returns "/some/file"
141
- Puppet.settings.stubs(:value).with(:hostcert).returns "/host/cert"
142
- Puppet.settings.stubs(:value).with(:localcacert).returns "/local/ca/cert"
143
-
144
- FileTest.stubs(:exist?).with("/host/cert").returns true
145
- FileTest.stubs(:exist?).with("/local/ca/cert").returns true
146
-
147
- Puppet::Network::HttpPool.stubs(:ssl_host).returns @host
148
- end
149
-
150
- after do
151
- Puppet.settings.clear
138
+ describe "when doing SSL setup for http instances" do
139
+ let :http do
140
+ http = Net::HTTP.new('localhost', 443)
141
+ http.use_ssl = true
142
+ http
152
143
  end
153
144
 
154
- it "should do nothing if no host certificate is on disk" do
155
- FileTest.expects(:exist?).with("/host/cert").returns false
156
- @http.expects(:cert=).never
157
- Puppet::Network::HttpPool.cert_setup(@http)
158
- end
145
+ let :store do stub('store') end
159
146
 
160
- it "should do nothing if no local certificate is on disk" do
161
- FileTest.expects(:exist?).with("/local/ca/cert").returns false
162
- @http.expects(:cert=).never
163
- Puppet::Network::HttpPool.cert_setup(@http)
147
+ before :each do
148
+ Puppet[:hostcert] = '/host/cert'
149
+ Puppet[:localcacert] = '/local/ca/cert'
150
+ cert = stub 'cert', :content => 'real_cert'
151
+ key = stub 'key', :content => 'real_key'
152
+ host = stub 'host', :certificate => cert, :key => key, :ssl_store => store
153
+ Puppet::Network::HttpPool.stubs(:ssl_host).returns(host)
164
154
  end
165
155
 
166
- it "should add a certificate store from the ssl host" do
167
- @http.expects(:cert_store=).with(@store)
156
+ shared_examples "HTTPS setup without all certificates" do
157
+ subject { Puppet::Network::HttpPool.cert_setup(http); http }
168
158
 
169
- Puppet::Network::HttpPool.cert_setup(@http)
159
+ it { should be_use_ssl }
160
+ its(:cert) { should be_nil }
161
+ its(:ca_file) { should be_nil }
162
+ its(:key) { should be_nil }
163
+ its(:verify_mode) { should == OpenSSL::SSL::VERIFY_NONE }
170
164
  end
171
165
 
172
- it "should add the client certificate" do
173
- @http.expects(:cert=).with("real_cert")
166
+ context "with neither a host cert or a local CA cert" do
167
+ before :each do
168
+ FileTest.stubs(:exist?).with(Puppet[:hostcert]).returns(false)
169
+ FileTest.stubs(:exist?).with(Puppet[:localcacert]).returns(false)
170
+ end
174
171
 
175
- Puppet::Network::HttpPool.cert_setup(@http)
172
+ include_examples "HTTPS setup without all certificates"
176
173
  end
177
174
 
178
- it "should add the client key" do
179
- @http.expects(:key=).with("real_key")
175
+ context "with there is no host certificate" do
176
+ before :each do
177
+ FileTest.stubs(:exist?).with(Puppet[:hostcert]).returns(false)
178
+ FileTest.stubs(:exist?).with(Puppet[:localcacert]).returns(true)
179
+ end
180
180
 
181
- Puppet::Network::HttpPool.cert_setup(@http)
181
+ include_examples "HTTPS setup without all certificates"
182
182
  end
183
183
 
184
- it "should set the verify mode to OpenSSL::SSL::VERIFY_PEER" do
185
- @http.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
184
+ context "with there is no local CA certificate" do
185
+ before :each do
186
+ FileTest.stubs(:exist?).with(Puppet[:hostcert]).returns(true)
187
+ FileTest.stubs(:exist?).with(Puppet[:localcacert]).returns(false)
188
+ end
186
189
 
187
- Puppet::Network::HttpPool.cert_setup(@http)
190
+ include_examples "HTTPS setup without all certificates"
188
191
  end
189
192
 
190
- it "should set the ca file" do
191
- Puppet.settings.stubs(:value).returns "/some/file"
192
- FileTest.stubs(:exist?).with(Puppet[:hostcert]).returns true
193
+ context "with both the host and CA cert" do
194
+ subject { Puppet::Network::HttpPool.cert_setup(http); http }
193
195
 
194
- Puppet.settings.stubs(:value).with(:localcacert).returns "/ca/cert/file"
195
- FileTest.stubs(:exist?).with("/ca/cert/file").returns true
196
- @http.expects(:ca_file=).with("/ca/cert/file")
196
+ before :each do
197
+ FileTest.expects(:exist?).with(Puppet[:hostcert]).returns(true)
198
+ FileTest.expects(:exist?).with(Puppet[:localcacert]).returns(true)
199
+ end
197
200
 
198
- Puppet::Network::HttpPool.cert_setup(@http)
201
+ it { should be_use_ssl }
202
+ its(:cert_store) { should equal store }
203
+ its(:cert) { should == "real_cert" }
204
+ its(:key) { should == "real_key" }
205
+ its(:verify_mode) { should == OpenSSL::SSL::VERIFY_PEER }
206
+ its(:ca_file) { should == Puppet[:localcacert] }
199
207
  end
200
208
 
201
209
  it "should set up certificate information when creating http instances" do
202
- Puppet::Network::HttpPool.expects(:cert_setup).with { |i| i.is_a?(Net::HTTP) }
203
- Puppet::Network::HttpPool.http_instance("one", "two")
210
+ Puppet::Network::HttpPool.expects(:cert_setup).with do |http|
211
+ http.should be_an_instance_of Net::HTTP
212
+ http.address.should == "one"
213
+ http.port.should == 2
214
+ end
215
+
216
+ Puppet::Network::HttpPool.http_instance("one", 2)
204
217
  end
205
218
  end
206
219
  end
@@ -12,7 +12,7 @@ describe Puppet::Network::RestAuthConfig do
12
12
  # to fileserver.conf
13
13
  { :acl => "/file" },
14
14
  { :acl => "/certificate_revocation_list/ca", :method => :find, :authenticated => true },
15
- { :acl => "/report", :method => :save, :authenticated => true },
15
+ { :acl => "~ ^\/report\/([^\/]+)$", :method => :save, :allow => '$1', :authenticated => true },
16
16
  { :acl => "/certificate/ca", :method => :find, :authenticated => false },
17
17
  { :acl => "/certificate/", :method => :find, :authenticated => false },
18
18
  { :acl => "/certificate_request", :method => [:find, :save], :authenticated => false },
@@ -104,7 +104,22 @@ describe Puppet::Network::RestAuthConfig do
104
104
  end
105
105
  end
106
106
 
107
+ it '(CVE-2013-2275) allows report submission only for the node matching the certname by default' do
108
+ acl = {
109
+ :acl => "~ ^\/report\/([^\/]+)$",
110
+ :method => :save,
111
+ :allow => '$1',
112
+ :authenticated => true
113
+ }
114
+ @authconfig.stubs(:mk_acl)
115
+ @authconfig.expects(:mk_acl).with(acl)
116
+ @authconfig.insert_default_acl
117
+ end
118
+
107
119
  it "should create default ACL entries if no file have been read" do
120
+ # The singleton instance is stored as an instance variable we don't have
121
+ # access to, so.. instance_variable_set. Alas.
122
+ Puppet::Network::RestAuthConfig.instance_variable_set(:@main, nil)
108
123
  Puppet::Network::RestAuthConfig.any_instance.stubs(:exists?).returns(false)
109
124
 
110
125
  Puppet::Network::RestAuthConfig.any_instance.expects(:insert_default_acl)
@@ -141,7 +156,5 @@ describe Puppet::Network::RestAuthConfig do
141
156
 
142
157
  @authconfig.insert_default_acl
143
158
  end
144
-
145
159
  end
146
-
147
160
  end
@@ -56,4 +56,17 @@ describe "the inline_template function" do
56
56
  lambda { @scope.function_inline_template("1") }.should raise_error(Puppet::ParseError)
57
57
  end
58
58
 
59
- end
59
+ it "is not interfered with by a variable called 'string' (#14093)" do
60
+ @scope.setvar("string", "this is a variable")
61
+ inline_template("this is a template").should == "this is a template"
62
+ end
63
+
64
+ it "has access to a variable called 'string' (#14093)" do
65
+ @scope.setvar('string', "this is a variable")
66
+ inline_template("string was: <%= @string %>").should == "string was: this is a variable"
67
+ end
68
+
69
+ def inline_template(*templates)
70
+ @scope.function_inline_template(templates)
71
+ end
72
+ end
@@ -51,6 +51,16 @@ describe "the template function" do
51
51
  @scope.function_template(["1","2"]).should == "result1result2"
52
52
  end
53
53
 
54
+ it "is not interfered with by having a variable named 'string' (#14093)" do
55
+ @scope.setvar('string', "this output should not be seen")
56
+ eval_template("some text that is static").should == "some text that is static"
57
+ end
58
+
59
+ it "has access to a variable named 'string' (#14093)" do
60
+ @scope.setvar('string', "the string value")
61
+ eval_template("string was: <%= @string %>").should == "string was: the string value"
62
+ end
63
+
54
64
  it "should raise an error if the template raises an error" do
55
65
  tw = stub_everything 'template_wrapper'
56
66
  Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
@@ -59,4 +69,11 @@ describe "the template function" do
59
69
  lambda { @scope.function_template("1") }.should raise_error(Puppet::ParseError)
60
70
  end
61
71
 
62
- end
72
+ def eval_template(content)
73
+ File.stubs(:read).with("template").returns(content)
74
+ Puppet::Parser::Files.stubs(:find_template).returns("template")
75
+ env = Puppet::Node::Environment.new('production')
76
+ @scope.compiler = stub('compiler', :environment => env)
77
+ @scope.function_template(['template'])
78
+ end
79
+ end
@@ -25,16 +25,14 @@ describe Puppet::Parser::TemplateWrapper do
25
25
 
26
26
  it "should check template file existance and read its content" do
27
27
  Puppet::Parser::Files.expects(:find_template).with("fake_template", @scope.environment.to_s).returns("/tmp/fake_template")
28
- File.expects(:read).with("/tmp/fake_template").returns("template content")
29
28
 
30
29
  @tw.file = @file
31
30
  end
32
31
 
33
32
  it "should mark the file for watching" do
34
- Puppet::Parser::Files.expects(:find_template).returns("/tmp/fake_template")
35
- File.stubs(:read)
33
+ full_file_name = given_a_template_file("fake_template", "content")
36
34
 
37
- @known_resource_types.expects(:watch_file).with("/tmp/fake_template")
35
+ @known_resource_types.expects(:watch_file).with(full_file_name)
38
36
  @tw.file = @file
39
37
  end
40
38
 
@@ -54,7 +52,7 @@ describe Puppet::Parser::TemplateWrapper do
54
52
  end
55
53
 
56
54
  it "should return the processed template contents with a call to result" do
57
- template_mock = mock("template", :result => "woot!")
55
+ template_mock = mock("template", :result => "woot!", :filename= => nil)
58
56
  File.expects(:read).with("/tmp/fake_template").returns("template contents")
59
57
  ERB.expects(:new).with("template contents", 0, "-").returns(template_mock)
60
58
 
@@ -62,8 +60,15 @@ describe Puppet::Parser::TemplateWrapper do
62
60
  @tw.result.should eql("woot!")
63
61
  end
64
62
 
63
+ it "provides access to the name of the template via #file" do
64
+ full_file_name = given_a_template_file("fake_template", "<%= file %>")
65
+
66
+ @tw.file = "fake_template"
67
+ @tw.result.should == full_file_name
68
+ end
69
+
65
70
  it "should return the processed template contents with a call to result and a string" do
66
- template_mock = mock("template", :result => "woot!")
71
+ template_mock = mock("template", :result => "woot!", :filename= => nil)
67
72
  ERB.expects(:new).with("template contents", 0, "-").returns(template_mock)
68
73
 
69
74
  @tw.result("template contents").should eql("woot!")
@@ -114,7 +119,7 @@ describe Puppet::Parser::TemplateWrapper do
114
119
  end
115
120
 
116
121
  it "should set all of the scope's variables as instance variables" do
117
- template_mock = mock("template", :result => "woot!")
122
+ template_mock = mock("template", :result => "woot!", :filename= => nil)
118
123
  ERB.expects(:new).with("template contents", 0, "-").returns(template_mock)
119
124
 
120
125
  @scope.expects(:to_hash).returns("one" => "foo")
@@ -124,7 +129,7 @@ describe Puppet::Parser::TemplateWrapper do
124
129
  end
125
130
 
126
131
  it "should not error out if one of the variables is a symbol" do
127
- template_mock = mock("template", :result => "woot!")
132
+ template_mock = mock("template", :result => "woot!", :filename= => nil)
128
133
  ERB.expects(:new).with("template contents", 0, "-").returns(template_mock)
129
134
 
130
135
  @scope.expects(:to_hash).returns(:_timestamp => "1234")
@@ -133,7 +138,7 @@ describe Puppet::Parser::TemplateWrapper do
133
138
 
134
139
  %w{! . ; :}.each do |badchar|
135
140
  it "should translate #{badchar} to _ when setting the instance variables" do
136
- template_mock = mock("template", :result => "woot!")
141
+ template_mock = mock("template", :result => "woot!", :filename= => nil)
137
142
  ERB.expects(:new).with("template contents", 0, "-").returns(template_mock)
138
143
 
139
144
  @scope.expects(:to_hash).returns("one#{badchar}" => "foo")
@@ -142,4 +147,14 @@ describe Puppet::Parser::TemplateWrapper do
142
147
  @tw.instance_variable_get("@one_").should == "foo"
143
148
  end
144
149
  end
150
+
151
+ def given_a_template_file(name, contents)
152
+ full_name = "/full/path/to/#{name}"
153
+ Puppet::Parser::Files.stubs(:find_template).
154
+ with(name, anything()).
155
+ returns(full_name)
156
+ File.stubs(:read).with(full_name).returns(contents)
157
+
158
+ full_name
159
+ end
145
160
  end