-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Front end changes - added a row for the specific email domain sign up - added corresponding locales * Created specific email domain sign up site setting - added specific email domain sign up to site settings in `tenant.rb` * Rspec tests and data migration * external controller tests + rubocop fixes * rubocop fixes * Rspec test fix for tenants controller spec - added the setting SpecificEmailDomainSignUp * rubocop fix * test fixes * Changed Specific Email Domain Sign Up to Allowed Domains - changed all instances of previous name to AllowedDomains * Delete db/data/20240806205559_add_domain_specific_email_signup_to_site_settings.rb * gemfile change * schema change * locale changes --------- Co-authored-by: Ahmad Farhat <[email protected]>
- Loading branch information
1 parent
7d248f2
commit 8ea1848
Showing
11 changed files
with
254 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
db/data/20240812210436_add_allowed_domains_to_site_settings.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddAllowedDomainsToSiteSettings < ActiveRecord::Migration[7.1] | ||
def up | ||
setting = Setting.find_or_create_by(name: 'AllowedDomains') | ||
|
||
SiteSetting.create!(setting:, value: '', provider: 'greenlight') unless SiteSetting.exists?(setting:, provider: 'greenlight') | ||
|
||
Tenant.find_each do |tenant| | ||
SiteSetting.create!(setting:, value: '', provider: tenant.name) unless SiteSetting.exists?(setting:, provider: tenant.name) | ||
end | ||
end | ||
|
||
def down | ||
Tenant.find_each do |tenant| | ||
SiteSetting.find_by(setting: Setting.find_by(name: 'Maintenance'), provider: tenant.name)&.destroy | ||
end | ||
|
||
SiteSetting.find_by(setting: Setting.find_by(name: 'Maintenance'), provider: 'greenlight')&.destroy | ||
|
||
Setting.find_by(name: 'AllowedDomains')&.destroy | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
DataMigrate::Data.define(version: 20240423162700) | ||
DataMigrate::Data.define(version: 20240812210436) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
|
||
require 'rails_helper' | ||
|
||
RSpec.describe ExternalController, type: :controller do | ||
RSpec.describe ExternalController do | ||
let(:fake_setting_getter) { instance_double(SettingGetter) } | ||
|
||
describe '#create_user' do | ||
|
@@ -80,7 +80,7 @@ | |
|
||
expect do | ||
get :create_user, params: { provider: 'openid_connect' } | ||
end.to change(User, :count).by(0) | ||
end.not_to change(User, :count) | ||
end | ||
|
||
it 'looks the user up based on email' do | ||
|
@@ -90,7 +90,7 @@ | |
|
||
expect do | ||
get :create_user, params: { provider: 'openid_connect' } | ||
end.to change(User, :count).by(0) | ||
end.not_to change(User, :count) | ||
end | ||
|
||
context 'redirect' do | ||
|
@@ -212,40 +212,52 @@ | |
email: '[email protected]') | ||
end | ||
|
||
it 'overwrites the saved values with the values from the authentication provider if true' do | ||
allow_any_instance_of(SettingGetter).to receive(:call).and_return(true) | ||
context 'value is true' do | ||
before do | ||
reg_method = instance_double(SettingGetter) | ||
allow(SettingGetter).to receive(:new).with(setting_name: 'ResyncOnLogin', provider: 'greenlight').and_return(reg_method) | ||
allow(reg_method).to receive(:call).and_return(true) | ||
end | ||
|
||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
it 'overwrites the saved values with the values from the authentication provider if true' do | ||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
|
||
get :create_user, params: { provider: 'openid_connect' } | ||
get :create_user, params: { provider: 'openid_connect' } | ||
|
||
user.reload | ||
expect(user.name).to eq(OmniAuth.config.mock_auth[:openid_connect]['info']['name']) | ||
expect(user.email).to eq(OmniAuth.config.mock_auth[:openid_connect]['info']['email']) | ||
end | ||
user.reload | ||
expect(user.name).to eq(OmniAuth.config.mock_auth[:openid_connect]['info']['name']) | ||
expect(user.email).to eq(OmniAuth.config.mock_auth[:openid_connect]['info']['email']) | ||
end | ||
|
||
it 'does not overwrite the saved values with the values from the authentication provider if false' do | ||
allow_any_instance_of(SettingGetter).to receive(:call).and_return(false) | ||
it 'does not overwrite the role even if true' do | ||
allow_any_instance_of(SettingGetter).to receive(:call).and_return(true) | ||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
|
||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
new_role = create(:role) | ||
user.update(role: new_role) | ||
|
||
get :create_user, params: { provider: 'openid_connect' } | ||
get :create_user, params: { provider: 'openid_connect' } | ||
|
||
user.reload | ||
expect(user.name).to eq('Example Name') | ||
expect(user.email).to eq('[email protected]') | ||
expect(user.reload.role).to eq(new_role) | ||
end | ||
end | ||
|
||
it 'does not overwrite the role even if true' do | ||
allow_any_instance_of(SettingGetter).to receive(:call).and_return(true) | ||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
context 'value is false' do | ||
before do | ||
reg_method = instance_double(SettingGetter) | ||
allow(SettingGetter).to receive(:new).with(setting_name: 'ResyncOnLogin', provider: 'greenlight').and_return(reg_method) | ||
allow(reg_method).to receive(:call).and_return(false) | ||
end | ||
|
||
new_role = create(:role) | ||
user.update(role: new_role) | ||
it 'does not overwrite the saved values with the values from the authentication provider if false' do | ||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
|
||
get :create_user, params: { provider: 'openid_connect' } | ||
get :create_user, params: { provider: 'openid_connect' } | ||
|
||
expect(user.reload.role).to eq(new_role) | ||
user.reload | ||
expect(user.name).to eq('Example Name') | ||
expect(user.email).to eq('[email protected]') | ||
end | ||
end | ||
end | ||
|
||
|
@@ -325,6 +337,79 @@ | |
end | ||
end | ||
|
||
context 'Allowed Domains' do | ||
context 'restricted domain not set' do | ||
before do | ||
site_settings = instance_double(SettingGetter) | ||
allow(SettingGetter).to receive(:new).with(setting_name: 'AllowedDomains', provider: 'greenlight').and_return(site_settings) | ||
allow(site_settings).to receive(:call).and_return('') | ||
end | ||
|
||
it 'creates the user' do | ||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
|
||
expect { get :create_user, params: { provider: 'openid_connect' } }.to change(User, :count).from(0).to(1) | ||
end | ||
end | ||
|
||
context 'restricted domain set to 1 domain' do | ||
before do | ||
site_settings = instance_double(SettingGetter) | ||
allow(SettingGetter).to receive(:new).with(setting_name: 'AllowedDomains', provider: 'greenlight').and_return(site_settings) | ||
allow(site_settings).to receive(:call).and_return('@domain.com') | ||
end | ||
|
||
it 'creates the user if the domain is allowed' do | ||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
request.env['omniauth.auth'][:info][:email] = '[email protected]' | ||
|
||
expect { get :create_user, params: { provider: 'openid_connect' } }.to change(User, :count).from(0).to(1) | ||
end | ||
|
||
it 'does not create if the domain is not allowed' do | ||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
|
||
expect { get :create_user, params: { provider: 'openid_connect' } }.not_to change(User, :count) | ||
end | ||
end | ||
|
||
context 'restricted domain set to multiple domain' do | ||
before do | ||
site_settings = instance_double(SettingGetter) | ||
allow(SettingGetter).to receive(:new).with(setting_name: 'AllowedDomains', provider: 'greenlight').and_return(site_settings) | ||
allow(site_settings).to receive(:call).and_return('@example.com,@test.com,@domain.com') | ||
end | ||
|
||
it 'creates the user if the domain is allowed 1' do | ||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
request.env['omniauth.auth'][:info][:email] = '[email protected]' | ||
|
||
expect { get :create_user, params: { provider: 'openid_connect' } }.to change(User, :count).from(0).to(1) | ||
end | ||
|
||
it 'creates the user if the domain is allowed 2' do | ||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
request.env['omniauth.auth'][:info][:email] = '[email protected]' | ||
|
||
expect { get :create_user, params: { provider: 'openid_connect' } }.to change(User, :count).from(0).to(1) | ||
end | ||
|
||
it 'creates the user if the domain is allowed 3' do | ||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
request.env['omniauth.auth'][:info][:email] = '[email protected]' | ||
|
||
expect { get :create_user, params: { provider: 'openid_connect' } }.to change(User, :count).from(0).to(1) | ||
end | ||
|
||
it 'does not create if the domain is not allowed' do | ||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
request.env['omniauth.auth'][:info][:email] = '[email protected]' | ||
|
||
expect { get :create_user, params: { provider: 'openid_connect' } }.not_to change(User, :count) | ||
end | ||
end | ||
end | ||
|
||
context 'Role mapping' do | ||
let!(:role1) { create(:role, name: 'role1') } | ||
|
||
|
Oops, something went wrong.