puppet 2.6.16 → 2.6.17
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 +13 -0
- data/conf/redhat/puppet.spec +4 -1
- data/lib/puppet.rb +1 -1
- data/lib/puppet/application/master.rb +26 -6
- data/lib/puppet/file_bucket/file.rb +5 -6
- data/lib/puppet/file_serving/configuration.rb +2 -1
- data/lib/puppet/file_serving/content.rb +1 -2
- data/lib/puppet/file_serving/metadata.rb +1 -2
- data/lib/puppet/file_serving/mount/modules.rb +4 -5
- data/lib/puppet/file_serving/{indirection_hooks.rb → terminus_selector.rb} +2 -3
- data/lib/puppet/indirector/file_bucket_file/selector.rb +49 -0
- data/lib/puppet/indirector/file_content/selector.rb +30 -0
- data/lib/puppet/indirector/file_metadata/selector.rb +30 -0
- data/lib/puppet/reports/store.rb +7 -3
- data/lib/puppet/ssl/base.rb +8 -0
- data/lib/puppet/ssl/certificate_authority.rb +10 -0
- data/lib/puppet/ssl/certificate_authority/interface.rb +4 -2
- data/lib/puppet/ssl/host.rb +1 -0
- data/spec/integration/file_bucket/file_spec.rb +44 -0
- data/spec/integration/file_serving/content_spec.rb +1 -8
- data/spec/integration/file_serving/metadata_spec.rb +1 -8
- data/spec/integration/indirector/file_content/file_server_spec.rb +2 -2
- data/spec/shared_behaviours/file_serving.rb +71 -62
- data/spec/shared_behaviours/file_serving_model.rb +73 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/unit/file_serving/configuration_spec.rb +37 -29
- data/spec/unit/file_serving/content_spec.rb +0 -4
- data/spec/unit/file_serving/metadata_spec.rb +0 -4
- data/spec/unit/file_serving/mount/modules_spec.rb +8 -0
- data/spec/unit/file_serving/{indirection_hooks_spec.rb → terminus_selector_spec.rb} +11 -12
- data/spec/unit/indirector/file_bucket_file/selector_spec.rb +29 -0
- data/spec/unit/indirector/file_content/selector_spec.rb +10 -0
- data/spec/unit/indirector/file_metadata/selector_spec.rb +11 -0
- data/spec/unit/network/handler/ca_spec.rb +1 -0
- data/spec/unit/reports/store_spec.rb +14 -0
- data/spec/unit/ssl/certificate_authority/interface_spec.rb +17 -17
- data/spec/unit/ssl/certificate_authority_spec.rb +76 -11
- metadata +16 -9
- data/lib/puppet/file_bucket/file/indirection_hooks.rb +0 -9
@@ -9,12 +9,5 @@ require 'puppet/file_serving/content'
|
|
9
9
|
require 'shared_behaviours/file_serving'
|
10
10
|
|
11
11
|
describe Puppet::FileServing::Content, " when finding files" do
|
12
|
-
it_should_behave_like "
|
13
|
-
|
14
|
-
before do
|
15
|
-
@test_class = Puppet::FileServing::Content
|
16
|
-
@indirection = Puppet::FileServing::Content.indirection
|
17
|
-
end
|
18
|
-
|
19
|
-
after { Puppet::Util::Cacher.expire }
|
12
|
+
it_should_behave_like "a file_serving model"
|
20
13
|
end
|
@@ -10,12 +10,5 @@ require 'shared_behaviours/file_serving'
|
|
10
10
|
require 'puppet/indirector/file_metadata/file_server'
|
11
11
|
|
12
12
|
describe Puppet::FileServing::Metadata, " when finding files" do
|
13
|
-
it_should_behave_like "
|
14
|
-
|
15
|
-
before do
|
16
|
-
@test_class = Puppet::FileServing::Metadata
|
17
|
-
@indirection = Puppet::FileServing::Metadata.indirection
|
18
|
-
end
|
19
|
-
|
20
|
-
after { Puppet::Util::Cacher.expire }
|
13
|
+
it_should_behave_like "a file_serving model"
|
21
14
|
end
|
@@ -38,8 +38,8 @@ describe Puppet::Indirector::FileContent::FileServer, " when finding files" do
|
|
38
38
|
|
39
39
|
result.should_not be_nil
|
40
40
|
result.length.should == 2
|
41
|
-
result
|
42
|
-
result
|
41
|
+
result.map {|x| x.should be_instance_of(Puppet::FileServing::Content) }
|
42
|
+
result.find {|x| x.relative_path == 'file.rb' }.content.should == "1\n"
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should find file content in modules" do
|
@@ -1,71 +1,80 @@
|
|
1
|
-
#!/usr/bin/env
|
2
|
-
#
|
3
|
-
# Created by Luke Kanies on 2007-10-18.
|
4
|
-
# Copyright (c) 2007. All rights reserved.
|
5
|
-
|
6
|
-
shared_examples_for "Puppet::FileServing::Files" do
|
7
|
-
it "should use the rest terminus when the 'puppet' URI scheme is used and a host name is present" do
|
8
|
-
uri = "puppet://myhost/fakemod/my/file"
|
9
|
-
|
10
|
-
# It appears that the mocking somehow interferes with the caching subsystem.
|
11
|
-
# This mock somehow causes another terminus to get generated.
|
12
|
-
term = @indirection.terminus(:rest)
|
13
|
-
@indirection.stubs(:terminus).with(:rest).returns term
|
14
|
-
term.expects(:find)
|
15
|
-
@test_class.find(uri)
|
16
|
-
end
|
1
|
+
#!/usr/bin/env rspec
|
17
2
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
Puppet.settings.stubs(:value).with(:name).returns("puppetd")
|
22
|
-
Puppet.settings.stubs(:value).with(:modulepath).returns("")
|
23
|
-
@indirection.terminus(:rest).expects(:find)
|
24
|
-
@test_class.find(uri)
|
25
|
-
end
|
3
|
+
shared_examples_for "Puppet::FileServing::Files" do |indirection|
|
4
|
+
%w[find search].each do |method|
|
5
|
+
let(:request) { Puppet::Indirector::Request.new(indirection, method, 'foo') }
|
26
6
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
Puppet.settings.stubs(:value).with(:name).returns("puppet")
|
32
|
-
Puppet.settings.stubs(:value).with(:fileserverconfig).returns("/whatever")
|
33
|
-
@indirection.terminus(:file_server).expects(:find)
|
34
|
-
@indirection.terminus(:file_server).stubs(:authorized?).returns(true)
|
35
|
-
@test_class.find(uri)
|
36
|
-
end
|
7
|
+
before :each do
|
8
|
+
# Stub this so we can set the :name setting
|
9
|
+
Puppet::Util::Settings::ReadOnly.stubs(:include?)
|
10
|
+
end
|
37
11
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
Puppet.settings.stubs(:value).returns ""
|
42
|
-
Puppet.settings.stubs(:value).with(:name).returns("apply")
|
43
|
-
Puppet.settings.stubs(:value).with(:fileserverconfig).returns("/whatever")
|
44
|
-
@indirection.terminus(:file_server).expects(:find)
|
45
|
-
@indirection.terminus(:file_server).stubs(:authorized?).returns(true)
|
46
|
-
@test_class.find(uri)
|
47
|
-
end
|
12
|
+
describe "##{method}" do
|
13
|
+
it "should proxy to file terminus if the path is absolute" do
|
14
|
+
request.key = '/tmp/foo'
|
48
15
|
|
49
|
-
|
50
|
-
uri = "file:///fakemod/my/file"
|
51
|
-
@indirection.terminus(:file).expects(:find)
|
52
|
-
@test_class.find(uri)
|
53
|
-
end
|
16
|
+
described_class.indirection.terminus(:file).class.any_instance.expects(method).with(request)
|
54
17
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
18
|
+
subject.send(method, request)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should proxy to file terminus if the protocol is file" do
|
22
|
+
request.protocol = 'file'
|
23
|
+
|
24
|
+
described_class.indirection.terminus(:file).class.any_instance.expects(method).with(request)
|
25
|
+
|
26
|
+
subject.send(method, request)
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "when the protocol is puppet" do
|
30
|
+
before :each do
|
31
|
+
request.protocol = 'puppet'
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "and a server is specified" do
|
35
|
+
before :each do
|
36
|
+
request.server = 'puppet_server'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should proxy to rest terminus if we're 'apply'" do
|
40
|
+
Puppet[:name] = 'apply'
|
41
|
+
|
42
|
+
described_class.indirection.terminus(:rest).class.any_instance.expects(method).with(request)
|
43
|
+
|
44
|
+
subject.send(method, request)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should proxy to rest terminus if we aren't 'apply'" do
|
48
|
+
Puppet[:name] = 'not_apply'
|
49
|
+
|
50
|
+
described_class.indirection.terminus(:rest).class.any_instance.expects(method).with(request)
|
51
|
+
|
52
|
+
subject.send(method, request)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "and no server is specified" do
|
57
|
+
before :each do
|
58
|
+
request.server = nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should proxy to file_server if we're 'apply'" do
|
62
|
+
Puppet[:name] = 'apply'
|
63
|
+
|
64
|
+
described_class.indirection.terminus(:file_server).class.any_instance.expects(method).with(request)
|
65
|
+
|
66
|
+
subject.send(method, request)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should proxy to rest if we're not 'apply'" do
|
70
|
+
Puppet[:name] = 'not_apply'
|
60
71
|
|
61
|
-
|
62
|
-
uri = "fakemod/my/file"
|
63
|
-
mount = mock 'mount'
|
64
|
-
config = stub 'configuration', :split_path => [mount, "eh"]
|
65
|
-
@indirection.terminus(:file_server).stubs(:configuration).returns config
|
72
|
+
described_class.indirection.terminus(:rest).class.any_instance.expects(method).with(request)
|
66
73
|
|
67
|
-
|
68
|
-
|
69
|
-
|
74
|
+
subject.send(method, request)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
70
79
|
end
|
71
80
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
shared_examples_for "a file_serving model" do
|
4
|
+
include PuppetSpec::Files
|
5
|
+
|
6
|
+
describe "#indirection" do
|
7
|
+
before :each do
|
8
|
+
# Never connect to the network, no matter what
|
9
|
+
described_class.indirection.terminus(:rest).class.any_instance.stubs(:find)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "when running the master application" do
|
13
|
+
before :each do
|
14
|
+
Puppet::Application[:master].setup_terminuses
|
15
|
+
end
|
16
|
+
|
17
|
+
{
|
18
|
+
"/etc/sudoers" => :file_server,
|
19
|
+
"file:///etc/sudoers" => :file_server,
|
20
|
+
"puppet:///modules/foo/bar" => :file_server,
|
21
|
+
"puppet://server/modules/foo/bar" => :file_server,
|
22
|
+
}.each do |key, terminus|
|
23
|
+
it "should use the #{terminus} terminus when requesting #{key.inspect}" do
|
24
|
+
described_class.indirection.terminus(terminus).class.any_instance.expects(:find)
|
25
|
+
|
26
|
+
described_class.indirection.find(key)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "when running the apply application" do
|
32
|
+
before :each do
|
33
|
+
# Stub this so we can set the 'name' setting
|
34
|
+
Puppet::Util::Settings::ReadOnly.stubs(:include?)
|
35
|
+
Puppet[:name] = 'apply'
|
36
|
+
end
|
37
|
+
|
38
|
+
{
|
39
|
+
"/etc/sudoers" => :file,
|
40
|
+
"file:///etc/sudoers" => :file,
|
41
|
+
"puppet:///modules/foo/bar" => :file_server,
|
42
|
+
"puppet://server/modules/foo/bar" => :rest,
|
43
|
+
}.each do |key, terminus|
|
44
|
+
it "should use the #{terminus} terminus when requesting #{key.inspect}" do
|
45
|
+
described_class.indirection.terminus(terminus).class.any_instance.expects(:find)
|
46
|
+
|
47
|
+
described_class.indirection.find(key)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "when running another application" do
|
53
|
+
before :each do
|
54
|
+
# Stub this so we can set the 'name' setting
|
55
|
+
Puppet::Util::Settings::ReadOnly.stubs(:include?)
|
56
|
+
Puppet[:name] = 'agent'
|
57
|
+
end
|
58
|
+
|
59
|
+
{
|
60
|
+
"/etc/sudoers" => :file,
|
61
|
+
"file:///etc/sudoers" => :file,
|
62
|
+
"puppet:///modules/foo/bar" => :rest,
|
63
|
+
"puppet://server/modules/foo/bar" => :rest,
|
64
|
+
}.each do |key, terminus|
|
65
|
+
it "should use the #{terminus} terminus when requesting #{key.inspect}" do
|
66
|
+
described_class.indirection.terminus(terminus).class.any_instance.expects(:find)
|
67
|
+
|
68
|
+
described_class.indirection.find(key)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -63,8 +63,26 @@ RSpec.configure do |config|
|
|
63
63
|
$tmpfiles.clear
|
64
64
|
end
|
65
65
|
|
66
|
+
|
67
|
+
# Some tests can cause us to connect, in which case the lingering
|
68
|
+
# connection is a resource that can cause unexpected failure in later
|
69
|
+
# tests, as well as sharing state accidentally.
|
70
|
+
# We're testing if ActiveRecord::Base is defined because some test cases
|
71
|
+
# may stub Puppet.features.rails? which is how we should normally
|
72
|
+
# introspect for this functionality.
|
73
|
+
ActiveRecord::Base.remove_connection if defined?(ActiveRecord::Base)
|
74
|
+
|
66
75
|
@logs.clear
|
67
76
|
Puppet::Util::Log.close_all
|
77
|
+
|
78
|
+
# Restore the terminuses to the defaults in case they were changed
|
79
|
+
indirections = Puppet::Indirector::Indirection.send(:class_variable_get, :@@indirections)
|
80
|
+
indirections.each do |indirector|
|
81
|
+
$saved_indirection_state.fetch(indirector.name, {}).each do |variable, value|
|
82
|
+
indirector.instance_variable_set(variable, value)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
$saved_indirection_state = nil
|
68
86
|
end
|
69
87
|
|
70
88
|
config.before :each do
|
@@ -73,6 +91,17 @@ RSpec.configure do |config|
|
|
73
91
|
$puppet_application_name = nil
|
74
92
|
Signal.stubs(:trap)
|
75
93
|
|
94
|
+
# Save off the current terminuses so we can restore them afterward
|
95
|
+
$saved_indirection_state = {}
|
96
|
+
indirections = Puppet::Indirector::Indirection.send(:class_variable_get, :@@indirections)
|
97
|
+
indirections.each do |indirector|
|
98
|
+
$saved_indirection_state[indirector.name] = {
|
99
|
+
:@terminus_class => indirector.instance_variable_get(:@terminus_class),
|
100
|
+
:@cache_class => indirector.instance_variable_get(:@cache_class)
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
|
76
105
|
# Set the confdir and vardir to gibberish so that tests
|
77
106
|
# have to be correctly mocked.
|
78
107
|
Puppet[:confdir] = "/dev/null"
|
@@ -170,80 +170,88 @@ describe Puppet::FileServing::Configuration do
|
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
|
-
describe "
|
174
|
-
|
175
|
-
|
176
|
-
@config.stubs(:find_mount)
|
173
|
+
describe "#split_path" do
|
174
|
+
let(:config) { Puppet::FileServing::Configuration.create }
|
175
|
+
let(:request) { stub 'request', :key => "foo/bar/baz", :options => {}, :node => nil, :environment => mock("env") }
|
177
176
|
|
178
|
-
|
177
|
+
before do
|
178
|
+
config.stubs(:find_mount)
|
179
179
|
end
|
180
180
|
|
181
181
|
it "should reread the configuration" do
|
182
|
-
|
182
|
+
config.expects(:readconfig)
|
183
183
|
|
184
|
-
|
184
|
+
config.split_path(request)
|
185
185
|
end
|
186
186
|
|
187
187
|
it "should treat the first field of the URI path as the mount name" do
|
188
|
-
|
188
|
+
config.expects(:find_mount).with { |name, node| name == "foo" }
|
189
189
|
|
190
|
-
|
190
|
+
config.split_path(request)
|
191
191
|
end
|
192
192
|
|
193
193
|
it "should fail if the mount name is not alpha-numeric" do
|
194
|
-
|
194
|
+
request.expects(:key).returns "foo&bar/asdf"
|
195
195
|
|
196
|
-
lambda {
|
196
|
+
lambda { config.split_path(request) }.should raise_error(ArgumentError)
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should support dashes in the mount name" do
|
200
|
-
|
200
|
+
request.expects(:key).returns "foo-bar/asdf"
|
201
201
|
|
202
|
-
lambda {
|
202
|
+
lambda { config.split_path(request) }.should_not raise_error(ArgumentError)
|
203
203
|
end
|
204
204
|
|
205
205
|
it "should use the mount name and environment to find the mount" do
|
206
|
-
|
207
|
-
|
206
|
+
config.expects(:find_mount).with { |name, env| name == "foo" and env == request.environment }
|
207
|
+
request.stubs(:node).returns("mynode")
|
208
208
|
|
209
|
-
|
209
|
+
config.split_path(request)
|
210
210
|
end
|
211
211
|
|
212
212
|
it "should return nil if the mount cannot be found" do
|
213
|
-
|
213
|
+
config.expects(:find_mount).returns nil
|
214
214
|
|
215
|
-
|
215
|
+
config.split_path(request).should be_nil
|
216
216
|
end
|
217
217
|
|
218
218
|
it "should return the mount and the relative path if the mount is found" do
|
219
219
|
mount = stub 'mount', :name => "foo"
|
220
|
-
|
220
|
+
config.expects(:find_mount).returns mount
|
221
221
|
|
222
|
-
|
222
|
+
config.split_path(request).should == [mount, "bar/baz"]
|
223
223
|
end
|
224
224
|
|
225
225
|
it "should remove any double slashes" do
|
226
|
-
|
226
|
+
request.stubs(:key).returns "foo/bar//baz"
|
227
227
|
mount = stub 'mount', :name => "foo"
|
228
|
-
|
228
|
+
config.expects(:find_mount).returns mount
|
229
|
+
|
230
|
+
config.split_path(request).should == [mount, "bar/baz"]
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should fail if the path contains .." do
|
234
|
+
request.stubs(:key).returns 'module/foo/../../bar'
|
229
235
|
|
230
|
-
|
236
|
+
expect do
|
237
|
+
config.split_path(request)
|
238
|
+
end.to raise_error(ArgumentError, /Invalid relative path/)
|
231
239
|
end
|
232
240
|
|
233
241
|
it "should return the relative path as nil if it is an empty string" do
|
234
|
-
|
242
|
+
request.expects(:key).returns "foo"
|
235
243
|
mount = stub 'mount', :name => "foo"
|
236
|
-
|
244
|
+
config.expects(:find_mount).returns mount
|
237
245
|
|
238
|
-
|
246
|
+
config.split_path(request).should == [mount, nil]
|
239
247
|
end
|
240
248
|
|
241
249
|
it "should add 'modules/' to the relative path if the modules mount is used but not specified, for backward compatibility" do
|
242
|
-
|
250
|
+
request.expects(:key).returns "foo/bar"
|
243
251
|
mount = stub 'mount', :name => "modules"
|
244
|
-
|
252
|
+
config.expects(:find_mount).returns mount
|
245
253
|
|
246
|
-
|
254
|
+
config.split_path(request).should == [mount, "foo/bar"]
|
247
255
|
end
|
248
256
|
end
|
249
257
|
end
|
@@ -13,10 +13,6 @@ describe Puppet::FileServing::Content do
|
|
13
13
|
Puppet::FileServing::Content.indirection.name.should == :file_content
|
14
14
|
end
|
15
15
|
|
16
|
-
it "should should include the IndirectionHooks module in its indirection" do
|
17
|
-
Puppet::FileServing::Content.indirection.singleton_class.included_modules.should include(Puppet::FileServing::IndirectionHooks)
|
18
|
-
end
|
19
|
-
|
20
16
|
it "should only support the raw format" do
|
21
17
|
Puppet::FileServing::Content.supported_formats.should == [:raw]
|
22
18
|
end
|
@@ -13,10 +13,6 @@ describe Puppet::FileServing::Metadata do
|
|
13
13
|
Puppet::FileServing::Metadata.indirection.name.should == :file_metadata
|
14
14
|
end
|
15
15
|
|
16
|
-
it "should should include the IndirectionHooks module in its indirection" do
|
17
|
-
Puppet::FileServing::Metadata.indirection.singleton_class.included_modules.should include(Puppet::FileServing::IndirectionHooks)
|
18
|
-
end
|
19
|
-
|
20
16
|
it "should have a method that triggers attribute collection" do
|
21
17
|
Puppet::FileServing::Metadata.new("/foo/bar").should respond_to(:collect)
|
22
18
|
end
|
@@ -12,6 +12,10 @@ describe Puppet::FileServing::Mount::Modules do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "when finding files" do
|
15
|
+
it "should fail if no module is specified" do
|
16
|
+
expect { @mount.find("", @request) }.to raise_error(/No module specified/)
|
17
|
+
end
|
18
|
+
|
15
19
|
it "should use the provided environment to find the module" do
|
16
20
|
@environment.expects(:module)
|
17
21
|
|
@@ -37,6 +41,10 @@ describe Puppet::FileServing::Mount::Modules do
|
|
37
41
|
end
|
38
42
|
|
39
43
|
describe "when searching for files" do
|
44
|
+
it "should fail if no module is specified" do
|
45
|
+
expect { @mount.find("", @request) }.to raise_error(/No module specified/)
|
46
|
+
end
|
47
|
+
|
40
48
|
it "should use the node's environment to search the module" do
|
41
49
|
@environment.expects(:module)
|
42
50
|
|