2016-01-06 02:38:52 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-10-31 05:52:44 -04:00
|
|
|
describe Identity do
|
2016-01-06 02:38:52 -05:00
|
|
|
describe 'relations' do
|
|
|
|
it { is_expected.to belong_to(:user) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'fields' do
|
|
|
|
it { is_expected.to respond_to(:provider) }
|
|
|
|
it { is_expected.to respond_to(:extern_uid) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#is_ldap?' do
|
|
|
|
let(:ldap_identity) { create(:identity, provider: 'ldapmain') }
|
|
|
|
let(:other_identity) { create(:identity, provider: 'twitter') }
|
|
|
|
|
|
|
|
it 'returns true if it is a ldap identity' do
|
2016-01-12 09:29:10 -05:00
|
|
|
expect(ldap_identity.ldap?).to be_truthy
|
2016-01-06 02:38:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if it is not a ldap identity' do
|
2016-01-12 09:29:10 -05:00
|
|
|
expect(other_identity.ldap?).to be_falsey
|
2016-01-06 02:38:52 -05:00
|
|
|
end
|
|
|
|
end
|
2017-10-31 05:52:44 -04:00
|
|
|
|
|
|
|
describe '.with_extern_uid' do
|
|
|
|
context 'LDAP identity' do
|
|
|
|
let!(:ldap_identity) { create(:identity, provider: 'ldapmain', extern_uid: 'uid=john smith,ou=people,dc=example,dc=com') }
|
|
|
|
|
|
|
|
it 'finds the identity when the DN is formatted differently' do
|
|
|
|
identity = described_class.with_extern_uid('ldapmain', 'uid=John Smith, ou=People, dc=example, dc=com').first
|
|
|
|
|
|
|
|
expect(identity).to eq(ldap_identity)
|
|
|
|
end
|
|
|
|
end
|
2017-11-17 09:24:25 -05:00
|
|
|
|
|
|
|
context 'any other provider' do
|
|
|
|
let!(:test_entity) { create(:identity, provider: 'test_provider', extern_uid: 'test_uid') }
|
|
|
|
|
|
|
|
it 'the extern_uid lookup is case insensitive' do
|
|
|
|
identity = described_class.with_extern_uid('test_provider', 'TEST_UID').first
|
|
|
|
|
|
|
|
expect(identity).to eq(test_entity)
|
|
|
|
end
|
|
|
|
end
|
2017-10-31 05:52:44 -04:00
|
|
|
end
|
2016-01-06 02:38:52 -05:00
|
|
|
end
|