debian-mirror-gitlab/spec/lib/gitlab/o_auth/auth_hash_spec.rb

113 lines
3.4 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe Gitlab::OAuth::AuthHash do
2015-04-26 12:48:37 +05:30
let(:auth_hash) do
2017-09-10 17:25:29 +05:30
described_class.new(
2015-09-25 12:07:36 +05:30
OmniAuth::AuthHash.new(
2015-09-11 14:41:01 +05:30
provider: provider_ascii,
uid: uid_ascii,
2015-09-25 12:07:36 +05:30
info: info_hash
)
2015-09-11 14:41:01 +05:30
)
end
let(:uid_raw) do
"CN=Onur K\xC3\xBC\xC3\xA7\xC3\xBCk,OU=Test,DC=example,DC=net"
end
2015-12-23 02:04:40 +05:30
let(:email_raw) { "onur.k\xC3\xBC\xC3\xA7\xC3\xBCk_ABC-123@example.net" }
2015-09-11 14:41:01 +05:30
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) }
let(:info_hash) do
2015-04-26 12:48:37 +05:30
{
2015-09-11 14:41:01 +05:30
email: email_ascii,
first_name: first_name_ascii,
last_name: last_name_ascii,
name: name_ascii,
nickname: nickname_ascii,
uid: uid_ascii
2015-04-26 12:48:37 +05:30
}
2015-09-11 14:41:01 +05:30
end
2015-04-26 12:48:37 +05:30
2015-09-11 14:41:01 +05:30
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 }
it { expect(auth_hash.password).not_to be_empty }
2015-04-26 12:48:37 +05:30
end
2015-09-11 14:41:01 +05:30
context 'email not provided' do
2017-09-10 17:25:29 +05:30
before do
info_hash.delete(:email)
end
2015-09-11 14:41:01 +05:30
it 'generates a temp email' do
2015-04-26 12:48:37 +05:30
expect( auth_hash.email).to start_with('temp-email-for-oauth')
end
end
2015-09-11 14:41:01 +05:30
context 'username not provided' do
2017-09-10 17:25:29 +05:30
before do
info_hash.delete(:nickname)
end
2015-04-26 12:48:37 +05:30
2015-09-11 14:41:01 +05:30
it 'takes the first part of the email as username' do
2015-12-23 02:04:40 +05:30
expect(auth_hash.username).to eql 'onur.kucuk_ABC-123'
2015-04-26 12:48:37 +05:30
end
end
2015-09-11 14:41:01 +05:30
context 'name not provided' do
2017-09-10 17:25:29 +05:30
before do
info_hash.delete(:name)
end
2015-04-26 12:48:37 +05:30
2015-09-11 14:41:01 +05:30
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
expect(auth_hash.uid.encoding).to eql Encoding::UTF_8
end
it 'forces utf8 encoding on provider' do
expect(auth_hash.provider.encoding).to eql Encoding::UTF_8
end
it 'forces utf8 encoding on name' do
expect(auth_hash.name.encoding).to eql Encoding::UTF_8
end
it 'forces utf8 encoding on username' do
expect(auth_hash.username.encoding).to eql Encoding::UTF_8
end
it 'forces utf8 encoding on email' do
expect(auth_hash.email.encoding).to eql Encoding::UTF_8
end
it 'forces utf8 encoding on password' do
expect(auth_hash.password.encoding).to eql Encoding::UTF_8
2015-04-26 12:48:37 +05:30
end
end
2015-09-11 14:41:01 +05:30
end