-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CV2-4595 Validate password strength in check (#1888)
* CV2-4595: validate password strength * CV2-4595: fix tests
- Loading branch information
Showing
15 changed files
with
139 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,7 +190,8 @@ def teardown | |
end | ||
|
||
test "should connect when current user set" do | ||
u = create_user login: 'test', password: '12345678', password_confirmation: '12345678', email: '[email protected]' | ||
p1 = random_complex_password | ||
u = create_user login: 'test', password: p1, password_confirmation: p1, email: '[email protected]' | ||
u.confirm | ||
authenticate_with_user(u) | ||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,9 @@ def teardown | |
end | ||
|
||
test "should create user" do | ||
p1 = random_complex_password | ||
assert_difference 'User.count' do | ||
post :create, params: { api_user: { password: '12345678', password_confirmation: '12345678', email: '[email protected]', login: 'test', name: 'Test' } } | ||
post :create, params: { api_user: { password: p1, password_confirmation: p1, email: '[email protected]', login: 'test', name: 'Test' } } | ||
assert_response 401 # needs to confirm before login | ||
end | ||
end | ||
|
@@ -32,67 +33,76 @@ def teardown | |
User.send_user_invitation(members) | ||
end | ||
User.current = Team.current = nil | ||
p1 = random_complex_password | ||
assert_no_difference 'User.count' do | ||
post :create, params: { api_user: { password: '12345678', password_confirmation: '12345678', email: email, login: 'test', name: 'Test' } } | ||
post :create, params: { api_user: { password: p1, password_confirmation: p1, email: email, login: 'test', name: 'Test' } } | ||
assert_response :success | ||
end | ||
end | ||
|
||
test "should create user if confirmed" do | ||
p1 = random_complex_password | ||
User.any_instance.stubs(:confirmation_required?).returns(false) | ||
assert_difference 'User.count' do | ||
post :create, params: { api_user: { password: '12345678', password_confirmation: '12345678', email: '[email protected]', login: 'test', name: 'Test' } } | ||
post :create, params: { api_user: { password: p1, password_confirmation: p1, email: '[email protected]', login: 'test', name: 'Test' } } | ||
assert_response :success | ||
end | ||
User.any_instance.unstub(:confirmation_required?) | ||
end | ||
|
||
test "should not create user if password is missing" do | ||
p1 = random_complex_password | ||
assert_no_difference 'User.count' do | ||
post :create, params: { api_user: { password_confirmation: '12345678', email: '[email protected]', login: 'test', name: 'Test' } } | ||
post :create, params: { api_user: { password_confirmation: p1, email: '[email protected]', login: 'test', name: 'Test' } } | ||
assert_response 400 | ||
end | ||
end | ||
|
||
test "should not create user if password is too short" do | ||
p1 = '1234' | ||
assert_no_difference 'User.count' do | ||
post :create, params: { api_user: { password: '123456', password_confirmation: '123456', email: '[email protected]', login: 'test', name: 'Test' } } | ||
post :create, params: { api_user: { password: p1, password_confirmation: p1, email: '[email protected]', login: 'test', name: 'Test' } } | ||
assert_response 400 | ||
end | ||
end | ||
|
||
test "should not create user if password don't match" do | ||
p1 = random_complex_password | ||
assert_no_difference 'User.count' do | ||
post :create, params: { api_user: { password: '12345678', password_confirmation: '12345677', email: '[email protected]', login: 'test', name: 'Test' } } | ||
post :create, params: { api_user: { password: random_complex_password, password_confirmation: random_complex_password, email: '[email protected]', login: 'test', name: 'Test' } } | ||
assert_response 400 | ||
end | ||
end | ||
|
||
test "should not create user if email is not present" do | ||
p1 = random_complex_password | ||
assert_no_difference 'User.count' do | ||
post :create, params: { api_user: { password: '12345678', password_confirmation: '12345678', email: '', login: 'test', name: 'Test' } } | ||
post :create, params: { api_user: { password: p1, password_confirmation: p1, email: '', login: 'test', name: 'Test' } } | ||
assert_response 400 | ||
end | ||
end | ||
|
||
test "should create user if login is not present" do | ||
p1 = random_complex_password | ||
assert_difference 'User.count' do | ||
post :create, params: { api_user: { password: '12345678', password_confirmation: '12345678', email: '[email protected]', login: '', name: 'Test' } } | ||
post :create, params: { api_user: { password: p1, password_confirmation: p1, email: '[email protected]', login: '', name: 'Test' } } | ||
assert_response 401 # needs to confirm before login | ||
end | ||
end | ||
|
||
test "should not create user if name is not present" do | ||
p1 = random_complex_password | ||
assert_no_difference 'User.count' do | ||
post :create, params: { api_user: { password: '12345678', password_confirmation: '12345678', email: '[email protected]', login: 'test', name: '' } } | ||
post :create, params: { api_user: { password: p1, password_confirmation: p1, email: '[email protected]', login: 'test', name: '' } } | ||
assert_response 400 | ||
end | ||
end | ||
|
||
test "should update only a few attributes" do | ||
u = create_user name: 'Foo', login: 'test', token: 'test', email: '[email protected]', password: '12345678' | ||
p1 = random_complex_password | ||
u = create_user name: 'Foo', login: 'test', token: 'test', email: '[email protected]', password: p1 | ||
authenticate_with_user(u) | ||
post :update, params: { api_user: { name: 'Bar', login: 'bar', token: 'bar', email: '[email protected]', current_password: '12345678' } } | ||
post :update, params: { api_user: { name: 'Bar', login: 'bar', token: 'bar', email: '[email protected]', current_password: p1 } } | ||
assert_response :success | ||
u = u.reload | ||
assert_equal 'Bar', u.name | ||
|
@@ -103,20 +113,23 @@ def teardown | |
end | ||
|
||
test "should not update account if not logged in" do | ||
post :update, params: { api_user: { name: 'Bar', login: 'bar', token: 'bar', email: '[email protected]', current_password: '12345678' } } | ||
p1 = random_complex_password | ||
post :update, params: { api_user: { name: 'Bar', login: 'bar', token: 'bar', email: '[email protected]', current_password: p1 } } | ||
assert_response 401 | ||
end | ||
|
||
test "should not update account" do | ||
u = create_user name: 'Foo', login: 'test', token: 'test', email: '[email protected]', password: '12345678' | ||
p1 = random_complex_password | ||
u = create_user name: 'Foo', login: 'test', token: 'test', email: '[email protected]', password: p1 | ||
authenticate_with_user(u) | ||
post :update, params: { api_user: { name: 'Bar', login: 'bar', token: 'bar', email: '[email protected]', current_password: '12345678', password: '123', password_confirmation: '123' } } | ||
post :update, params: { api_user: { name: 'Bar', login: 'bar', token: 'bar', email: '[email protected]', current_password: p1, password: '123', password_confirmation: '123' } } | ||
assert_response 400 | ||
u = u.reload | ||
end | ||
|
||
test "should destroy account" do | ||
u = create_user name: 'Foo', login: 'test', token: 'test', email: '[email protected]', password: '12345678' | ||
p1 = random_complex_password | ||
u = create_user name: 'Foo', login: 'test', token: 'test', email: '[email protected]', password: p1 | ||
authenticate_with_user(u) | ||
assert_difference 'User.count', -1 do | ||
delete :destroy, params: {} | ||
|
Oops, something went wrong.