Skip to content

Commit 1e83d27

Browse files
Merge pull request #15614 from CartoDB/2496_oauth_whitelist
check whitelist when signing up from login form with OAuth providers
2 parents c02c80b + 4ace0be commit 1e83d27

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ SPEC_HELPER_MIN_SPECS = \
296296
spec/requests/carto/superadmin/user_migration_imports_spec.rb \
297297
spec/requests/carto/superadmin/user_migration_exports_spec.rb \
298298
spec/requests/carto/saml_controller_spec.rb \
299+
spec/requests/carto/oauth_login_controller_spec.rb \
299300
spec/services/carto/user_table_index_service_spec.rb \
300301
spec/services/carto/user_metadata_export_service_spec.rb \
301302
spec/services/carto/organization_metadata_export_service_spec.rb \

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ sudo make install
4040
- Set node 10.15.1 as default and only for building assets, removing 6.9.2 ([#15530](https://github.com/CartoDB/cartodb/issues/15530))
4141
- Update toolkit libraries to fix case sensitive fields ([#15569](https://github.com/CartoDB/cartodb/pull/15569))
4242
- Fix to avoid locks when sorting rows in dataset table ([#2399](https://github.com/CartoDB/support/issues/2399))
43+
- Fix whitelisted domains for OAuth signup ([#2495]https://github.com/CartoDB/support/issues/2495))
4344
- Lazy loading of Dashboard routes ([#15581](https://github.com/CartoDB/cartodb/pull/15581))
4445

4546
4.36.0 (2020-03-09)

app/controllers/carto/oauth_login_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def login(api)
7575
def signup(api)
7676
org_name = @organization_name
7777
@organization = ::Organization.where(name: org_name).first if org_name.present?
78-
unless @organization.present? && api.config.auth_enabled?(@organization)
78+
unless @organization.present? && signup_page_enabled?(api)
7979
return redirect_to CartoDB.url(self, 'login')
8080
end
8181

@@ -101,5 +101,9 @@ def signup(api)
101101
end
102102
end
103103
end
104+
105+
def signup_page_enabled?(api)
106+
api.config.auth_enabled?(@organization) && @organization.whitelisted_email_domains.present?
107+
end
104108
end
105109
end

spec/factories/organizations.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
auth_username_password_enabled true
3333
end
3434

35+
factory :organization_google_whitelist_empty do
36+
whitelisted_email_domains []
37+
auth_google_enabled true
38+
end
39+
3540
factory :organization_with_users do
3641
after(:create) do |org|
3742
create_account_type_fg('ORGANIZATION USER')
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require 'spec_helper_min'
2+
3+
describe Carto::OauthLoginController do
4+
before(:all) do
5+
@organization = FactoryGirl.create(:organization_google_whitelist_empty)
6+
end
7+
8+
after(:all) do
9+
@organization.destroy
10+
end
11+
12+
it 'does not allow Google signup if whitelisted domains is empty' do
13+
Carto::Oauth::Google::Api.any_instance.stubs(:user).returns(nil)
14+
Carto::Oauth::Google::Config.stubs(:config).returns('client_id' => '11')
15+
Carto::Oauth::Client.any_instance.stubs(:exchange_code_for_token).returns('123')
16+
Carto::OauthLoginController.any_instance.stubs(:valid_authenticity_token?).returns(true)
17+
18+
CartoDB::UserAccountCreator.any_instance.expects(:new).never
19+
get google_oauth_url(user_domain: @organization.name,
20+
code: 'blabla',
21+
state: '{"organization_name": "' + @organization.name + '"}')
22+
response.status.should eq 302
23+
follow_redirect!
24+
request.path.should eq '/login'
25+
end
26+
27+
it 'allows Google signup with whitelisted domains' do
28+
@organization.whitelisted_email_domains = ['*gmail.com']
29+
@organization.save
30+
31+
Carto::Oauth::Google::Api.any_instance.stubs(:user).returns(nil)
32+
Carto::Oauth::Google::Config.stubs(:config).returns('client_id' => '11')
33+
Carto::Oauth::Client.any_instance.stubs(:exchange_code_for_token).returns('123')
34+
Carto::OauthLoginController.any_instance.stubs(:valid_authenticity_token?).returns(true)
35+
36+
CartoDB::UserAccountCreator.any_instance.expects(:valid?).once
37+
get google_oauth_url(user_domain: @organization.name,
38+
code: 'blabla',
39+
state: '{"organization_name": "' + @organization.name + '"}')
40+
response.status.should eq 200
41+
end
42+
end

0 commit comments

Comments
 (0)