Skip to content

Commit cb2b888

Browse files
committed
Merge pull request gitlabhq#1365 from tsigo/gitolite_identifier
Update User#identifier to conform to Gitolite 2.x's user pattern
2 parents b44e9a0 + d298274 commit cb2b888

File tree

3 files changed

+44
-27
lines changed

3 files changed

+44
-27
lines changed

app/roles/account.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
module Account
1+
module Account
2+
# Returns a string for use as a Gitolite user identifier
3+
#
4+
# Note that Gitolite 2.x requires the following pattern for users:
5+
#
6+
# ^@?[0-9a-zA-Z][0-9a-zA-Z._\@+-]*$
27
def identifier
3-
email.gsub /[^[:alnum:]]/, "_"
8+
# Replace non-word chars with underscores, then make sure it starts with
9+
# valid chars
10+
email.gsub(/\W/, '_').gsub(/\A([\W\_])+/, '')
411
end
512

613
def is_admin?

spec/factories.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def self.new(type, *args)
2828
email { Faker::Internet.email }
2929
name
3030
password "123456"
31-
password_confirmation "123456"
31+
password_confirmation { password }
3232

3333
trait :admin do
3434
admin true

spec/models/user_spec.rb

+34-24
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,46 @@
3131
it { should respond_to(:private_token) }
3232
end
3333

34-
it "should return valid identifier" do
35-
user = User.new(email: "[email protected]")
36-
user.identifier.should == "test_mail_com"
37-
end
34+
describe '#identifier' do
35+
it "should return valid identifier" do
36+
user = build(:user, email: "[email protected]")
37+
user.identifier.should == "test_mail_com"
38+
end
3839

39-
it "should return identifier without + sign" do
40-
user = User.new(email: "[email protected]")
41-
user.identifier.should == "test_foo_mail_com"
42-
end
40+
it "should return identifier without + sign" do
41+
user = build(:user, email: "[email protected]")
42+
user.identifier.should == "test_foo_mail_com"
43+
end
4344

44-
it "should execute callback when force_random_password specified" do
45-
user = User.new(email: "test@mail.com", force_random_password: true)
46-
user.should_receive(:generate_password)
47-
user.save
45+
it "should conform to Gitolite's required identifier pattern" do
46+
user = build(:user, email: "_test@example.com")
47+
user.identifier.should == 'test_example_com'
48+
end
4849
end
4950

50-
it "should not generate password by default" do
51-
user = Factory(:user, password: 'abcdefg', password_confirmation: 'abcdefg')
52-
user.password.should == 'abcdefg'
53-
end
51+
describe '#generate_password' do
52+
it "should execute callback when force_random_password specified" do
53+
user = build(:user, force_random_password: true)
54+
user.should_receive(:generate_password)
55+
user.save
56+
end
57+
58+
it "should not generate password by default" do
59+
user = create(:user, password: 'abcdefg')
60+
user.password.should == 'abcdefg'
61+
end
5462

55-
it "should generate password when forcing random password" do
56-
Devise.stub(:friendly_token).and_return('123456789')
57-
user = User.create(email: "[email protected]", force_random_password: true)
58-
user.password.should == user.password_confirmation
59-
user.password.should == '12345678'
63+
it "should generate password when forcing random password" do
64+
Devise.stub(:friendly_token).and_return('123456789')
65+
user = create(:user, password: 'abcdefg', force_random_password: true)
66+
user.password.should == '12345678'
67+
end
6068
end
6169

62-
it "should have authentication token" do
63-
user = Factory(:user)
64-
user.authentication_token.should_not == ""
70+
describe 'authentication token' do
71+
it "should have authentication token" do
72+
user = Factory(:user)
73+
user.authentication_token.should_not be_blank
74+
end
6575
end
6676
end

0 commit comments

Comments
 (0)