2015-09-25 12:07:36 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
describe Gitlab::LDAP::AuthHash, lib: true do
|
2015-09-25 12:07:36 +05:30
|
|
|
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
|
|
|
|
{
|
|
|
|
uid: ['123456'],
|
|
|
|
email: ['johnsmith@example.com'],
|
|
|
|
cn: ['Smith, J.'],
|
|
|
|
fullName: ['John Smith']
|
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
2017-08-17 22:00:37 +05:30
|
|
|
'username' => %w(mail email),
|
2015-09-25 12:07:36 +05:30
|
|
|
'name' => 'fullName'
|
|
|
|
}
|
|
|
|
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
|