BigW Consortium Gitlab

auth_spec.rb 1.53 KB
Newer Older
1 2 3 4 5
require 'spec_helper'

describe Gitlab::Auth do
  let(:gl_auth) { Gitlab::Auth.new }

6
  describe :find do
7 8 9 10 11
    let!(:user) do
      create(:user,
        username: username,
        password: password,
        password_confirmation: password)
12
    end
13
    let(:username) { 'John' }     # username isn't lowercase, test this
14
    let(:password) { 'my-secret' }
15

16
    it "should find user by valid login/password" do
17
      expect( gl_auth.find(username, password) ).to eql user
18 19
    end

20 21 22 23 24 25 26 27
    it 'should find user by valid email/password with case-insensitive email' do
      expect(gl_auth.find(user.email.upcase, password)).to eql user
    end

    it 'should find user by valid username/password with case-insensitive username' do
      expect(gl_auth.find(username.upcase, password)).to eql user
    end

28
    it "should not find user with invalid password" do
29 30
      password = 'wrong'
      expect( gl_auth.find(username, password) ).to_not eql user
31 32
    end

33 34 35
    it "should not find user with invalid login" do
      user = 'wrong'
      expect( gl_auth.find(username, password) ).to_not eql user
36
    end
37 38

    context "with ldap enabled" do
39
      before { Gitlab::LDAP::Config.stub(enabled?: true) }
40 41

      it "tries to autheticate with db before ldap" do
42
        expect(Gitlab::LDAP::Authentication).not_to receive(:login)
43 44 45 46 47

        gl_auth.find(username, password)
      end

      it "uses ldap as fallback to for authentication" do
48
        expect(Gitlab::LDAP::Authentication).to receive(:login)
49 50 51 52

        gl_auth.find('ldap_user', 'password')
      end
    end
53 54
  end
end