Commit cc66c3fd authored by Rémy Coutable's avatar Rémy Coutable

Don't force the encoding of the OAuth provider in Gitlab::OAuth::AuthHash#provider

Some providers freeze their name (e.g.
https://github.com/zquestz/omniauth-google-oauth2/blob/414c43ef3ffec37d473321f262e80f1e46dda89f/lib/omniauth/strategies/google_oauth2.rb#L1),
so trying to modify the string would fail with a `can't modify frozen
String` exception (see
https://gitlab.com/gitlab-org/gitlab-ce/issues/37845#note_40308148).

In this case, we can just stop trying to force the encoding of the
provider name as they should always be in utf8 by default.
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent d3fb1da1
......@@ -13,7 +13,7 @@ module Gitlab
end
def provider
@provider ||= Gitlab::Utils.force_utf8(auth_hash.provider.to_s)
@provider ||= auth_hash.provider.to_s
end
def name
......
require 'spec_helper'
describe Gitlab::OAuth::AuthHash do
let(:provider) { 'ldap'.freeze }
let(:auth_hash) do
described_class.new(
OmniAuth::AuthHash.new(
provider: provider_ascii,
provider: provider,
uid: uid_ascii,
info: info_hash
)
......@@ -20,7 +21,6 @@ describe Gitlab::OAuth::AuthHash do
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) }
......@@ -28,7 +28,6 @@ describe Gitlab::OAuth::AuthHash do
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) }
......@@ -46,7 +45,7 @@ describe Gitlab::OAuth::AuthHash do
end
context 'defaults' do
it { expect(auth_hash.provider).to eql provider_utf8 }
it { expect(auth_hash.provider).to eq provider }
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 }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment