pull/6378/head
Juan Ignacio Sánchez Lara 9 years ago
parent 2e743488c7
commit 6924f7ab0f

@ -92,7 +92,11 @@ class Carto::UserCreation < ActiveRecord::Base
# TODO: Shorcut, search for a better solution to detect requirement
def requires_validation_email?
google_sign_in != true && !has_valid_invitation? && !Carto::Ldap::Manager.new.configuration_present? && !created_via_api? && !created_via_http_authentication?
google_sign_in != true &&
!has_valid_invitation? &&
!Carto::Ldap::Manager.new.configuration_present? &&
!created_via_api? &&
!created_via_http_authentication?
end
def autologin?
@ -110,18 +114,18 @@ class Carto::UserCreation < ActiveRecord::Base
# Maybe some functionality of UserAccountCreator should be moved here to avoid this setter
def with_created_via(created_via)
raise "#{created_via} is not a valid value: #{VALID_CREATED_VIA.join(', ')}" unless VALID_CREATED_VIA.include?(created_via)
raise "Not valid #{created_via}: #{VALID_CREATED_VIA.join(', ')}" unless VALID_CREATED_VIA.include?(created_via)
self.created_via = created_via
self
end
def created_via_api?
self.created_via == CREATED_VIA_API
created_via == CREATED_VIA_API
end
def created_via_http_authentication?
self.created_via == CREATED_VIA_HTTP_AUTENTICATION
created_via == CREATED_VIA_HTTP_AUTENTICATION
end
def has_valid_invitation?

@ -162,15 +162,13 @@ Warden::Strategies.add(:http_header_authentication) do
end
def authenticate!
begin
user = Carto::HttpHeaderAuthentication.new.get_user(request)
return fail! unless user.present?
user = Carto::HttpHeaderAuthentication.new.get_user(request)
return fail! unless user.present?
success!(user)
rescue => e
CartoDB.notify_exception(e)
return fail!
end
success!(user)
rescue => e
CartoDB.notify_exception(e)
return fail!
end
end

@ -11,7 +11,7 @@ module Carto
end
def get_user(request)
header = identity(request)
header = identity(request)
return nil if header.nil? || header.empty?
::User.where("#{field(request)} = ?", header).first
@ -30,7 +30,7 @@ module Carto
end
def email(request)
raise "You can only fetch email if configuration is set to email or auto and request has an email" unless field(request) == 'email'
raise "Configuration is not set to email, or it's auto but request hasn't email" unless field(request) == 'email'
identity(request)
end

@ -9,11 +9,11 @@ require_relative '../../../lib/carto/http_header_authentication'
require_relative '../../requests/http_authentication_helper'
RSpec.configure do |config|
config.mock_with :mocha
config.mock_with :mocha
end
module Cartodb
def self.get_config(*args)
def self.get_config(*)
end
end
@ -31,9 +31,9 @@ describe Carto::HttpHeaderAuthentication do
OpenStruct.new(headers: {})
end
let(:mock_email_request) { OpenStruct.new(headers: { "#{authenticated_header}" => EMAIL } ) }
let(:mock_username_request) { OpenStruct.new(headers: { "#{authenticated_header}" => USERNAME } ) }
let(:mock_id_request) { OpenStruct.new(headers: { "#{authenticated_header}" => ID } ) }
let(:mock_email_request) { OpenStruct.new(headers: { "#{authenticated_header}" => EMAIL }) }
let(:mock_username_request) { OpenStruct.new(headers: { "#{authenticated_header}" => USERNAME }) }
let(:mock_id_request) { OpenStruct.new(headers: { "#{authenticated_header}" => ID }) }
let(:mock_user) do
OpenStruct.new(

@ -16,9 +16,9 @@ module HttpAuthenticationHelper
'autocreation' => autocreation
}
config.each do |field, value|
Cartodb.stubs(:get_config).with(:http_header_authentication, field).
returns(enabled ? value : nil)
config.each do |f, v|
Cartodb.stubs(:get_config).with(:http_header_authentication, f).
returns(enabled ? v: nil)
end
config

@ -295,7 +295,5 @@ describe SignupController do
end
end
end
end
end

Loading…
Cancel
Save