auth_spec.rb 1.22 KB
Newer Older
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
1 2 3 4 5
require 'spec_helper'

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

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
6
  describe :find do
7 8 9 10 11
    let!(:user) do
      create(:user,
        username: username,
        password: password,
        password_confirmation: password)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
12
    end
13 14
    let(:username) { 'john' }
    let(:password) { 'my-secret' }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
15

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

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
20
    it "should not find user with invalid password" do
21 22
      password = 'wrong'
      expect( gl_auth.find(username, password) ).to_not eql user
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
23 24
    end

25 26 27
    it "should not find user with invalid login" do
      user = 'wrong'
      expect( gl_auth.find(username, password) ).to_not eql user
28
    end
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

    context "with ldap enabled" do
      before { Gitlab.config.ldap['enabled'] = true }
      after  { Gitlab.config.ldap['enabled'] = false }

      it "tries to autheticate with db before ldap" do
        expect(Gitlab::LDAP::User).not_to receive(:authenticate)

        gl_auth.find(username, password)
      end

      it "uses ldap as fallback to for authentication" do
        expect(Gitlab::LDAP::User).to receive(:authenticate)

        gl_auth.find('ldap_user', 'password')
      end
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
46 47
  end
end