2015-09-09 06:51:40 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Gitlab::LDAP::AuthHash do
|
2015-09-09 06:51:40 -04:00
|
|
|
let(:auth_hash) do
|
2017-07-25 13:09:00 -04:00
|
|
|
described_class.new(
|
2015-09-09 06:51:40 -04:00
|
|
|
OmniAuth::AuthHash.new(
|
2017-09-17 21:07:29 -04:00
|
|
|
uid: given_uid,
|
2017-08-15 13:44:37 -04:00
|
|
|
provider: 'ldapmain',
|
2015-09-09 06:51:40 -04:00
|
|
|
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
|
|
|
|
{
|
2015-09-23 10:37:59 -04:00
|
|
|
uid: ['123456'],
|
|
|
|
email: ['johnsmith@example.com'],
|
|
|
|
cn: ['Smith, J.'],
|
|
|
|
fullName: ['John Smith']
|
2015-09-09 06:51:40 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
context "without overridden attributes" do
|
2017-09-17 21:07:29 -04:00
|
|
|
let(:given_uid) { 'uid=John Smith,ou=People,dc=example,dc=com' }
|
|
|
|
|
2015-09-09 06:51:40 -04:00
|
|
|
it "has the correct username" do
|
2017-08-15 13:44:37 -04:00
|
|
|
expect(auth_hash.username).to eq("123456")
|
2015-09-09 06:51:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "has the correct name" do
|
2017-08-15 13:44:37 -04:00
|
|
|
expect(auth_hash.name).to eq("Smith, J.")
|
2015-09-09 06:51:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with overridden attributes" do
|
2017-09-17 21:07:29 -04:00
|
|
|
let(:given_uid) { 'uid=John Smith,ou=People,dc=example,dc=com' }
|
|
|
|
|
2015-09-09 06:51:40 -04:00
|
|
|
let(:attributes) do
|
|
|
|
{
|
2017-02-22 12:46:57 -05:00
|
|
|
'username' => %w(mail email),
|
2015-09-23 10:37:59 -04:00
|
|
|
'name' => 'fullName'
|
2015-09-09 06:51:40 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(Gitlab::LDAP::Config).to receive(:attributes).and_return(attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has the correct username" do
|
2017-08-15 13:44:37 -04:00
|
|
|
expect(auth_hash.username).to eq("johnsmith@example.com")
|
2015-09-09 06:51:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "has the correct name" do
|
2017-08-15 13:44:37 -04:00
|
|
|
expect(auth_hash.name).to eq("John Smith")
|
2015-09-09 06:51:40 -04:00
|
|
|
end
|
|
|
|
end
|
2017-09-17 21:07:29 -04:00
|
|
|
|
|
|
|
describe '#uid' do
|
|
|
|
context 'when there is extraneous (but valid) whitespace' do
|
|
|
|
let(:given_uid) { 'uid =John Smith , ou = People, dc= example,dc =com' }
|
|
|
|
|
|
|
|
it 'removes the extraneous whitespace' do
|
|
|
|
expect(auth_hash.uid).to eq('uid=John Smith,ou=People,dc=example,dc=com')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-09-09 06:51:40 -04:00
|
|
|
end
|