Commit cfa3e79e authored by Jackie Fraser's avatar Jackie Fraser Committed by Mayra Cabrera

Add SAML provider search to UsersFinder

parent d70ea657
......@@ -6,7 +6,8 @@ module EE
override :execute
def execute
by_non_ldap(super)
users = by_non_ldap(super)
by_saml_provider_id(users)
end
def by_non_ldap(users)
......@@ -14,5 +15,12 @@ module EE
users.non_ldap
end
def by_saml_provider_id(users)
saml_provider_id = params[:by_saml_provider_id]
return users unless saml_provider_id
users.limit_to_saml_provider(saml_provider_id)
end
end
end
......@@ -8,7 +8,7 @@ RSpec.describe UsersFinder do
context 'with a normal user' do
context 'with LDAP users' do
let!(:ldap_user) { create(:omniauth_user, provider: 'ldap') }
let_it_be(:ldap_user) { create(:omniauth_user, provider: 'ldap') }
it 'returns ldap users by default' do
users = described_class.new(normal_user).execute
......@@ -22,6 +22,29 @@ RSpec.describe UsersFinder do
expect(users).to contain_exactly(normal_user, blocked_user, omniauth_user, external_user, internal_user, admin_user)
end
end
context 'with SAML users' do
let_it_be(:group) { create(:group) }
let_it_be(:saml_provider) { create(:saml_provider, group: group, enabled: true, enforced_sso: true) }
let_it_be(:saml_user) { create(:user) }
let_it_be(:non_saml_user) { create(:user) }
before do
create(:identity, provider: 'group_saml1', saml_provider_id: saml_provider.id, user: saml_user)
end
it 'returns all users by default' do
users = described_class.new(normal_user).execute
expect(users).to contain_exactly(normal_user, blocked_user, omniauth_user, external_user, internal_user, admin_user, saml_user, non_saml_user)
end
it 'returns only saml users from the provided saml_provider_id' do
users = described_class.new(normal_user, by_saml_provider_id: saml_provider.id).execute
expect(users).to contain_exactly(saml_user)
end
end
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