Ensure oath callbacks without a nickname work (google)

parent 5801d520
...@@ -86,6 +86,7 @@ module Gitlab ...@@ -86,6 +86,7 @@ module Gitlab
end end
def username def username
return unless auth.info.respond_to?(:nickname)
auth.info.nickname.to_s.force_encoding("utf-8") auth.info.nickname.to_s.force_encoding("utf-8")
end end
......
...@@ -68,5 +68,17 @@ describe Gitlab::OAuth::User do ...@@ -68,5 +68,17 @@ describe Gitlab::OAuth::User do
user = gl_auth.create(auth) user = gl_auth.create(auth)
expect(user.email).to_not be_empty expect(user.email).to_not be_empty
end end
it 'generates a username if non provided (google)' do
info = double(
uid: 'my-uid',
name: 'John',
email: 'john@example.com'
)
auth = double(info: info, provider: 'my-provider')
user = gl_auth.create(auth)
expect(user.username).to eql 'john'
end
end end
end end
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