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

redirect_to_default_host should not throw away query parameters #1553

Merged
merged 1 commit into from
Dec 8, 2019
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
3 changes: 2 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def sandbox?
private

def redirect_to_default_host
redirect_to host: Rails.configuration.default_host
redirect_to host: Rails.configuration.default_host,
params: request.query_parameters
end

def user_not_authorized
Expand Down
33 changes: 33 additions & 0 deletions test/controllers/exercises_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,39 @@ def setup
assert_equal 'image/png', response.content_type
end

test 'should not get private media without token' do
sign_out :user
Exercise.any_instance.stubs(:media_path).returns(Pathname.new('public'))
@instance.update access: :private

get media_exercise_url(@instance, media: 'icon.png')

assert_response :redirect
end

test 'should get private media with token' do
sign_out :user
Exercise.any_instance.stubs(:media_path).returns(Pathname.new('public'))
@instance.update access: :private

get media_exercise_url(@instance, media: 'icon.png', token: @instance.access_token)

assert_response :success
end

test 'should redirect when requesting media on sandbox_host' do
sign_out :user
Exercise.any_instance.stubs(:media_path).returns(Pathname.new('public'))
@instance.update access: :private

get media_exercise_url(@instance, host: 'sandbox.example.com', media: 'icon.png', token: @instance.access_token)

assert_response :redirect
location = response.headers['location']
assert location.starts_with?('http://www.example.com'), 'should redirect to default_host'
assert location.ends_with?("?token=#{@instance.access_token}"), 'should still contain access token'
end

test 'should get exercices by repository_id' do
get exercises_url repository_id: @instance.repository.id
assert_response :success
Expand Down