diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-08-30 11:16:45 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-08-30 11:16:45 +0400 |
commit | 14f5199cdcd9a84bdd273b24ba8d8f2eb9f60c23 (patch) | |
tree | c3b92e307179a44b198b9279a17d5091777ae8ba /spec/lib/gitlab/ldap/user_spec.rb | |
parent | cb71b26353b4b3d927e20678b6f26c50c7d7b7c2 (diff) | |
parent | 0d5ae2802e887dcd95fe537a59450a2c0f548382 (diff) |
Merge branch 'feature-ldap-tests' into 'master'
Feature ldap tests
Move specs to proper places. Relates to #154
This is already mergeable, will continue in a new branch for additions & refactorings.
See merge request !1053
Diffstat (limited to 'spec/lib/gitlab/ldap/user_spec.rb')
-rw-r--r-- | spec/lib/gitlab/ldap/user_spec.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ldap/user_spec.rb b/spec/lib/gitlab/ldap/user_spec.rb new file mode 100644 index 00000000000..de5717417f1 --- /dev/null +++ b/spec/lib/gitlab/ldap/user_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe Gitlab::LDAP::User do + let(:gl_auth) { Gitlab::LDAP::User } + + before do + Gitlab.config.stub(omniauth: {}) + + @info = double( + uid: '12djsak321', + name: 'John', + email: 'john@mail.com', + nickname: 'john' + ) + end + + describe :find_for_ldap_auth do + before do + @auth = double( + uid: '12djsak321', + info: @info, + provider: 'ldap' + ) + end + + it "should update credentials by email if missing uid" do + user = double('User') + User.stub find_by_extern_uid_and_provider: nil + User.stub(:find_by).with(hash_including(email: anything())) { user } + user.should_receive :update_attributes + gl_auth.find_or_create(@auth) + end + + it "should not update credentials by username if missing uid and Gitlab.config.ldap.allow_username_or_email_login is false" do + user = double('User') + value = Gitlab.config.ldap.allow_username_or_email_login + Gitlab.config.ldap['allow_username_or_email_login'] = false + User.stub find_by_extern_uid_and_provider: nil + User.stub(:find_by).with(hash_including(email: anything())) { nil } + User.stub(:find_by).with(hash_including(username: anything())) { user } + user.should_not_receive :update_attributes + gl_auth.find_or_create(@auth) + Gitlab.config.ldap['allow_username_or_email_login'] = value + end + end +end |