Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/puppet/http/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ class Puppet::HTTP::Service
#
# @api private
def self.create_service(client, session, name, server = nil, port = nil)
# this is the entry point for creating all services, check and issue warning here.
# this is the entry point for creating all services, check and issue error(s)/warning(s) here.
unless Puppet.settings.set_by_config? :server
if Puppet.features.root?
Puppet.deprecation_warning('OpenVox will not default to `server=puppet` as of version 9.0. Please update your configuration appropriately.')
error_message = <<~MSG
OpenVox does not default to `server=puppet` as of version 9.0. Please update your configuration appropriately by providing a specific server of your choice.

You can update the server setting in puppet.conf by running a command similar to:
puppet config --section main set server YOUR_SERVER_NAME
MSG
raise ArgumentError, error_message
else
Puppet.deprecation_warning('OpenVox no longer defaults to `server=puppet` when running as a non-privileged user. (Did you mean to run as root?)')

Expand Down
1 change: 1 addition & 0 deletions spec/unit/http/service/ca_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
let(:subject) { client.create_session.route_to(:ca) }

before :each do
allow(Puppet.features).to receive(:root?).and_return(false)
Puppet[:ca_server] = 'www.example.com'
Puppet[:ca_port] = 443
end
Expand Down
1 change: 1 addition & 0 deletions spec/unit/http/service/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
let(:report) { Puppet::Transaction::Report.new }

before :each do
allow(Puppet.features).to receive(:root?).and_return(false)
Puppet[:report_server] = 'www.example.com'
Puppet[:report_port] = 443
end
Expand Down
26 changes: 26 additions & 0 deletions spec/unit/http/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,37 @@ def mime_types(model)
end

it 'raises for unknown service names' do
allow(Puppet.settings).to receive(:set_by_config?).and_call_original
allow(Puppet.settings).to receive(:set_by_config?).with(:server).and_return(true)

expect {
described_class.create_service(client, session, :westbound)
}.to raise_error(ArgumentError, "Unknown service westbound")
end

it 'raises when server is unconfigured while running as root' do
allow(Puppet.settings).to receive(:set_by_config?).and_call_original
allow(Puppet.settings).to receive(:set_by_config?).with(:server).and_return(false)
allow(Puppet.features).to receive(:root?).and_return(true)

expect {
described_class.create_service(client, session, :westbound)
}.to raise_error(ArgumentError, /OpenVox does not default to `server=puppet` as of version 9\.0/)
end

it 'shows a non-privileged deprecation warning when server is unconfigured while running as non-root' do
allow(Puppet.settings).to receive(:set_by_config?).and_call_original
allow(Puppet.settings).to receive(:set_by_config?).with(:server).and_return(false)
allow(Puppet.features).to receive(:root?).and_return(false)

expect(Puppet).to receive(:deprecation_warning).with('OpenVox no longer defaults to `server=puppet` when running as a non-privileged user. (Did you mean to run as root?)')

expect {
# following call is needed to trigger above warning
described_class.create_service(client, session, :puppet)
}.to raise_error(ArgumentError, 'Required setting `server` is not specified.')
end

[:ca].each do |name|
it "returns true for #{name}" do
expect(described_class.valid_name?(name)).to eq(true)
Expand Down
1 change: 1 addition & 0 deletions spec/unit/indirector/report/rest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
end

before(:each) do
allow(Puppet.features).to receive(:root?).and_return(false)
Puppet[:report_server] = 'puppet'
described_class.indirection.terminus_class = :rest
end
Expand Down