Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-03-31 12:01:53 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-03-31 12:01:53 +0300
commita47a6d6fd56f92497b164d45ff9b53023202c4b1 (patch)
treefdbfbee5e51865b3a43749dbbdf0d03047001ed7 /spec
parent616d6dc767ba33148a11768f3d73504368897ee9 (diff)
Add latest changes from gitlab-org/gitlab@15-10-stable-ee
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/auth/o_auth/user_spec.rb81
1 files changed, 50 insertions, 31 deletions
diff --git a/spec/lib/gitlab/auth/o_auth/user_spec.rb b/spec/lib/gitlab/auth/o_auth/user_spec.rb
index 8a86b306604..78e0df91103 100644
--- a/spec/lib/gitlab/auth/o_auth/user_spec.rb
+++ b/spec/lib/gitlab/auth/o_auth/user_spec.rb
@@ -320,6 +320,38 @@ RSpec.describe Gitlab::Auth::OAuth::User, feature_category: :system_access do
end
include_examples "to verify compliance with allow_single_sign_on"
+
+ context 'and other providers' do
+ context 'when sync_name is disabled' do
+ before do
+ stub_ldap_config(sync_name: false)
+ end
+
+ let!(:existing_user) { create(:omniauth_user, name: 'John Swift', email: 'john@example.com', extern_uid: dn, provider: 'twitter', username: 'john') }
+
+ it "updates the gl_user name" do
+ oauth_user.save # rubocop:disable Rails/SaveBang
+
+ expect(gl_user).to be_valid
+ expect(gl_user.name).to eql 'John'
+ end
+ end
+
+ context 'when sync_name is enabled' do
+ before do
+ stub_ldap_config(sync_name: true)
+ end
+
+ let!(:existing_user) { create(:omniauth_user, name: 'John Swift', email: 'john@example.com', extern_uid: dn, provider: 'twitter', username: 'john') }
+
+ it "updates the gl_user name" do
+ oauth_user.save # rubocop:disable Rails/SaveBang
+
+ expect(gl_user).to be_valid
+ expect(gl_user.name).to eql 'John'
+ end
+ end
+ end
end
context "with auto_link_ldap_user enabled" do
@@ -418,54 +450,41 @@ RSpec.describe Gitlab::Auth::OAuth::User, feature_category: :system_access do
end
context "and LDAP user has an account already" do
+ let(:provider) { 'ldapmain' }
+
+ before do
+ allow(Gitlab::Auth::Ldap::Person).to receive(:find_by_uid).and_return(ldap_user)
+ stub_omniauth_config(sync_profile_attributes: true)
+ allow(Gitlab.config.ldap).to receive(:enabled).and_return(true)
+ end
+
context 'when sync_name is disabled' do
before do
- allow(Gitlab.config.ldap).to receive(:enabled).and_return(true)
- allow(Gitlab.config.ldap).to receive(:sync_name).and_return(false)
+ stub_ldap_config(sync_name: false)
end
- let!(:existing_user) { create(:omniauth_user, name: 'John Doe', email: 'john@example.com', extern_uid: dn, provider: 'ldapmain', username: 'john') }
-
- it "adds the omniauth identity to the LDAP account" do
- allow(Gitlab::Auth::Ldap::Person).to receive(:find_by_uid).and_return(ldap_user)
+ let!(:existing_user) { create(:omniauth_user, name: 'John Deo', email: 'john@example.com', extern_uid: dn, provider: 'ldapmain', username: 'john') }
+ it "does not update the user name" do
oauth_user.save # rubocop:disable Rails/SaveBang
expect(gl_user).to be_valid
- expect(gl_user.username).to eql 'john'
- expect(gl_user.name).to eql 'John Doe'
- expect(gl_user.email).to eql 'john@example.com'
- expect(gl_user.identities.length).to be 2
- identities_as_hash = gl_user.identities.map { |id| { provider: id.provider, extern_uid: id.extern_uid } }
- expect(identities_as_hash).to match_array(
- [
- { provider: 'ldapmain', extern_uid: dn },
- { provider: 'twitter', extern_uid: uid }
- ]
- )
+ expect(gl_user.name).to eql 'John Deo'
end
end
context 'when sync_name is enabled' do
- let!(:existing_user) { create(:omniauth_user, name: 'John Swift', email: 'john@example.com', extern_uid: dn, provider: 'ldapmain', username: 'john') }
+ before do
+ stub_ldap_config(sync_name: true)
+ end
- it "adds the omniauth identity to the LDAP account" do
- allow(Gitlab::Auth::Ldap::Person).to receive(:find_by_uid).and_return(ldap_user)
+ let!(:existing_user) { create(:omniauth_user, name: 'John Swift', email: 'john@example.com', extern_uid: dn, provider: 'ldapmain', username: 'john') }
+ it "updates the user name" do
oauth_user.save # rubocop:disable Rails/SaveBang
expect(gl_user).to be_valid
- expect(gl_user.username).to eql 'john'
- expect(gl_user.name).to eql 'John Swift'
- expect(gl_user.email).to eql 'john@example.com'
- expect(gl_user.identities.length).to be 2
- identities_as_hash = gl_user.identities.map { |id| { provider: id.provider, extern_uid: id.extern_uid } }
- expect(identities_as_hash).to match_array(
- [
- { provider: 'ldapmain', extern_uid: dn },
- { provider: 'twitter', extern_uid: uid }
- ]
- )
+ expect(gl_user.name).to eql 'John'
end
end
end