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.
- data/CHANGELOG +25 -0
- data/conf/auth.conf +3 -3
- data/conf/redhat/puppet.spec +5 -2
- data/lib/puppet.rb +1 -1
- data/lib/puppet/indirector/catalog/compiler.rb +13 -2
- data/lib/puppet/indirector/errors.rb +5 -0
- data/lib/puppet/indirector/file_bucket_file/file.rb +4 -0
- data/lib/puppet/indirector/file_bucket_file/selector.rb +4 -0
- data/lib/puppet/indirector/indirection.rb +1 -0
- data/lib/puppet/indirector/request.rb +4 -0
- data/lib/puppet/indirector/resource/ral.rb +4 -0
- data/lib/puppet/indirector/resource/validator.rb +8 -0
- data/lib/puppet/indirector/rest.rb +4 -0
- data/lib/puppet/indirector/run/local.rb +4 -0
- data/lib/puppet/indirector/terminus.rb +20 -0
- data/lib/puppet/network/http/handler.rb +9 -0
- data/lib/puppet/network/http/rack/rest.rb +7 -2
- data/lib/puppet/network/http/webrick.rb +1 -0
- data/lib/puppet/network/http_pool.rb +17 -8
- data/lib/puppet/network/rest_authconfig.rb +1 -1
- data/lib/puppet/parser/templatewrapper.rb +13 -12
- data/lib/puppet/util/monkey_patches.rb +43 -0
- data/spec/integration/indirector/bucket_file/rest_spec.rb +1 -1
- data/spec/integration/indirector/catalog/compiler_spec.rb +1 -0
- data/spec/integration/indirector/catalog/queue_spec.rb +1 -1
- data/spec/integration/indirector/certificate_request/rest_spec.rb +1 -1
- data/spec/integration/indirector/report/rest_spec.rb +1 -1
- data/spec/integration/resource/catalog_spec.rb +1 -0
- data/spec/unit/indirector/catalog/compiler_spec.rb +30 -3
- data/spec/unit/indirector/indirection_spec.rb +18 -1
- data/spec/unit/indirector/request_spec.rb +22 -0
- data/spec/unit/indirector/terminus_spec.rb +186 -174
- data/spec/unit/network/http/handler_spec.rb +1 -0
- data/spec/unit/network/http/rack/rest_spec.rb +17 -0
- data/spec/unit/network/http/webrick_spec.rb +4 -0
- data/spec/unit/network/http_pool_spec.rb +93 -80
- data/spec/unit/network/rest_authconfig_spec.rb +16 -3
- data/spec/unit/parser/functions/inline_template_spec.rb +14 -1
- data/spec/unit/parser/functions/template_spec.rb +18 -1
- data/spec/unit/parser/templatewrapper_spec.rb +24 -9
- data/spec/unit/util/monkey_patches_spec.rb +11 -1
- data/test/language/snippets.rb +1 -1
- 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
|
-
|
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 =
|
40
|
-
Net::HTTP
|
41
|
-
|
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).
|
40
|
+
Puppet::Network::HttpPool.http_instance("me", 54321).should be_use_ssl
|
46
41
|
end
|
47
42
|
|
48
|
-
|
49
|
-
Puppet::Network::HttpPool.http_instance("me", 54321)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
57
|
-
|
58
|
-
Puppet::Network::HttpPool.http_instance("me", 54321).
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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
|
-
|
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
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
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
|
-
|
167
|
-
|
156
|
+
shared_examples "HTTPS setup without all certificates" do
|
157
|
+
subject { Puppet::Network::HttpPool.cert_setup(http); http }
|
168
158
|
|
169
|
-
|
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
|
-
|
173
|
-
|
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
|
-
|
172
|
+
include_examples "HTTPS setup without all certificates"
|
176
173
|
end
|
177
174
|
|
178
|
-
|
179
|
-
|
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
|
-
|
181
|
+
include_examples "HTTPS setup without all certificates"
|
182
182
|
end
|
183
183
|
|
184
|
-
|
185
|
-
|
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
|
-
|
190
|
+
include_examples "HTTPS setup without all certificates"
|
188
191
|
end
|
189
192
|
|
190
|
-
|
191
|
-
Puppet.
|
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
|
-
|
195
|
-
|
196
|
-
|
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
|
-
|
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
|
203
|
-
|
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 => "
|
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
|
-
|
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
|
-
|
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
|
-
|
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(
|
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
|