fix url redirection for subdomainless

pull/14587/head
Gonzalo Riestra 6 years ago
parent 247259fa21
commit 056a5fb1a0

@ -310,7 +310,8 @@ class ApplicationController < ActionController::Base
respond_to do |format|
format.html do
session[:return_to] = request.url
redirect_to CartoDB.path(self, 'login') and return
redirect_to CartoDB.url(self, 'login', {}, nil, true)
return
end
format.json do
head :unauthorized

@ -17,7 +17,7 @@
</div>
<div class="Sessions-form">
<%= form_tag CartoDB.path(self, 'create_session'), class: "js-Loading-form" do %>
<%= form_tag CartoDB.url(self, 'create_session', {}, nil, true), class: "js-Loading-form" do %>
<% if @flash_login_error %>
<p class="CDB-Text CDB-Size-huge u-altTextColor u-tSpace--m u-justifyCenter Sessions-description" style="background: #f24440; border-radius: 4px; padding: 5px; color: #fff;">

@ -29,9 +29,13 @@ module CartoDB
# @param path String Rails route name
# @param params Hash Parameters to send to the url (Optional)
# @param user ::User (Optional) If not sent will use subdomain or /user/xxx from controller request
def self.url(context, path, params = {}, user = nil)
def self.url(context, path, params = {}, user = nil, keep_base_url = false)
base_url = if keep_base_url && !subdomainless_urls?
context.request.base_url
else
CartoDB.base_url_from_request(context.request, user)
end
# Must clean user_domain or else polymorphic_path will use it and generate again /u/xxx/user/xxx
base_url = CartoDB.base_url_from_request(context.request, user)
base_url + main_context(context).polymorphic_path(path, params.merge(user_domain: nil))
end

@ -346,12 +346,62 @@ describe Carto::OauthProviderController do
end
end
it 'logged out, redirects to login' do
logout
post oauth_provider_authorize_url(valid_payload)
context 'without session' do
before(:each) do
logout
end
expect(response.status).to(eq(302))
expect(response.location).to(include('/login'))
context 'with subdomainless' do
before(:each) do
stub_subdomainless
end
it 'redirects to login with username' do
endpoint = "http://localhost.lan:53716/user/#{@user.username}/oauth2/authorize"
expected_url = "http://localhost.lan:53716/user/#{@user.username}/login"
post endpoint, valid_payload
expect(response.status).to(eq(302))
expect(response.location).to eql expected_url
end
it 'redirects to login without username' do
endpoint = "http://localhost.lan:53716/oauth2/authorize"
expected_url = "http://localhost.lan:53716/login"
post endpoint, valid_payload
expect(response.status).to(eq(302))
expect(response.location).to eql expected_url
end
end
context 'with subdomainful' do
before(:each) do
stub_domainful('wadus')
end
it 'redirects to login with username' do
endpoint = "http://wadus.localhost.lan:53716/user/#{@user.username}/oauth2/authorize"
expected_url = "http://wadus.localhost.lan:53716/login"
post endpoint, valid_payload
expect(response.status).to(eq(302))
expect(response.location).to eql expected_url
end
it 'redirects to login without username' do
endpoint = "http://wadus.localhost.lan:53716/oauth2/authorize"
expected_url = "http://wadus.localhost.lan:53716/login"
post endpoint, valid_payload
expect(response.status).to(eq(302))
expect(response.location).to eql expected_url
end
end
end
shared_examples_for 'successfully authorizes' do

Loading…
Cancel
Save