Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rails path mutation #122

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion lib/api_auth/request_drivers/action_dispatch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ module ApiAuth
module RequestDrivers # :nodoc:
class ActionDispatchRequest < ActionControllerRequest # :nodoc:
def request_uri
@request.fullpath
if @request.respond_to?(:original_fullpath)
@request.original_fullpath
else
@request.fullpath
end
end
end
end
Expand Down
25 changes: 23 additions & 2 deletions spec/request_drivers/action_dispatch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,29 @@
expect(driven_request.content_md5).to eq('1B2M2Y8AsgTpgAmY7PhCfg==')
end

it 'gets the request_uri' do
expect(driven_request.request_uri).to eq('/resource.xml?foo=bar&bar=foo')
describe 'request_uri' do
context 'with url parameters' do
it 'gets the request_uri' do
expect(driven_request.request_uri).to eq('/resource.xml?foo=bar&bar=foo')
end
end

context 'with mutated path' do
let(:request) do
ActionDispatch::Request.new(
'PATH_INFO' => '/resource/',
'ORIGINAL_FULLPATH' => '/resource/'
)
end

before do
request.path_info = 'overwritten_in_action_dispatch'
end

it 'gets the original path' do
expect(driven_request.request_uri).to eq('/resource/')
end
end
end

it 'gets the timestamp' do
Expand Down