summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorPatricio Cano <suprnova32@gmail.com>2016-06-06 18:47:49 -0500
committerPatricio Cano <suprnova32@gmail.com>2016-06-06 18:47:49 -0500
commit7038440e342a521807b1e5ffb6d47d4c0b13048d (patch)
treeb22cdf0ac390d0ccec2ddee46ad351d62175a993 /spec/lib
parent740a6ecba07a056fca481622b4fa89939c225987 (diff)
downloadgitlab-ce-7038440e342a521807b1e5ffb6d47d4c0b13048d.tar.gz
Adjust the SAML control flow to allow LDAP identities to be added to an existing SAML user.
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/saml/user_spec.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/spec/lib/gitlab/saml/user_spec.rb b/spec/lib/gitlab/saml/user_spec.rb
index c2a51d9249c..f0a17244ff6 100644
--- a/spec/lib/gitlab/saml/user_spec.rb
+++ b/spec/lib/gitlab/saml/user_spec.rb
@@ -145,6 +145,7 @@ describe Gitlab::Saml::User, lib: true do
allow(ldap_user).to receive(:email) { %w(john@mail.com john2@example.com) }
allow(ldap_user).to receive(:dn) { 'uid=user1,ou=People,dc=example' }
allow(Gitlab::LDAP::Person).to receive(:find_by_uid).and_return(ldap_user)
+ allow(Gitlab::LDAP::Person).to receive(:find_by_dn).and_return(ldap_user)
end
context 'and no account for the LDAP user' do
@@ -177,6 +178,24 @@ describe Gitlab::Saml::User, lib: true do
])
end
end
+
+ context 'user has SAML user, and wants to add their LDAP identity' do
+ it 'adds the LDAP identity to the existing SAML user' do
+ create(:omniauth_user, email: 'john@mail.com', extern_uid: 'uid=user1,ou=People,dc=example', provider: 'saml', username: 'john')
+ local_hash = OmniAuth::AuthHash.new(uid: 'uid=user1,ou=People,dc=example', provider: provider, info: info_hash, extra: { raw_info: OneLogin::RubySaml::Attributes.new({ 'groups' => %w(Developers Freelancers Designers) }) })
+ local_saml_user = described_class.new(local_hash)
+
+ local_saml_user.save
+ local_gl_user = local_saml_user.gl_user
+ expect(local_gl_user).to be_valid
+ expect(local_gl_user.identities.length).to eql 2
+ identities_as_hash = local_gl_user.identities.map { |id| { provider: id.provider, extern_uid: id.extern_uid } }
+ expect(identities_as_hash).to match_array([ { provider: 'ldapmain', extern_uid: 'uid=user1,ou=People,dc=example' },
+ { provider: 'saml', extern_uid: 'uid=user1,ou=People,dc=example' }
+ ])
+ end
+
+ end
end
end
end