Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/auth/o_auth/auth_hash_spec.rb')
-rw-r--r--spec/lib/gitlab/auth/o_auth/auth_hash_spec.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/lib/gitlab/auth/o_auth/auth_hash_spec.rb b/spec/lib/gitlab/auth/o_auth/auth_hash_spec.rb
index 69068883096..a044094179c 100644
--- a/spec/lib/gitlab/auth/o_auth/auth_hash_spec.rb
+++ b/spec/lib/gitlab/auth/o_auth/auth_hash_spec.rb
@@ -14,6 +14,7 @@ RSpec.describe Gitlab::Auth::OAuth::AuthHash do
)
end
+ let(:provider_config) { { 'args' => { 'gitlab_username_claim' => 'first_name' } } }
let(:uid_raw) do
+"CN=Onur K\xC3\xBC\xC3\xA7\xC3\xBCk,OU=Test,DC=example,DC=net"
end
@@ -35,6 +36,7 @@ RSpec.describe Gitlab::Auth::OAuth::AuthHash do
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(:first_name_utf8) { first_name_ascii.force_encoding(Encoding::UTF_8) }
let(:info_hash) do
{
@@ -91,6 +93,34 @@ RSpec.describe Gitlab::Auth::OAuth::AuthHash do
end
end
+ context 'custom username field provided' do
+ before do
+ allow(Gitlab::Auth::OAuth::Provider).to receive(:config_for).and_return(provider_config)
+ end
+
+ it 'uses the custom field for the username' do
+ expect(auth_hash.username).to eql first_name_utf8
+ end
+
+ it 'uses the default claim for the username when the custom claim is not found' do
+ provider_config['args']['gitlab_username_claim'] = 'nonexistent'
+
+ expect(auth_hash.username).to eql nickname_utf8
+ end
+
+ it 'uses the default claim for the username when the custom claim is empty' do
+ info_hash[:first_name] = ''
+
+ expect(auth_hash.username).to eql nickname_utf8
+ end
+
+ it 'uses the default claim for the username when the custom claim is nil' do
+ info_hash[:first_name] = nil
+
+ expect(auth_hash.username).to eql nickname_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