From 9a0264b6efd3b24170b41ff109d1b8a3997db556 Mon Sep 17 00:00:00 2001 From: Mark Dechiaro Date: Thu, 12 Mar 2026 10:08:29 -0500 Subject: [PATCH] Fix filebucket REST terminus to support request.server The REST terminus called session.route_to(:puppet) with no URL, so route_to always resolved via the normal resolver chain and sent filebucket traffic to Puppet[:server], silently ignoring the server value encoded in the filebucket:// URI. Add specs that stub only the explicit host (xanadu:8141) so WebMock raises if the request is routed to the wrong server. Co-Authored-By: Claude Sonnet 4.6 Closes: #367 Signed-off-by: Mark Dechiaro --- .../indirector/file_bucket_file/rest.rb | 10 +++++-- .../indirector/file_bucket_file/rest_spec.rb | 28 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/puppet/indirector/file_bucket_file/rest.rb b/lib/puppet/indirector/file_bucket_file/rest.rb index ec33c651c1..236d0b0a4b 100644 --- a/lib/puppet/indirector/file_bucket_file/rest.rb +++ b/lib/puppet/indirector/file_bucket_file/rest.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require 'uri' require_relative '../../../puppet/indirector/rest' require_relative '../../../puppet/file_bucket/file' @@ -9,7 +10,8 @@ class Rest < Puppet::Indirector::REST def head(request) session = Puppet.lookup(:http_session) - api = session.route_to(:puppet) + url = URI::HTTPS.build(host: request.server, port: request.port) if request.server + api = session.route_to(:puppet, url: url) api.head_filebucket_file( request.key, environment: request.environment.to_s, @@ -23,7 +25,8 @@ def head(request) def find(request) session = Puppet.lookup(:http_session) - api = session.route_to(:puppet) + url = URI::HTTPS.build(host: request.server, port: request.port) if request.server + api = session.route_to(:puppet, url: url) _, filebucket_file = api.get_filebucket_file( request.key, environment: request.environment.to_s, @@ -40,7 +43,8 @@ def find(request) def save(request) session = Puppet.lookup(:http_session) - api = session.route_to(:puppet) + url = URI::HTTPS.build(host: request.server, port: request.port) if request.server + api = session.route_to(:puppet, url: url) api.put_filebucket_file( request.key, body: request.instance.render, diff --git a/spec/unit/indirector/file_bucket_file/rest_spec.rb b/spec/unit/indirector/file_bucket_file/rest_spec.rb index 54a566d936..f96c5c041a 100644 --- a/spec/unit/indirector/file_bucket_file/rest_spec.rb +++ b/spec/unit/indirector/file_bucket_file/rest_spec.rb @@ -86,4 +86,32 @@ expect{described_class.indirection.save(file_bucket_file, dest_path)}.to raise_error(Net::HTTPError, "Error 503 on SERVER: server unavailable") end end + + context 'when the request URI contains an explicit server' do + let(:server_uri) { %r{https://xanadu:8141/puppet/v3/file_bucket_file} } + + describe '#head' do + it 'routes the request to the server in the filebucket URI' do + stub_request(:head, server_uri) + + described_class.indirection.head(file_bucket_path, :bucket_path => file_bucket_file.bucket_path) + end + end + + describe '#find' do + it 'routes the request to the server in the filebucket URI' do + stub_request(:get, server_uri).to_return(status: 200, headers: {'Content-Type' => 'application/octet-stream'}) + + described_class.indirection.find(source_path, :bucket_path => nil) + end + end + + describe '#save' do + it 'routes the request to the server in the filebucket URI' do + stub_request(:put, server_uri) + + described_class.indirection.save(file_bucket_file, dest_path) + end + end + end end