2014-10-10 06:03:32 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:36 -05:00
|
|
|
describe Gitlab::OAuth::AuthHash, lib: true do
|
2014-10-10 06:03:32 -04:00
|
|
|
let(:auth_hash) do
|
2015-05-02 17:43:46 -04:00
|
|
|
Gitlab::OAuth::AuthHash.new(
|
2015-09-08 05:58:48 -04:00
|
|
|
OmniAuth::AuthHash.new(
|
2015-05-02 17:43:46 -04:00
|
|
|
provider: provider_ascii,
|
|
|
|
uid: uid_ascii,
|
2015-09-08 05:58:48 -04:00
|
|
|
info: info_hash
|
|
|
|
)
|
2015-05-02 17:43:46 -04:00
|
|
|
)
|
2014-10-10 06:03:32 -04:00
|
|
|
end
|
2015-05-02 17:43:46 -04:00
|
|
|
|
2015-06-22 16:00:54 -04:00
|
|
|
let(:uid_raw) do
|
2015-05-02 17:43:46 -04:00
|
|
|
"CN=Onur K\xC3\xBC\xC3\xA7\xC3\xBCk,OU=Test,DC=example,DC=net"
|
2015-06-22 16:00:54 -04:00
|
|
|
end
|
2015-05-14 11:46:48 -04:00
|
|
|
let(:email_raw) { "onur.k\xC3\xBC\xC3\xA7\xC3\xBCk_ABC-123@example.net" }
|
2015-05-02 17:43:46 -04:00
|
|
|
let(:nickname_raw) { "ok\xC3\xBC\xC3\xA7\xC3\xBCk" }
|
|
|
|
let(:first_name_raw) { 'Onur' }
|
|
|
|
let(:last_name_raw) { "K\xC3\xBC\xC3\xA7\xC3\xBCk" }
|
|
|
|
let(:name_raw) { "Onur K\xC3\xBC\xC3\xA7\xC3\xBCk" }
|
|
|
|
|
|
|
|
let(:provider_ascii) { 'ldap'.force_encoding(Encoding::ASCII_8BIT) }
|
|
|
|
let(:uid_ascii) { uid_raw.force_encoding(Encoding::ASCII_8BIT) }
|
|
|
|
let(:email_ascii) { email_raw.force_encoding(Encoding::ASCII_8BIT) }
|
|
|
|
let(:nickname_ascii) { nickname_raw.force_encoding(Encoding::ASCII_8BIT) }
|
|
|
|
let(:first_name_ascii) { first_name_raw.force_encoding(Encoding::ASCII_8BIT) }
|
|
|
|
let(:last_name_ascii) { last_name_raw.force_encoding(Encoding::ASCII_8BIT) }
|
|
|
|
let(:name_ascii) { name_raw.force_encoding(Encoding::ASCII_8BIT) }
|
|
|
|
|
|
|
|
let(:provider_utf8) { provider_ascii.force_encoding(Encoding::UTF_8) }
|
|
|
|
let(:uid_utf8) { uid_ascii.force_encoding(Encoding::UTF_8) }
|
|
|
|
let(:email_utf8) { email_ascii.force_encoding(Encoding::UTF_8) }
|
|
|
|
let(:nickname_utf8) { nickname_ascii.force_encoding(Encoding::UTF_8) }
|
|
|
|
let(:name_utf8) { name_ascii.force_encoding(Encoding::UTF_8) }
|
|
|
|
|
2015-06-22 16:00:54 -04:00
|
|
|
let(:info_hash) do
|
2014-10-10 06:03:32 -04:00
|
|
|
{
|
2015-06-22 16:00:54 -04:00
|
|
|
email: email_ascii,
|
2015-05-02 17:43:46 -04:00
|
|
|
first_name: first_name_ascii,
|
2015-06-22 16:00:54 -04:00
|
|
|
last_name: last_name_ascii,
|
|
|
|
name: name_ascii,
|
|
|
|
nickname: nickname_ascii,
|
|
|
|
uid: uid_ascii
|
2014-10-10 06:03:32 -04:00
|
|
|
}
|
2015-06-22 16:00:54 -04:00
|
|
|
end
|
2014-10-10 06:03:32 -04:00
|
|
|
|
2015-05-02 17:43:46 -04:00
|
|
|
context 'defaults' do
|
|
|
|
it { expect(auth_hash.provider).to eql provider_utf8 }
|
|
|
|
it { expect(auth_hash.uid).to eql uid_utf8 }
|
|
|
|
it { expect(auth_hash.email).to eql email_utf8 }
|
|
|
|
it { expect(auth_hash.username).to eql nickname_utf8 }
|
|
|
|
it { expect(auth_hash.name).to eql name_utf8 }
|
2015-06-17 21:30:58 -04:00
|
|
|
it { expect(auth_hash.password).not_to be_empty }
|
2014-10-10 06:03:32 -04:00
|
|
|
end
|
|
|
|
|
2015-05-02 17:43:46 -04:00
|
|
|
context 'email not provided' do
|
2014-10-10 06:03:32 -04:00
|
|
|
before { info_hash.delete(:email) }
|
2015-05-02 17:43:46 -04:00
|
|
|
|
|
|
|
it 'generates a temp email' do
|
2014-10-10 06:03:32 -04:00
|
|
|
expect( auth_hash.email).to start_with('temp-email-for-oauth')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-02 17:43:46 -04:00
|
|
|
context 'username not provided' do
|
2014-10-10 06:03:32 -04:00
|
|
|
before { info_hash.delete(:nickname) }
|
|
|
|
|
2015-05-02 17:43:46 -04:00
|
|
|
it 'takes the first part of the email as username' do
|
2015-05-14 11:46:48 -04:00
|
|
|
expect(auth_hash.username).to eql 'onur.kucuk_ABC-123'
|
2014-10-10 06:03:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-02 17:43:46 -04:00
|
|
|
context 'name not provided' do
|
2014-10-10 06:03:32 -04:00
|
|
|
before { info_hash.delete(:name) }
|
|
|
|
|
2015-05-02 17:43:46 -04:00
|
|
|
it 'concats first and lastname as the name' do
|
|
|
|
expect(auth_hash.name).to eql name_utf8
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'auth_hash constructed with ASCII-8BIT encoding' do
|
|
|
|
it 'forces utf8 encoding on uid' do
|
2015-06-13 18:24:51 -04:00
|
|
|
expect(auth_hash.uid.encoding).to eql Encoding::UTF_8
|
2015-05-02 17:43:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'forces utf8 encoding on provider' do
|
2015-06-13 18:24:51 -04:00
|
|
|
expect(auth_hash.provider.encoding).to eql Encoding::UTF_8
|
2015-05-02 17:43:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'forces utf8 encoding on name' do
|
2015-06-13 18:24:51 -04:00
|
|
|
expect(auth_hash.name.encoding).to eql Encoding::UTF_8
|
2015-05-02 17:43:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'forces utf8 encoding on username' do
|
2015-06-13 18:24:51 -04:00
|
|
|
expect(auth_hash.username.encoding).to eql Encoding::UTF_8
|
2015-05-02 17:43:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'forces utf8 encoding on email' do
|
2015-06-13 18:24:51 -04:00
|
|
|
expect(auth_hash.email.encoding).to eql Encoding::UTF_8
|
2015-05-02 17:43:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'forces utf8 encoding on password' do
|
2015-06-13 18:24:51 -04:00
|
|
|
expect(auth_hash.password.encoding).to eql Encoding::UTF_8
|
2014-10-10 06:03:32 -04:00
|
|
|
end
|
|
|
|
end
|
2015-05-02 17:43:46 -04:00
|
|
|
end
|