debian-mirror-gitlab/spec/features/password_reset_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
2.2 KiB
Ruby
Raw Permalink Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2015-09-11 14:41:01 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'Password reset', feature_category: :system_access do
2015-10-24 18:46:33 +05:30
describe 'throttling' do
it 'sends reset instructions when not previously sent' do
2015-12-23 02:04:40 +05:30
user = create(:user)
forgot_password(user)
2015-09-11 14:41:01 +05:30
2015-12-23 02:04:40 +05:30
expect(page).to have_content(I18n.t('devise.passwords.send_paranoid_instructions'))
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path new_user_session_path, ignore_query: true
2015-12-23 02:04:40 +05:30
expect(user.recently_sent_password_reset?).to be_truthy
2015-10-24 18:46:33 +05:30
end
2015-09-11 14:41:01 +05:30
2015-10-24 18:46:33 +05:30
it 'sends reset instructions when previously sent more than a minute ago' do
user = create(:user)
user.send_reset_password_instructions
user.update_attribute(:reset_password_sent_at, 5.minutes.ago)
2015-09-11 14:41:01 +05:30
2018-03-17 18:26:18 +05:30
expect { forgot_password(user) }.to change { user.reset_password_sent_at }
2015-12-23 02:04:40 +05:30
expect(page).to have_content(I18n.t('devise.passwords.send_paranoid_instructions'))
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path new_user_session_path, ignore_query: true
2015-09-11 14:41:01 +05:30
end
2015-12-23 02:04:40 +05:30
it 'throttles multiple resets in a short timespan' do
2015-10-24 18:46:33 +05:30
user = create(:user)
user.send_reset_password_instructions
2015-12-23 02:04:40 +05:30
# Reload because PG handles datetime less precisely than Ruby/Rails
user.reload
2015-09-11 14:41:01 +05:30
2018-03-17 18:26:18 +05:30
expect { forgot_password(user) }.not_to change { user.reset_password_sent_at }
2015-12-23 02:04:40 +05:30
expect(page).to have_content(I18n.t('devise.passwords.send_paranoid_instructions'))
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path new_user_session_path, ignore_query: true
2015-09-11 14:41:01 +05:30
end
end
2015-10-24 18:46:33 +05:30
2018-03-17 18:26:18 +05:30
describe 'Changing password while logged in' do
it 'updates the password' do
user = create(:user)
token = user.send_reset_password_instructions
sign_in(user)
visit(edit_user_password_path(reset_password_token: token))
2022-04-01 21:47:47 +05:30
fill_in 'New password', with: 'hello1234'
fill_in 'Confirm new password', with: 'hello1234'
2018-03-17 18:26:18 +05:30
click_button 'Change your password'
expect(page).to have_content(I18n.t('devise.passwords.updated_not_active'))
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path new_user_session_path, ignore_query: true
2018-03-17 18:26:18 +05:30
end
end
2015-10-24 18:46:33 +05:30
def forgot_password(user)
2015-12-23 02:04:40 +05:30
visit root_path
2015-10-24 18:46:33 +05:30
click_on 'Forgot your password?'
fill_in 'Email', with: user.email
click_button 'Reset password'
user.reload
end
2015-09-11 14:41:01 +05:30
end