Skip to content

Commit 1af992a

Browse files
committed
feat: Enable Devise.paranoid mode by default
This will prevent email enumeration. See https://github.com/heartcombo/devise/wiki/How-To:-Using-paranoid-mode,-avoid-user-enumeration-on-registerable Signed-off-by: Thomas von Deyen <thomas@vondeyen.com>
1 parent bd5540c commit 1af992a

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

lib/generators/alchemy/devise/install/templates/devise.rb.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Devise.setup do |config|
9090
# It will change confirmation, password recovery and other workflows
9191
# to behave the same regardless if the e-mail provided was right or wrong.
9292
# Does not affect registerable.
93-
# config.paranoid = true
93+
config.paranoid = true
9494

9595
# By default Devise will store the user in session. You can skip storage for
9696
# particular strategies by setting this option.

spec/features/password_reset_feature_spec.rb

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,39 @@
1717
click_button "Send reset instructions"
1818

1919
expect(page)
20-
.to have_content("You will receive an email with instructions on how to reset your password in a few minutes.")
20+
.to have_content("If your email address exists in our database, you will receive a password recovery link")
2121
end
2222

23-
it "Displays error if email not found." do
24-
visit admin_new_password_path
23+
context "with paranoid mode disabled" do
24+
before do
25+
allow(Devise).to receive(:paranoid).and_return(false)
26+
end
2527

26-
fill_in :user_email, with: "wrong@email.com"
27-
click_button "Send reset instructions"
28+
it "Displays error if email not found." do
29+
visit admin_new_password_path
30+
31+
fill_in :user_email, with: "wrong@email.com"
32+
click_button "Send reset instructions"
33+
34+
expect(page).to have_content("Email not found")
35+
end
36+
end
37+
38+
context "with paranoid mode enabled" do
39+
before do
40+
allow(Devise).to receive(:paranoid).and_return(true)
41+
end
42+
43+
it "Displays notification about reset instructions.", :js do
44+
visit admin_new_password_path
45+
46+
fill_in :user_email, with: "wrong@email.com"
47+
click_button "Send reset instructions"
2848

29-
expect(page).to have_content("Email not found")
49+
expect(page).to have_content(
50+
"If your email address exists in our database, you will receive a password recovery link"
51+
)
52+
end
3053
end
3154

3255
it "User can visit edit password form." do

0 commit comments

Comments
 (0)