Skip to content

Commit

Permalink
Revert default rest_v3 request data to nil (theforeman#439)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
domcleal authored and mmoll committed Apr 29, 2016
1 parent 225a212 commit b9c63f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/provider/foreman_resource/rest_v3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def generate_token
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?('/')

Expand Down
8 changes: 7 additions & 1 deletion spec/unit/foreman_resource_rest_v3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,18 @@
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')
Expand Down

0 comments on commit b9c63f9

Please sign in to comment.