From 6840a276d51962cf5c4e1111994cefd9843f16c0 Mon Sep 17 00:00:00 2001 From: Jan-Willem van der Meer Date: Fri, 29 Aug 2014 13:49:01 +0200 Subject: Fix naming convention of LDAP tests --- spec/lib/gitlab/ldap/access_spec.rb | 32 ++++++++++++++++ spec/lib/gitlab/ldap/adapter_spec.rb | 31 +++++++++++++++ spec/lib/gitlab/ldap/ldap_access_spec.rb | 32 ---------------- spec/lib/gitlab/ldap/ldap_adapter_spec.rb | 31 --------------- spec/lib/gitlab/ldap/ldap_user_auth_spec.rb | 58 ----------------------------- spec/lib/gitlab/ldap/user_auth_spec.rb | 58 +++++++++++++++++++++++++++++ 6 files changed, 121 insertions(+), 121 deletions(-) create mode 100644 spec/lib/gitlab/ldap/access_spec.rb create mode 100644 spec/lib/gitlab/ldap/adapter_spec.rb delete mode 100644 spec/lib/gitlab/ldap/ldap_access_spec.rb delete mode 100644 spec/lib/gitlab/ldap/ldap_adapter_spec.rb delete mode 100644 spec/lib/gitlab/ldap/ldap_user_auth_spec.rb create mode 100644 spec/lib/gitlab/ldap/user_auth_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ldap/access_spec.rb b/spec/lib/gitlab/ldap/access_spec.rb new file mode 100644 index 00000000000..d8c107502ba --- /dev/null +++ b/spec/lib/gitlab/ldap/access_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe Gitlab::LDAP::Access do + let(:access) { Gitlab::LDAP::Access.new } + let(:user) { create(:user) } + + describe :allowed? do + subject { access.allowed?(user) } + + context 'when the user cannot be found' do + before { Gitlab::LDAP::Person.stub(find_by_dn: nil) } + + it { should be_false } + end + + context 'when the user is found' do + before { Gitlab::LDAP::Person.stub(find_by_dn: :ldap_user) } + + context 'and the Active Directory disabled flag is set' do + before { Gitlab::LDAP::Person.stub(active_directory_disabled?: true) } + + it { should be_false } + end + + context 'and the Active Directory disabled flag is not set' do + before { Gitlab::LDAP::Person.stub(active_directory_disabled?: false) } + + it { should be_true } + end + end + end +end diff --git a/spec/lib/gitlab/ldap/adapter_spec.rb b/spec/lib/gitlab/ldap/adapter_spec.rb new file mode 100644 index 00000000000..c3f07334431 --- /dev/null +++ b/spec/lib/gitlab/ldap/adapter_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe Gitlab::LDAP::Adapter do + let(:adapter) { Gitlab::LDAP::Adapter.new } + + describe :dn_matches_filter? do + let(:ldap) { double(:ldap) } + subject { adapter.dn_matches_filter?(:dn, :filter) } + before { adapter.stub(ldap: ldap) } + + context "when the search is successful" do + context "and the result is non-empty" do + before { ldap.stub(search: [:foo]) } + + it { should be_true } + end + + context "and the result is empty" do + before { ldap.stub(search: []) } + + it { should be_false } + end + end + + context "when the search encounters an error" do + before { ldap.stub(search: nil, get_operation_result: double(code: 1, message: 'some error')) } + + it { should be_false } + end + end +end diff --git a/spec/lib/gitlab/ldap/ldap_access_spec.rb b/spec/lib/gitlab/ldap/ldap_access_spec.rb deleted file mode 100644 index d8c107502ba..00000000000 --- a/spec/lib/gitlab/ldap/ldap_access_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'spec_helper' - -describe Gitlab::LDAP::Access do - let(:access) { Gitlab::LDAP::Access.new } - let(:user) { create(:user) } - - describe :allowed? do - subject { access.allowed?(user) } - - context 'when the user cannot be found' do - before { Gitlab::LDAP::Person.stub(find_by_dn: nil) } - - it { should be_false } - end - - context 'when the user is found' do - before { Gitlab::LDAP::Person.stub(find_by_dn: :ldap_user) } - - context 'and the Active Directory disabled flag is set' do - before { Gitlab::LDAP::Person.stub(active_directory_disabled?: true) } - - it { should be_false } - end - - context 'and the Active Directory disabled flag is not set' do - before { Gitlab::LDAP::Person.stub(active_directory_disabled?: false) } - - it { should be_true } - end - end - end -end diff --git a/spec/lib/gitlab/ldap/ldap_adapter_spec.rb b/spec/lib/gitlab/ldap/ldap_adapter_spec.rb deleted file mode 100644 index c3f07334431..00000000000 --- a/spec/lib/gitlab/ldap/ldap_adapter_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'spec_helper' - -describe Gitlab::LDAP::Adapter do - let(:adapter) { Gitlab::LDAP::Adapter.new } - - describe :dn_matches_filter? do - let(:ldap) { double(:ldap) } - subject { adapter.dn_matches_filter?(:dn, :filter) } - before { adapter.stub(ldap: ldap) } - - context "when the search is successful" do - context "and the result is non-empty" do - before { ldap.stub(search: [:foo]) } - - it { should be_true } - end - - context "and the result is empty" do - before { ldap.stub(search: []) } - - it { should be_false } - end - end - - context "when the search encounters an error" do - before { ldap.stub(search: nil, get_operation_result: double(code: 1, message: 'some error')) } - - it { should be_false } - end - end -end diff --git a/spec/lib/gitlab/ldap/ldap_user_auth_spec.rb b/spec/lib/gitlab/ldap/ldap_user_auth_spec.rb deleted file mode 100644 index 501642dca79..00000000000 --- a/spec/lib/gitlab/ldap/ldap_user_auth_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -require 'spec_helper' - -describe Gitlab::LDAP 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 update credentials by username if missing uid and Gitlab.config.ldap.allow_username_or_email_login is true" do - user = double('User') - value = Gitlab.config.ldap.allow_username_or_email_login - Gitlab.config.ldap['allow_username_or_email_login'] = true - 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_receive :update_attributes - gl_auth.find_or_create(@auth) - Gitlab.config.ldap['allow_username_or_email_login'] = value - 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 diff --git a/spec/lib/gitlab/ldap/user_auth_spec.rb b/spec/lib/gitlab/ldap/user_auth_spec.rb new file mode 100644 index 00000000000..501642dca79 --- /dev/null +++ b/spec/lib/gitlab/ldap/user_auth_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' + +describe Gitlab::LDAP 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 update credentials by username if missing uid and Gitlab.config.ldap.allow_username_or_email_login is true" do + user = double('User') + value = Gitlab.config.ldap.allow_username_or_email_login + Gitlab.config.ldap['allow_username_or_email_login'] = true + 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_receive :update_attributes + gl_auth.find_or_create(@auth) + Gitlab.config.ldap['allow_username_or_email_login'] = value + 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 -- cgit v1.2.1