Project

General

Profile

« Previous | Next » 

Revision eb1f2a99

Added by Dominic Cleal about 8 years ago

Revert default rest_v3 request data to nil (#439)

Fixes refreshing of smart proxies against Foreman, since the PUT
request data defaulted to `{}`. This causes the oauth gem to form
encode the empty hash data, overriding the Content-Type to application/
x-www-form-urlencoded and the request is rejected by Foreman with a 415
HTTP response.

View differences:

lib/puppet/provider/foreman_resource/rest_v3.rb
OAuth::AccessToken.new(oauth_consumer)
end
def request(method, path, params = {}, data = {}, headers = {})
def request(method, path, params = {}, data = nil, headers = {})
base_url = resource[:base_url]
base_url += '/' unless base_url.end_with?('/')
spec/unit/foreman_resource_rest_v3_spec.rb
let(:consumer) { mock('oauth_consumer') }
let(:effective_user) { 'admin' }
it 'makes request via consumer and returns response' do
it 'makes GET request via consumer and returns response' do
response = mock(:code => '200')
consumer.expects(:request).with(:get, 'https://foreman.example.com/api/v2/example', is_a(OAuth::AccessToken), {}, is_a(Hash)).returns(response)
expect(provider.request(:get, 'api/v2/example')).to eq(response)
end
it 'makes PUT request via consumer and returns response' do
response = mock(:code => '200')
consumer.expects(:request).with(:put, 'https://foreman.example.com/api/v2/example', is_a(OAuth::AccessToken), {}, nil, is_a(Hash)).returns(response)
expect(provider.request(:put, 'api/v2/example')).to eq(response)
end
it 'specifies foreman_user header' do
consumer.expects(:request).with(:get, anything, anything, anything, has_entry('foreman_user', 'admin')).returns(mock(:code => '200'))
provider.request(:get, 'api/v2/example')

Also available in: Unified diff