summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRobin Bobbitt <ryehle@us.ibm.com>2017-08-01 16:42:46 -0400
committerRobin Bobbitt <ryehle@us.ibm.com>2017-08-02 09:40:49 -0400
commit71951fc38c080579f9270d0c7a80bb3330483886 (patch)
treea81113c6742d74a193fc19d821288f0bc540f5a4 /spec
parent48c51e207e4cba8a69e4ca65cba1e169d384cefa (diff)
downloadgitlab-ce-71951fc38c080579f9270d0c7a80bb3330483886.tar.gz
Uniquify reserved word usernames on OAuth user creation
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/o_auth/user_spec.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/lib/gitlab/o_auth/user_spec.rb b/spec/lib/gitlab/o_auth/user_spec.rb
index 47aa19d5fd9..6c84c4a0c1e 100644
--- a/spec/lib/gitlab/o_auth/user_spec.rb
+++ b/spec/lib/gitlab/o_auth/user_spec.rb
@@ -457,4 +457,34 @@ describe Gitlab::OAuth::User do
end
end
end
+
+ describe 'generating username' do
+ context 'when no collision with existing user' do
+ it 'generates the username with no counter' do
+ expect(gl_user.username).to eq('johngitlab-ETC')
+ end
+ end
+
+ context 'when collision with existing user' do
+ it 'generates the username with a counter' do
+ oauth_user.save
+ oauth_user2 = described_class.new(OmniAuth::AuthHash.new(uid: 'my-uid2', provider: provider, info: { nickname: 'johngitlab-ETC@othermail.com', email: 'john@othermail.com' }))
+
+ expect(oauth_user2.gl_user.username).to eq('johngitlab-ETC1')
+ end
+ end
+
+ context 'when username is a reserved word' do
+ let(:info_hash) do
+ {
+ nickname: 'admin@othermail.com',
+ email: 'admin@othermail.com'
+ }
+ end
+
+ it 'generates the username with a counter' do
+ expect(gl_user.username).to eq('admin1')
+ end
+ end
+ end
end