BigW Consortium Gitlab

auth_hash_spec.rb 1.31 KB
Newer Older
1 2
require 'spec_helper'

Douwe Maan committed
3
describe Gitlab::LDAP::AuthHash, lib: true do
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
  let(:auth_hash) do
    Gitlab::LDAP::AuthHash.new(
      OmniAuth::AuthHash.new(
        uid: '123456', 
        provider: 'ldapmain', 
        info: info,
        extra: {
          raw_info: raw_info
        }
      )
    )
  end

  let(:info) do
    {
      name:     'Smith, J.',
      email:    'johnsmith@example.com',
      nickname: '123456'
    }
  end

  let(:raw_info) do
    {
27 28 29 30
      uid:      ['123456'],
      email:    ['johnsmith@example.com'],
      cn:       ['Smith, J.'],
      fullName: ['John Smith']
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    }
  end

  context "without overridden attributes" do

    it "has the correct username" do
      expect(auth_hash.username).to eq("123456") 
    end

    it "has the correct name" do
      expect(auth_hash.name).to eq("Smith, J.") 
    end
  end

  context "with overridden attributes" do
    let(:attributes) do
      {
48 49
        'username'  => ['mail', 'email'],
        'name'      => 'fullName'
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
      }
    end

    before do
      allow_any_instance_of(Gitlab::LDAP::Config).to receive(:attributes).and_return(attributes)
    end

    it "has the correct username" do
      expect(auth_hash.username).to eq("johnsmith@example.com") 
    end

    it "has the correct name" do
      expect(auth_hash.name).to eq("John Smith") 
    end
  end
end