forked from gitlabhq/gitlabhq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'improve-reset-tokens' into 'master'
Explain reset token expiration in emails Update the new user emails to tell new users when their password reset token expires and provide a link to get a new one. See #1921. This MR adds new text to the emails: ```html This link is valid for X days. After it expires, you can <a href='new_user_password_url'>request a new one</a> ``` It will be more difficult to add the same link to the error message that's displayed when a user tries to reset his password with an expired token. Currently, we don't know why the password change fails, we just show the Devise error messages on the form. See merge request !1803
- Loading branch information
Showing
8 changed files
with
119 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'spec_helper' | ||
|
||
describe EmailsHelper do | ||
describe 'password_reset_token_valid_time' do | ||
def validate_time_string(time_limit, expected_string) | ||
Devise.reset_password_within = time_limit | ||
expect(password_reset_token_valid_time).to eq(expected_string) | ||
end | ||
|
||
context 'when time limit is less than 2 hours' do | ||
it 'should display the time in hours using a singular unit' do | ||
validate_time_string(1.hour, '1 hour') | ||
end | ||
end | ||
|
||
context 'when time limit is 2 or more hours' do | ||
it 'should display the time in hours using a plural unit' do | ||
validate_time_string(2.hours, '2 hours') | ||
end | ||
end | ||
|
||
context 'when time limit contains fractions of an hour' do | ||
it 'should round down to the nearest hour' do | ||
validate_time_string(96.minutes, '1 hour') | ||
end | ||
end | ||
|
||
context 'when time limit is 24 or more hours' do | ||
it 'should display the time in days using a singular unit' do | ||
validate_time_string(24.hours, '1 day') | ||
end | ||
end | ||
|
||
context 'when time limit is 2 or more days' do | ||
it 'should display the time in days using a plural unit' do | ||
validate_time_string(2.days, '2 days') | ||
end | ||
end | ||
|
||
context 'when time limit contains fractions of a day' do | ||
it 'should round down to the nearest day' do | ||
validate_time_string(57.hours, '2 days') | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
include EmailSpec::Matchers | ||
include RepoHelpers | ||
|
||
new_user_address = '[email protected]' | ||
|
||
let(:gitlab_sender_display_name) { Gitlab.config.gitlab.email_display_name } | ||
let(:gitlab_sender) { Gitlab.config.gitlab.email_from } | ||
let(:gitlab_sender_reply_to) { Gitlab.config.gitlab.email_reply_to } | ||
|
@@ -55,28 +57,35 @@ | |
end | ||
end | ||
|
||
describe 'for new users, the email' do | ||
let(:example_site_path) { root_path } | ||
let(:new_user) { create(:user, email: '[email protected]', created_by_id: 1) } | ||
|
||
token = 'kETLwRaayvigPq_x3SNM' | ||
|
||
subject { Notify.new_user_email(new_user.id, token) } | ||
|
||
it_behaves_like 'an email sent from GitLab' | ||
|
||
shared_examples 'a new user email' do |user_email, site_path| | ||
it 'is sent to the new user' do | ||
is_expected.to deliver_to new_user.email | ||
is_expected.to deliver_to user_email | ||
end | ||
|
||
it 'has the correct subject' do | ||
is_expected.to have_subject /^Account was created for you$/i | ||
end | ||
|
||
it 'contains the new user\'s login name' do | ||
is_expected.to have_body_text /#{new_user.email}/ | ||
is_expected.to have_body_text /#{user_email}/ | ||
end | ||
|
||
it 'includes a link to the site' do | ||
is_expected.to have_body_text /#{site_path}/ | ||
end | ||
end | ||
|
||
describe 'for new users, the email' do | ||
let(:example_site_path) { root_path } | ||
let(:new_user) { create(:user, email: new_user_address, created_by_id: 1) } | ||
|
||
token = 'kETLwRaayvigPq_x3SNM' | ||
|
||
subject { Notify.new_user_email(new_user.id, token) } | ||
|
||
it_behaves_like 'an email sent from GitLab' | ||
it_behaves_like 'a new user email', new_user_address | ||
|
||
it 'contains the password text' do | ||
is_expected.to have_body_text /Click here to set your password/ | ||
end | ||
|
@@ -88,39 +97,26 @@ | |
) | ||
end | ||
|
||
it 'includes a link to the site' do | ||
is_expected.to have_body_text /#{example_site_path}/ | ||
it 'explains the reset link expiration' do | ||
is_expected.to have_body_text(/This link is valid for \d+ (hours?|days?)/) | ||
is_expected.to have_body_text(new_user_password_url) | ||
is_expected.to have_body_text(/\?user_email=.*%40.*/) | ||
end | ||
end | ||
|
||
|
||
describe 'for users that signed up, the email' do | ||
let(:example_site_path) { root_path } | ||
let(:new_user) { create(:user, email: '[email protected]', password: "securePassword") } | ||
let(:new_user) { create(:user, email: new_user_address, password: "securePassword") } | ||
|
||
subject { Notify.new_user_email(new_user.id) } | ||
|
||
it_behaves_like 'an email sent from GitLab' | ||
|
||
it 'is sent to the new user' do | ||
is_expected.to deliver_to new_user.email | ||
end | ||
|
||
it 'has the correct subject' do | ||
is_expected.to have_subject /^Account was created for you$/i | ||
end | ||
|
||
it 'contains the new user\'s login name' do | ||
is_expected.to have_body_text /#{new_user.email}/ | ||
end | ||
it_behaves_like 'a new user email', new_user_address | ||
|
||
it 'should not contain the new user\'s password' do | ||
is_expected.not_to have_body_text /password/ | ||
end | ||
|
||
it 'includes a link to the site' do | ||
is_expected.to have_body_text /#{example_site_path}/ | ||
end | ||
end | ||
|
||
describe 'user added ssh key' do | ||
|