puppet 6.14.0-x86-mingw32 → 6.15.0-x86-mingw32
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +15 -15
- data/ext/windows/service/daemon.rb +3 -3
- data/lib/puppet.rb +1 -1
- data/lib/puppet/agent.rb +2 -10
- data/lib/puppet/application/agent.rb +2 -1
- data/lib/puppet/application/filebucket.rb +5 -14
- data/lib/puppet/application/ssl.rb +2 -2
- data/lib/puppet/configurer.rb +7 -3
- data/lib/puppet/configurer/plugin_handler.rb +1 -1
- data/lib/puppet/defaults.rb +22 -2
- data/lib/puppet/environments.rb +4 -5
- data/lib/puppet/face/plugin.rb +1 -1
- data/lib/puppet/file_system/file_impl.rb +13 -9
- data/lib/puppet/forge/repository.rb +1 -1
- data/lib/puppet/functions/call.rb +1 -1
- data/lib/puppet/functions/reduce.rb +2 -4
- data/lib/puppet/http.rb +2 -0
- data/lib/puppet/http/client.rb +191 -52
- data/lib/puppet/http/external_client.rb +96 -0
- data/lib/puppet/http/redirector.rb +34 -0
- data/lib/puppet/http/resolver.rb +46 -3
- data/lib/puppet/http/resolver/server_list.rb +75 -15
- data/lib/puppet/http/resolver/settings.rb +22 -2
- data/lib/puppet/http/resolver/srv.rb +28 -2
- data/lib/puppet/http/response.rb +63 -1
- data/lib/puppet/http/retry_after_handler.rb +39 -0
- data/lib/puppet/http/service.rb +67 -1
- data/lib/puppet/http/service/ca.rb +71 -9
- data/lib/puppet/http/service/compiler.rb +213 -11
- data/lib/puppet/http/service/file_server.rb +105 -4
- data/lib/puppet/http/service/report.rb +36 -3
- data/lib/puppet/http/session.rb +59 -8
- data/lib/puppet/indirector/catalog/rest.rb +2 -1
- data/lib/puppet/indirector/facts/rest.rb +2 -1
- data/lib/puppet/indirector/file_bucket_file/rest.rb +48 -0
- data/lib/puppet/indirector/file_metadata/rest.rb +4 -2
- data/lib/puppet/indirector/node/rest.rb +2 -1
- data/lib/puppet/indirector/report/yaml.rb +23 -0
- data/lib/puppet/indirector/status/rest.rb +2 -1
- data/lib/puppet/metatype/manager.rb +80 -80
- data/lib/puppet/network/http/base_pool.rb +6 -1
- data/lib/puppet/network/http/pool.rb +2 -4
- data/lib/puppet/network/http_pool.rb +1 -0
- data/lib/puppet/node/environment.rb +11 -1
- data/lib/puppet/pal/pal_impl.rb +1 -29
- data/lib/puppet/parser/compiler.rb +14 -7
- data/lib/puppet/parser/functions.rb +18 -13
- data/lib/puppet/pops/loaders.rb +7 -5
- data/lib/puppet/provider/group/windows_adsi.rb +3 -3
- data/lib/puppet/provider/package/apt.rb +61 -1
- data/lib/puppet/provider/package/dnfmodule.rb +39 -12
- data/lib/puppet/provider/package/gem.rb +41 -7
- data/lib/puppet/provider/package/pacman.rb +2 -5
- data/lib/puppet/provider/package/pip.rb +105 -33
- data/lib/puppet/provider/package/pip3.rb +0 -2
- data/lib/puppet/provider/package/pkgdmg.rb +1 -1
- data/lib/puppet/provider/package/pkgng.rb +16 -4
- data/lib/puppet/provider/package/puppet_gem.rb +6 -2
- data/lib/puppet/provider/package/rpm.rb +6 -213
- data/lib/puppet/provider/package/yum.rb +92 -19
- data/lib/puppet/provider/service/systemd.rb +2 -1
- data/lib/puppet/reports/http.rb +13 -11
- data/lib/puppet/resource/type_collection.rb +20 -16
- data/lib/puppet/ssl.rb +1 -0
- data/lib/puppet/ssl/host.rb +4 -4
- data/lib/puppet/ssl/oids.rb +1 -0
- data/lib/puppet/ssl/state_machine.rb +50 -33
- data/lib/puppet/transaction/report.rb +2 -2
- data/lib/puppet/type.rb +6 -1
- data/lib/puppet/type/file/source.rb +4 -2
- data/lib/puppet/type/package.rb +25 -2
- data/lib/puppet/type/user.rb +0 -19
- data/lib/puppet/util/at_fork.rb +1 -1
- data/lib/puppet/util/autoload.rb +3 -0
- data/lib/puppet/util/instance_loader.rb +14 -10
- data/lib/puppet/util/package/version/debian.rb +175 -0
- data/lib/puppet/util/package/version/gem.rb +15 -0
- data/lib/puppet/util/package/version/pip.rb +167 -0
- data/lib/puppet/util/package/version/range.rb +50 -0
- data/lib/puppet/util/package/version/range/gt.rb +14 -0
- data/lib/puppet/util/package/version/range/gt_eq.rb +14 -0
- data/lib/puppet/util/package/version/range/lt.rb +14 -0
- data/lib/puppet/util/package/version/range/lt_eq.rb +14 -0
- data/lib/puppet/util/package/version/range/min_max.rb +21 -0
- data/lib/puppet/util/package/version/range/simple.rb +11 -0
- data/lib/puppet/util/package/version/rpm.rb +73 -0
- data/lib/puppet/util/pidlock.rb +13 -7
- data/lib/puppet/util/platform.rb +5 -0
- data/lib/puppet/util/rpm_compare.rb +193 -0
- data/lib/puppet/util/windows/adsi.rb +2 -2
- data/lib/puppet/util/windows/process.rb +15 -14
- data/lib/puppet/util/windows/security.rb +1 -0
- data/lib/puppet/util/windows/sid.rb +3 -3
- data/lib/puppet/version.rb +1 -1
- data/locales/puppet.pot +207 -201
- data/man/man5/puppet.conf.5 +11 -3
- data/man/man8/puppet-agent.8 +1 -1
- data/man/man8/puppet-apply.8 +1 -1
- data/man/man8/puppet-catalog.8 +1 -1
- data/man/man8/puppet-config.8 +1 -1
- data/man/man8/puppet-describe.8 +1 -1
- data/man/man8/puppet-device.8 +1 -1
- data/man/man8/puppet-doc.8 +1 -1
- data/man/man8/puppet-epp.8 +1 -1
- data/man/man8/puppet-facts.8 +1 -1
- data/man/man8/puppet-filebucket.8 +1 -1
- data/man/man8/puppet-generate.8 +1 -1
- data/man/man8/puppet-help.8 +1 -1
- data/man/man8/puppet-key.8 +1 -1
- data/man/man8/puppet-lookup.8 +1 -1
- data/man/man8/puppet-man.8 +1 -1
- data/man/man8/puppet-module.8 +1 -1
- data/man/man8/puppet-node.8 +1 -1
- data/man/man8/puppet-parser.8 +1 -1
- data/man/man8/puppet-plugin.8 +1 -1
- data/man/man8/puppet-report.8 +1 -1
- data/man/man8/puppet-resource.8 +1 -1
- data/man/man8/puppet-script.8 +1 -1
- data/man/man8/puppet-ssl.8 +1 -1
- data/man/man8/puppet-status.8 +1 -1
- data/man/man8/puppet.8 +2 -2
- data/spec/fixtures/ssl/unknown-127.0.0.1-key.pem +67 -0
- data/spec/fixtures/ssl/unknown-127.0.0.1.pem +48 -0
- data/spec/fixtures/ssl/unknown-ca-key.pem +67 -0
- data/spec/fixtures/ssl/unknown-ca.pem +59 -0
- data/spec/fixtures/unit/provider/package/dnfmodule/{dnf-module-list-installed.txt → dnf-module-list-enabled.txt} +2 -0
- data/spec/fixtures/unit/provider/package/pkgng/pkg.version +2 -0
- data/spec/fixtures/unit/provider/package/yum/yum-check-update-subscription-manager.txt +9 -0
- data/spec/fixtures/unit/provider/service/systemd/list_unit_files_services +9 -0
- data/spec/integration/application/agent_spec.rb +329 -0
- data/spec/integration/application/apply_spec.rb +132 -3
- data/spec/integration/application/filebucket_spec.rb +190 -0
- data/spec/integration/application/plugin_spec.rb +50 -0
- data/spec/integration/http/client_spec.rb +34 -40
- data/spec/integration/indirector/report/yaml.rb +83 -0
- data/spec/integration/module_tool/forge_spec.rb +2 -15
- data/spec/integration/network/http_pool_spec.rb +11 -19
- data/spec/integration/node/environment_spec.rb +15 -0
- data/spec/integration/util/windows/adsi_spec.rb +1 -1
- data/spec/lib/puppet/test_ca.rb +2 -2
- data/spec/lib/puppet_spec/https.rb +10 -7
- data/spec/lib/puppet_spec/puppetserver.rb +119 -0
- data/spec/shared_contexts/https.rb +29 -0
- data/spec/unit/agent_spec.rb +33 -25
- data/spec/unit/application/agent_spec.rb +5 -1
- data/spec/unit/application/device_spec.rb +2 -2
- data/spec/unit/application/filebucket_spec.rb +22 -2
- data/spec/unit/configurer_spec.rb +1 -1
- data/spec/unit/defaults_spec.rb +24 -1
- data/spec/unit/environments_spec.rb +8 -0
- data/spec/unit/file_system_spec.rb +10 -0
- data/spec/unit/http/client_spec.rb +105 -46
- data/spec/unit/http/external_client_spec.rb +201 -0
- data/spec/unit/http/resolver_spec.rb +20 -0
- data/spec/unit/http/service/ca_spec.rb +25 -2
- data/spec/unit/http/service/compiler_spec.rb +184 -6
- data/spec/unit/http/service/file_server_spec.rb +35 -3
- data/spec/unit/http/service/report_spec.rb +3 -1
- data/spec/unit/http/service_spec.rb +3 -3
- data/spec/unit/http/session_spec.rb +56 -7
- data/spec/unit/indirector/file_bucket_file/rest_spec.rb +82 -2
- data/spec/unit/network/http/pool_spec.rb +3 -3
- data/spec/unit/node/environment_spec.rb +16 -0
- data/spec/unit/provider/group/windows_adsi_spec.rb +43 -10
- data/spec/unit/provider/package/apt_spec.rb +30 -0
- data/spec/unit/provider/package/dnfmodule_spec.rb +33 -14
- data/spec/unit/provider/package/gem_spec.rb +40 -0
- data/spec/unit/provider/package/pacman_spec.rb +6 -21
- data/spec/unit/provider/package/pip_spec.rb +26 -3
- data/spec/unit/provider/package/pkgdmg_spec.rb +1 -1
- data/spec/unit/provider/package/pkgng_spec.rb +38 -0
- data/spec/unit/provider/package/puppet_gem_spec.rb +8 -0
- data/spec/unit/provider/package/rpm_spec.rb +0 -212
- data/spec/unit/provider/package/yum_spec.rb +235 -1
- data/spec/unit/provider/service/systemd_spec.rb +10 -1
- data/spec/unit/provider/user/windows_adsi_spec.rb +3 -3
- data/spec/unit/puppet_pal_2pec.rb +0 -29
- data/spec/unit/reports/http_spec.rb +70 -52
- data/spec/unit/ssl/host_spec.rb +4 -2
- data/spec/unit/ssl/oids_spec.rb +1 -0
- data/spec/unit/ssl/state_machine_spec.rb +38 -6
- data/spec/unit/transaction/report_spec.rb +4 -0
- data/spec/unit/util/at_fork_spec.rb +2 -2
- data/spec/unit/util/package/version/debian_spec.rb +83 -0
- data/spec/unit/util/package/version/pip_spec.rb +464 -0
- data/spec/unit/util/package/version/range_spec.rb +154 -0
- data/spec/unit/util/package/version/rpm_spec.rb +121 -0
- data/spec/unit/util/pidlock_spec.rb +83 -47
- data/spec/unit/util/rpm_compare_spec.rb +196 -0
- data/spec/unit/util/windows/adsi_spec.rb +4 -4
- data/spec/unit/util/windows/sid_spec.rb +2 -2
- data/tasks/generate_cert_fixtures.rake +15 -1
- metadata +51 -6
- data/spec/integration/faces/plugin_spec.rb +0 -63
@@ -4,21 +4,8 @@ require 'puppet_spec/https'
|
|
4
4
|
|
5
5
|
describe Puppet::Forge, unless: Puppet::Util::Platform.jruby? do
|
6
6
|
include PuppetSpec::Files
|
7
|
+
include_context "https client"
|
7
8
|
|
8
|
-
before :all do
|
9
|
-
WebMock.disable!
|
10
|
-
end
|
11
|
-
|
12
|
-
after :all do
|
13
|
-
WebMock.enable!
|
14
|
-
end
|
15
|
-
|
16
|
-
before :each do
|
17
|
-
# make sure we don't take too long
|
18
|
-
Puppet[:http_connect_timeout] = '5s'
|
19
|
-
end
|
20
|
-
|
21
|
-
let(:hostname) { '127.0.0.1' }
|
22
9
|
let(:wrong_hostname) { 'localhost' }
|
23
10
|
let(:server) { PuppetSpec::HTTPSServer.new }
|
24
11
|
let(:ssl_provider) { Puppet::SSL::SSLProvider.new }
|
@@ -41,7 +28,7 @@ describe Puppet::Forge, unless: Puppet::Util::Platform.jruby? do
|
|
41
28
|
# override path to system cacert bundle, this must be done before
|
42
29
|
# the SSLContext is created and the call to X509::Store.set_default_paths
|
43
30
|
Puppet::Util.withenv("SSL_CERT_FILE" => ssl_file) do
|
44
|
-
response_proc = -> res {
|
31
|
+
response_proc = -> (req, res) {
|
45
32
|
res.status = 200
|
46
33
|
res.body = release_response
|
47
34
|
}
|
@@ -24,14 +24,6 @@ describe Puppet::Network::HttpPool, unless: Puppet::Util::Platform.jruby? do
|
|
24
24
|
let(:server) { PuppetSpec::HTTPSServer.new }
|
25
25
|
|
26
26
|
context "when calling deprecated HttpPool methods" do
|
27
|
-
let(:ssl_host) {
|
28
|
-
# use server's cert/key as the client cert/key
|
29
|
-
host = Puppet::SSL::Host.new
|
30
|
-
host.key = Puppet::SSL::Key.from_instance(server.server_key, host.name)
|
31
|
-
host.certificate = Puppet::SSL::Certificate.from_instance(server.server_cert, host.name)
|
32
|
-
host
|
33
|
-
}
|
34
|
-
|
35
27
|
before(:each) do
|
36
28
|
ssldir = tmpdir('http_pool')
|
37
29
|
Puppet[:ssldir] = ssldir
|
@@ -43,16 +35,6 @@ describe Puppet::Network::HttpPool, unless: Puppet::Util::Platform.jruby? do
|
|
43
35
|
File.write(Puppet[:hostprivkey], server.server_key.to_pem)
|
44
36
|
end
|
45
37
|
|
46
|
-
# Can't use `around(:each)` because it will cause ssl_host to be
|
47
|
-
# created outside of any rspec example, and $confdir won't be set
|
48
|
-
before(:each) do
|
49
|
-
Puppet.push_context(ssl_host: ssl_host)
|
50
|
-
end
|
51
|
-
|
52
|
-
after (:each) do
|
53
|
-
Puppet.pop_context
|
54
|
-
end
|
55
|
-
|
56
38
|
def connection(host, port)
|
57
39
|
Puppet::Network::HttpPool.http_instance(host, port, use_ssl: true)
|
58
40
|
end
|
@@ -99,6 +81,16 @@ describe Puppet::Network::HttpPool, unless: Puppet::Util::Platform.jruby? do
|
|
99
81
|
end
|
100
82
|
end
|
101
83
|
|
84
|
+
it "doesn't generate a Puppet::SSL::Host deprecation warning" do
|
85
|
+
server.start_server do |port|
|
86
|
+
http = connection(hostname, port)
|
87
|
+
res = http.get('/')
|
88
|
+
expect(res.code).to eq('200')
|
89
|
+
end
|
90
|
+
|
91
|
+
expect(@logs).to eq([])
|
92
|
+
end
|
93
|
+
|
102
94
|
it "detects when the server has closed the connection and reconnects" do
|
103
95
|
server.start_server do |port|
|
104
96
|
http = connection(hostname, port)
|
@@ -115,7 +107,7 @@ describe Puppet::Network::HttpPool, unless: Puppet::Util::Platform.jruby? do
|
|
115
107
|
|
116
108
|
context "when using persistent HTTPS connections" do
|
117
109
|
around :each do |example|
|
118
|
-
pool = Puppet::Network::HTTP::Pool.new
|
110
|
+
pool = Puppet::Network::HTTP::Pool.new(15)
|
119
111
|
Puppet.override(:http_pool => pool) do
|
120
112
|
example.run
|
121
113
|
end
|
@@ -76,6 +76,21 @@ describe Puppet::Node::Environment do
|
|
76
76
|
expect(mods[0].path).to eq(File.join(base, "dir1", "mod"))
|
77
77
|
end
|
78
78
|
|
79
|
+
it "should not yield a module with the same name as a defined Bolt project" do
|
80
|
+
project_path = File.join(tmpfile('project'), 'bolt_project')
|
81
|
+
FileUtils.mkdir_p(project_path)
|
82
|
+
project = Struct.new("Project", :name, :path).new('project', project_path)
|
83
|
+
|
84
|
+
Puppet.override(bolt_project: project) do
|
85
|
+
base = tmpfile("base")
|
86
|
+
FileUtils.mkdir_p([File.join(base, 'project'), File.join(base, 'other')])
|
87
|
+
environment = Puppet::Node::Environment.create(:env, [base])
|
88
|
+
mods = environment.modules
|
89
|
+
expect(mods.length).to eq(2)
|
90
|
+
expect(mods.map(&:path)).to eq([project_path, File.join(base, 'other')])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
79
94
|
shared_examples_for "the environment's initial import" do |settings|
|
80
95
|
it "a manifest referring to a directory invokes parsing of all its files in sorted order" do
|
81
96
|
settings.each do |name, value|
|
@@ -160,7 +160,7 @@ describe Puppet::Util::Windows::ADSI::Group,
|
|
160
160
|
|
161
161
|
# unresolvable SID
|
162
162
|
expect(admins.members[1].sid).to eq('S-1-5-21-3661721861-956923663-2119435483-1112')
|
163
|
-
expect(admins.members[1].account).to eq('S-1-5-21-3661721861-956923663-2119435483-1112
|
163
|
+
expect(admins.members[1].account).to eq('S-1-5-21-3661721861-956923663-2119435483-1112')
|
164
164
|
expect(admins.members[1].account_type).to eq(:SidTypeUnknown)
|
165
165
|
end
|
166
166
|
|
data/spec/lib/puppet/test_ca.rb
CHANGED
@@ -21,9 +21,9 @@ module Puppet
|
|
21
21
|
id
|
22
22
|
end
|
23
23
|
|
24
|
-
def initialize
|
24
|
+
def initialize(name = 'Test CA')
|
25
25
|
@digest = OpenSSL::Digest::SHA256.new
|
26
|
-
info = create_cacert(
|
26
|
+
info = create_cacert(name)
|
27
27
|
@key = info[:private_key]
|
28
28
|
@ca_cert = info[:cert]
|
29
29
|
@ca_crl = create_crl(@ca_cert, @key)
|
@@ -6,11 +6,11 @@ class PuppetSpec::HTTPSServer
|
|
6
6
|
|
7
7
|
attr_reader :ca_cert, :ca_crl, :server_cert, :server_key
|
8
8
|
|
9
|
-
def initialize
|
10
|
-
@ca_cert = cert_fixture('ca.pem')
|
11
|
-
@ca_crl = crl_fixture('crl.pem')
|
12
|
-
@server_key = key_fixture('127.0.0.1-key.pem')
|
13
|
-
@server_cert = cert_fixture('127.0.0.1.pem')
|
9
|
+
def initialize(ca_cert: nil, ca_crl: nil, server_key: nil, server_cert: nil)
|
10
|
+
@ca_cert = ca_cert || cert_fixture('ca.pem')
|
11
|
+
@ca_crl = ca_crl || crl_fixture('crl.pem')
|
12
|
+
@server_key = server_key || key_fixture('127.0.0.1-key.pem')
|
13
|
+
@server_cert = server_cert || cert_fixture('127.0.0.1.pem')
|
14
14
|
@config = WEBrick::Config::HTTP.dup
|
15
15
|
end
|
16
16
|
|
@@ -18,10 +18,13 @@ class PuppetSpec::HTTPSServer
|
|
18
18
|
req = WEBrick::HTTPRequest.new(@config)
|
19
19
|
req.parse(ssl)
|
20
20
|
|
21
|
+
# always drain request body
|
22
|
+
req.body
|
23
|
+
|
21
24
|
res = WEBrick::HTTPResponse.new(@config)
|
22
25
|
res.status = 200
|
23
26
|
res.body = 'OK'
|
24
|
-
response_proc.call(res) if response_proc
|
27
|
+
response_proc.call(req, res) if response_proc
|
25
28
|
|
26
29
|
res.send_response(ssl)
|
27
30
|
end
|
@@ -52,7 +55,7 @@ class PuppetSpec::HTTPSServer
|
|
52
55
|
|
53
56
|
loop do
|
54
57
|
readable, = IO.select([ssls, stop_pipe_r])
|
55
|
-
break if readable.include?
|
58
|
+
break if readable.include?(stop_pipe_r)
|
56
59
|
|
57
60
|
ssl = ssls.accept
|
58
61
|
begin
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'webrick'
|
3
|
+
require "webrick/ssl"
|
4
|
+
|
5
|
+
class PuppetSpec::Puppetserver
|
6
|
+
include PuppetSpec::Fixtures
|
7
|
+
include PuppetSpec::Files
|
8
|
+
|
9
|
+
attr_reader :ca_cert, :ca_crl, :server_cert, :server_key
|
10
|
+
|
11
|
+
class NodeServlet < WEBrick::HTTPServlet::AbstractServlet
|
12
|
+
def do_GET request, response
|
13
|
+
node = Puppet::Node.new(Puppet[:certname])
|
14
|
+
response.body = node.render(:json)
|
15
|
+
response['Content-Type'] = 'application/json'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class CatalogServlet < WEBrick::HTTPServlet::AbstractServlet
|
20
|
+
def do_POST request, response
|
21
|
+
response['Content-Type'] = 'application/json'
|
22
|
+
catalog = Puppet::Resource::Catalog.new(Puppet[:certname], 'production')
|
23
|
+
response.body = catalog.render(:json)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class FileMetadatasServlet < WEBrick::HTTPServlet::AbstractServlet
|
28
|
+
def do_GET request, response
|
29
|
+
response['Content-Type'] = 'application/json'
|
30
|
+
response.body = "[{\"path\":\"/etc/puppetlabs/code/environments/production/modules\",\"relative_path\":\".\",\"links\":\"follow\",\"owner\":0,\"group\":0,\"mode\":493,\"checksum\":{\"type\":\"ctime\",\"value\":\"{ctime}2020-03-06 20:14:25 UTC\"},\"type\":\"directory\",\"destination\":null}]"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class ReportServlet < WEBrick::HTTPServlet::AbstractServlet
|
35
|
+
def do_PUT request, response
|
36
|
+
response['Content-Type'] = 'application/json'
|
37
|
+
response.body = "[]"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class StaticFileContentServlet < WEBrick::HTTPServlet::AbstractServlet
|
42
|
+
def do_GET request, response
|
43
|
+
response.status = 404
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class FilebucketServlet < WEBrick::HTTPServlet::AbstractServlet
|
48
|
+
def do_GET request, response
|
49
|
+
end
|
50
|
+
def do_PUT request, response
|
51
|
+
response['Content-Type'] = 'application/octet-stream'
|
52
|
+
end
|
53
|
+
def do_HEAD request, response
|
54
|
+
response.status = 404
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def initialize
|
59
|
+
@ca_cert = cert_fixture('ca.pem')
|
60
|
+
@ca_crl = crl_fixture('crl.pem')
|
61
|
+
@server_key = key_fixture('127.0.0.1-key.pem')
|
62
|
+
@server_cert = cert_fixture('127.0.0.1.pem')
|
63
|
+
@path = tmpfile('webrick')
|
64
|
+
|
65
|
+
@https = WEBrick::HTTPServer.new(
|
66
|
+
BindAddress: "127.0.0.1",
|
67
|
+
Port: 0, # webrick will choose the first available port, and set it in the config
|
68
|
+
SSLEnable: true,
|
69
|
+
SSLStartImmediately: true,
|
70
|
+
SSLCACertificateFile: File.join(PuppetSpec::FIXTURE_DIR, 'ssl', 'ca.pem'),
|
71
|
+
SSLCertificate: @server_cert,
|
72
|
+
SSLPrivateKey: @server_key,
|
73
|
+
Logger: WEBrick::Log.new(@path),
|
74
|
+
AccessLog: [
|
75
|
+
[@path, WEBrick::AccessLog::COMBINED_LOG_FORMAT],
|
76
|
+
]
|
77
|
+
)
|
78
|
+
|
79
|
+
trap('INT') do
|
80
|
+
@https.shutdown
|
81
|
+
end
|
82
|
+
|
83
|
+
# Enable this line for more detailed webrick logging
|
84
|
+
# @https.logger.level = 5 # DEBUG
|
85
|
+
end
|
86
|
+
|
87
|
+
def start_server(mounts: {}, &block)
|
88
|
+
register_mounts(mounts: mounts)
|
89
|
+
|
90
|
+
Thread.new do
|
91
|
+
@https.start
|
92
|
+
end
|
93
|
+
|
94
|
+
begin
|
95
|
+
yield @https.config[:Port]
|
96
|
+
ensure
|
97
|
+
@https.shutdown
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def register_mounts(mounts: {})
|
102
|
+
register_mount('/status/v1/simple/master', proc { |req, res| }, nil)
|
103
|
+
register_mount('/puppet/v3/node', mounts[:node], NodeServlet)
|
104
|
+
register_mount('/puppet/v3/catalog', mounts[:catalog], CatalogServlet)
|
105
|
+
register_mount('/puppet/v3/file_metadatas', mounts[:file_metadatas], FileMetadatasServlet)
|
106
|
+
register_mount('/puppet/v3/static_file_content', mounts[:static_file_content], StaticFileContentServlet)
|
107
|
+
register_mount('/puppet/v3/report', mounts[:report], ReportServlet)
|
108
|
+
register_mount('/puppet/v3/file_bucket_file', mounts[:filebucket], FilebucketServlet)
|
109
|
+
end
|
110
|
+
|
111
|
+
def register_mount(path, user_proc, default_servlet)
|
112
|
+
handler = if user_proc
|
113
|
+
WEBrick::HTTPServlet::ProcHandler.new(user_proc)
|
114
|
+
else
|
115
|
+
default_servlet
|
116
|
+
end
|
117
|
+
@https.mount(path, handler)
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.shared_context('https client') do
|
4
|
+
before :all do
|
5
|
+
WebMock.disable!
|
6
|
+
end
|
7
|
+
|
8
|
+
after :all do
|
9
|
+
WebMock.enable!
|
10
|
+
end
|
11
|
+
|
12
|
+
before :each do
|
13
|
+
# make sure we don't take too long
|
14
|
+
Puppet[:http_connect_timeout] = '5s'
|
15
|
+
Puppet[:server] = '127.0.0.1'
|
16
|
+
Puppet[:certname] = '127.0.0.1'
|
17
|
+
|
18
|
+
Puppet[:localcacert] = File.join(PuppetSpec::FIXTURE_DIR, 'ssl', 'ca.pem')
|
19
|
+
Puppet[:hostcrl] = File.join(PuppetSpec::FIXTURE_DIR, 'ssl', 'crl.pem')
|
20
|
+
Puppet[:hostprivkey] = File.join(PuppetSpec::FIXTURE_DIR, 'ssl', '127.0.0.1-key.pem')
|
21
|
+
Puppet[:hostcert] = File.join(PuppetSpec::FIXTURE_DIR, 'ssl', '127.0.0.1.pem')
|
22
|
+
|
23
|
+
# set in memory facts since certname is changed above
|
24
|
+
facts = Puppet::Node::Facts.new(Puppet[:certname])
|
25
|
+
Puppet::Node::Facts.indirection.save(facts)
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:https_server) { PuppetSpec::HTTPSServer.new }
|
29
|
+
end
|
data/spec/unit/agent_spec.rb
CHANGED
@@ -185,31 +185,26 @@ describe Puppet::Agent do
|
|
185
185
|
|
186
186
|
# So we don't actually try to hit the filesystem.
|
187
187
|
allow(@agent).to receive(:lock).and_yield
|
188
|
-
|
189
|
-
allow(Kernel).to receive(:fork)
|
190
|
-
allow(Process).to receive(:waitpid2).and_return([123, double('process::status', :exitstatus => 0)])
|
191
|
-
allow(@agent).to receive(:exit)
|
192
188
|
end
|
193
189
|
|
194
190
|
it "should run the agent in a forked process" do
|
195
191
|
client = AgentTestClient.new
|
196
192
|
expect(AgentTestClient).to receive(:new).and_return(client)
|
197
193
|
|
198
|
-
expect(client).to receive(:run)
|
194
|
+
expect(client).to receive(:run).and_return(0)
|
199
195
|
|
200
196
|
expect(Kernel).to receive(:fork).and_yield
|
201
|
-
@agent.run
|
197
|
+
expect { @agent.run }.to exit_with(0)
|
202
198
|
end
|
203
199
|
|
204
200
|
it "should exit child process if child exit" do
|
205
201
|
client = AgentTestClient.new
|
206
202
|
expect(AgentTestClient).to receive(:new).and_return(client)
|
207
203
|
|
208
|
-
expect(client).to receive(:run).and_raise(SystemExit)
|
204
|
+
expect(client).to receive(:run).and_raise(SystemExit.new(-1))
|
209
205
|
|
210
206
|
expect(Kernel).to receive(:fork).and_yield
|
211
|
-
expect
|
212
|
-
@agent.run
|
207
|
+
expect { @agent.run }.to exit_with(-1)
|
213
208
|
end
|
214
209
|
|
215
210
|
it 'should exit with 1 if an exception is raised' do
|
@@ -219,31 +214,44 @@ describe Puppet::Agent do
|
|
219
214
|
expect(client).to receive(:run).and_raise(StandardError)
|
220
215
|
|
221
216
|
expect(Kernel).to receive(:fork).and_yield
|
222
|
-
expect
|
223
|
-
@agent.run
|
217
|
+
expect { @agent.run }.to exit_with(1)
|
224
218
|
end
|
225
219
|
|
226
|
-
it
|
227
|
-
|
228
|
-
expect
|
220
|
+
it 'should exit with 254 if NoMemoryError exception is raised' do
|
221
|
+
client = AgentTestClient.new
|
222
|
+
expect(AgentTestClient).to receive(:new).and_return(client)
|
223
|
+
|
224
|
+
expect(client).to receive(:run).and_raise(NoMemoryError)
|
225
|
+
|
226
|
+
expect(Kernel).to receive(:fork).and_yield
|
227
|
+
expect { @agent.run }.to exit_with(254)
|
229
228
|
end
|
230
229
|
|
231
|
-
it "should
|
232
|
-
|
233
|
-
expect {
|
230
|
+
it "should return the block exit code as the child exit code" do
|
231
|
+
expect(Kernel).to receive(:fork).and_yield
|
232
|
+
expect {
|
233
|
+
@agent.run_in_fork {
|
234
|
+
777
|
235
|
+
}
|
236
|
+
}.to exit_with(777)
|
234
237
|
end
|
235
238
|
|
236
|
-
it "should return the
|
237
|
-
|
238
|
-
expect
|
239
|
+
it "should return `1` exit code if the block returns `nil`" do
|
240
|
+
expect(Kernel).to receive(:fork).and_yield
|
241
|
+
expect {
|
242
|
+
@agent.run_in_fork {
|
243
|
+
nil
|
244
|
+
}
|
245
|
+
}.to exit_with(1)
|
239
246
|
end
|
240
247
|
|
241
|
-
it "should return
|
248
|
+
it "should return `1` exit code if the block returns `false`" do
|
242
249
|
expect(Kernel).to receive(:fork).and_yield
|
243
|
-
expect
|
244
|
-
|
245
|
-
|
246
|
-
|
250
|
+
expect {
|
251
|
+
@agent.run_in_fork {
|
252
|
+
false
|
253
|
+
}
|
254
|
+
}.to exit_with(1)
|
247
255
|
end
|
248
256
|
end
|
249
257
|
|
@@ -122,6 +122,10 @@ describe Puppet::Application::Agent do
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
+
it "should log the agent start time" do
|
126
|
+
expect(@puppetd.options[:start_time]).to be_a(Time)
|
127
|
+
end
|
128
|
+
|
125
129
|
it "should set waitforcert to 0 with --onetime and if --waitforcert wasn't given" do
|
126
130
|
allow(@agent).to receive(:run).and_return(2)
|
127
131
|
Puppet[:onetime] = true
|
@@ -505,7 +509,7 @@ describe Puppet::Application::Agent do
|
|
505
509
|
|
506
510
|
it "should run the agent with the supplied job_id" do
|
507
511
|
@puppetd.options[:job_id] = 'special id'
|
508
|
-
expect(@agent).to receive(:run).with(:job_id => 'special id').and_return(:report)
|
512
|
+
expect(@agent).to receive(:run).with(hash_including(:job_id => 'special id')).and_return(:report)
|
509
513
|
|
510
514
|
expect { execute_agent }.to exit_with 0
|
511
515
|
end
|
@@ -459,7 +459,7 @@ describe Puppet::Application::Device do
|
|
459
459
|
resource = Puppet::Type.type(:user).new(:name => "jim").to_resource
|
460
460
|
allow(device.command_line).to receive(:args).and_return(['user', 'jim'])
|
461
461
|
expect(Puppet::Resource.indirection).to receive(:find).with('user/jim').and_return(resource)
|
462
|
-
expect(device).to receive(:puts).with("user { 'jim':\n}")
|
462
|
+
expect(device).to receive(:puts).with("user { 'jim':\n ensure => 'absent',\n}")
|
463
463
|
expect { device.main }.to exit_with 0
|
464
464
|
end
|
465
465
|
|
@@ -470,7 +470,7 @@ describe Puppet::Application::Device do
|
|
470
470
|
allow(device.options).to receive(:[]).with(:to_yaml).and_return(true)
|
471
471
|
allow(device.command_line).to receive(:args).and_return(['user'])
|
472
472
|
expect(Puppet::Resource.indirection).to receive(:search).with('user/', {}).and_return(resources)
|
473
|
-
expect(device).to receive(:puts).with("---\nuser:\n title:
|
473
|
+
expect(device).to receive(:puts).with("---\nuser:\n title:\n ensure: absent\n")
|
474
474
|
expect { device.main }.to exit_with 0
|
475
475
|
end
|
476
476
|
end
|