BigW Consortium Gitlab

auth_spec.rb 1.58 KB
Newer Older
1 2
require 'spec_helper'

Douwe Maan committed
3
describe Gitlab::Auth, lib: true do
4 5
  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
      password = 'wrong'
30
      expect( gl_auth.find(username, password) ).not_to eql user
31 32
    end

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

    context "with ldap enabled" do
39 40 41
      before do
        allow(Gitlab::LDAP::Config).to receive(:enabled?).and_return(true)
      end
42 43

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

        gl_auth.find(username, password)
      end

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

        gl_auth.find('ldap_user', 'password')
      end
    end
55 56
  end
end