Commit 3148355c authored by Bob Van Landuyt's avatar Bob Van Landuyt

Reuse `InternalRedirect` for the `EE::SessionsController`

parent 73a97a67
module InternalRedirect module InternalRedirect
prepend EE::InternalRedirect
extend ActiveSupport::Concern extend ActiveSupport::Concern
def safe_redirect_path(path) def safe_redirect_path(path)
......
module EE
module InternalRedirect
extend ::Gitlab::Utils::Override
override :host_allowed?
def host_allowed?(uri)
return true if super
# Redirect is not only allowed to current host, but also to other Geo
# nodes. relative_url_root *must* be ignored here as we don't know what
# is root and what is path
truncated = uri.dup.tap { |uri| uri.path = '/' }
::GeoNode.with_url_prefix(truncated).exists?
end
end
end
...@@ -36,17 +36,5 @@ module EE ...@@ -36,17 +36,5 @@ module EE
super super
end end
override :redirect_allowed_to?
def redirect_allowed_to?(uri)
# Redirect is not only allowed to current host, but also to other Geo
# nodes. relative_url_root *must* be ignored here as we don't know what
# is root and what is path
super || begin
truncated = uri.dup.tap { |uri| uri.path = '/' }
::GeoNode.with_url_prefix(truncated).exists?
end
end
end end
end end
require 'spec_helper'
describe InternalRedirect do
let(:controller_class) do
Class.new do
include InternalRedirect
def request
@request ||= Struct.new(:host, :port).new('test.host', 80)
end
end
end
subject(:controller) { controller_class.new }
describe '#host_allowed?' do
it 'allows redirecting to existing geo nodes' do
create(:geo_node, url: 'http://narnia.test.host')
expect(controller.host_allowed?(URI('http://narnia.test.host/test'))).to be(true)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment