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/models/user_spec.rb')
-rw-r--r--spec/models/user_spec.rb75
1 files changed, 75 insertions, 0 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 49991dbd2d4..db26b872045 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -98,6 +98,53 @@ describe User, :do_not_mock_admin_mode do
end
describe 'validations' do
+ describe 'password' do
+ let!(:user) { create(:user) }
+
+ before do
+ allow(Devise).to receive(:password_length).and_return(8..128)
+ allow(described_class).to receive(:password_length).and_return(10..130)
+ end
+
+ context 'length' do
+ it { is_expected.to validate_length_of(:password).is_at_least(10).is_at_most(130) }
+ end
+
+ context 'length validator' do
+ context 'for a short password' do
+ before do
+ user.password = user.password_confirmation = 'abc'
+ end
+
+ it 'does not run the default Devise password length validation' do
+ expect(user).to be_invalid
+ expect(user.errors.full_messages.join).not_to include('is too short (minimum is 8 characters)')
+ end
+
+ it 'runs the custom password length validator' do
+ expect(user).to be_invalid
+ expect(user.errors.full_messages.join).to include('is too short (minimum is 10 characters)')
+ end
+ end
+
+ context 'for a long password' do
+ before do
+ user.password = user.password_confirmation = 'a' * 140
+ end
+
+ it 'does not run the default Devise password length validation' do
+ expect(user).to be_invalid
+ expect(user.errors.full_messages.join).not_to include('is too long (maximum is 128 characters)')
+ end
+
+ it 'runs the custom password length validator' do
+ expect(user).to be_invalid
+ expect(user.errors.full_messages.join).to include('is too long (maximum is 130 characters)')
+ end
+ end
+ end
+ end
+
describe 'name' do
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_length_of(:name).is_at_most(128) }
@@ -461,6 +508,34 @@ describe User, :do_not_mock_admin_mode do
end
end
+ describe '.password_length' do
+ let(:password_length) { described_class.password_length }
+
+ it 'is expected to be a Range' do
+ expect(password_length).to be_a(Range)
+ end
+
+ context 'minimum value' do
+ before do
+ stub_application_setting(minimum_password_length: 101)
+ end
+
+ it 'is determined by the current value of `minimum_password_length` attribute of application_setting' do
+ expect(password_length.min).to eq(101)
+ end
+ end
+
+ context 'maximum value' do
+ before do
+ allow(Devise.password_length).to receive(:max).and_return(201)
+ end
+
+ it 'is determined by the current value of `Devise.password_length.max`' do
+ expect(password_length.max).to eq(201)
+ end
+ end
+ end
+
describe '.limit_to_todo_authors' do
context 'when filtering by todo authors' do
let(:user1) { create(:user) }