clearance 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of clearance might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/NEWS.md +4 -0
- data/lib/clearance/password_strategies/bcrypt.rb +3 -1
- data/lib/clearance/version.rb +1 -1
- data/lib/generators/clearance/install/templates/clearance.rb +1 -1
- data/lib/generators/clearance/install/templates/db/migrate/add_clearance_to_users.rb +2 -2
- data/lib/generators/clearance/install/templates/db/migrate/create_users.rb +1 -5
- data/lib/generators/clearance/specs/templates/factories/clearance.rb +1 -1
- data/lib/generators/clearance/specs/templates/features/clearance/user_signs_out_spec.rb +4 -4
- data/lib/generators/clearance/specs/templates/features/clearance/visitor_resets_password_spec.rb +14 -14
- data/lib/generators/clearance/specs/templates/features/clearance/visitor_signs_in_spec.rb +15 -15
- data/lib/generators/clearance/specs/templates/features/clearance/visitor_signs_up_spec.rb +11 -11
- data/lib/generators/clearance/specs/templates/features/clearance/visitor_updates_password_spec.rb +12 -12
- data/lib/generators/clearance/specs/templates/support/action_mailer.rb +1 -1
- data/lib/generators/clearance/specs/templates/support/clearance.rb +1 -1
- data/lib/generators/clearance/specs/templates/support/factory_girl.rb +2 -2
- data/lib/generators/clearance/specs/templates/support/features.rb +1 -1
- data/lib/generators/clearance/specs/templates/support/features/clearance_helpers.rb +24 -24
- data/spec/models/bcrypt_spec.rb +14 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0998695d86d391312a288b68a0721140249641b
|
4
|
+
data.tar.gz: 1995891a282666fee645519061cf0cd848aeff86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fca14ac8e1a9650c7acd431642331bbd0eb7365f1f03c070e83be7a7e2bddbb6cec28b7942cade5687b9a28aeb7a0d316e0a21087a71211724cdeaa034db7f1
|
7
|
+
data.tar.gz: c4097377a618028dba3656e1da534fa8d566dc5ea6107c94f45dc585bfaab77e8fa1cd9015a9c33fb43ac270fab2799d2c21e17b5e2e248fedc5fd9d47465442
|
data/Gemfile.lock
CHANGED
data/NEWS.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
Thank you to all the [contributors](https://github.com/thoughtbot/clearance/graphs/contributors)!
|
2
2
|
|
3
|
+
New for 1.4.1 (September 5, 2014)
|
4
|
+
* Prevent BCrypt strategy from raising an exception when `encypted_password`
|
5
|
+
is nil.
|
6
|
+
|
3
7
|
New for 1.4.0 (July 18, 2014)
|
4
8
|
* The sign out link in the default application layout has been replaced with a
|
5
9
|
semantically correct sign out button. This also removes an unnecessary
|
@@ -6,7 +6,9 @@ module Clearance
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
def authenticated?(password)
|
9
|
-
|
9
|
+
if encrypted_password.present?
|
10
|
+
::BCrypt::Password.new(encrypted_password) == password
|
11
|
+
end
|
10
12
|
end
|
11
13
|
|
12
14
|
def password=(new_password)
|
data/lib/clearance/version.rb
CHANGED
@@ -10,7 +10,7 @@ class AddClearanceToUsers < ActiveRecord::Migration
|
|
10
10
|
<%= index %>
|
11
11
|
<% end -%>
|
12
12
|
|
13
|
-
users = select_all(
|
13
|
+
users = select_all("SELECT id FROM users WHERE remember_token IS NULL")
|
14
14
|
|
15
15
|
users.each do |user|
|
16
16
|
update <<-SQL
|
@@ -24,7 +24,7 @@ class AddClearanceToUsers < ActiveRecord::Migration
|
|
24
24
|
def self.down
|
25
25
|
change_table :users do |t|
|
26
26
|
<% if config[:new_columns].any? -%>
|
27
|
-
t.remove <%= new_columns.keys.map { |column| ":#{column}" }.join(
|
27
|
+
t.remove <%= new_columns.keys.map { |column| ":#{column}" }.join(",") %>
|
28
28
|
<% end -%>
|
29
29
|
end
|
30
30
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class CreateUsers < ActiveRecord::Migration
|
2
|
-
def
|
2
|
+
def change
|
3
3
|
create_table :users do |t|
|
4
4
|
t.timestamps null: false
|
5
5
|
t.string :email, null: false
|
@@ -11,8 +11,4 @@ class CreateUsers < ActiveRecord::Migration
|
|
11
11
|
add_index :users, :email
|
12
12
|
add_index :users, :remember_token
|
13
13
|
end
|
14
|
-
|
15
|
-
def self.down
|
16
|
-
drop_table :users
|
17
|
-
end
|
18
14
|
end
|
data/lib/generators/clearance/specs/templates/features/clearance/visitor_resets_password_spec.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
feature
|
4
|
-
scenario
|
3
|
+
feature "Visitor resets password" do
|
4
|
+
scenario "by navigating to the page" do
|
5
5
|
visit sign_in_path
|
6
6
|
|
7
|
-
click_link I18n.t(
|
7
|
+
click_link I18n.t("sessions.form.forgot_password")
|
8
8
|
|
9
|
-
current_path.
|
9
|
+
expect(current_path).to eq new_password_path
|
10
10
|
end
|
11
11
|
|
12
|
-
scenario
|
12
|
+
scenario "with valid email" do
|
13
13
|
user = user_with_reset_password
|
14
14
|
|
15
15
|
page_should_display_change_password_message
|
16
16
|
reset_notification_should_be_sent_to user
|
17
17
|
end
|
18
18
|
|
19
|
-
scenario
|
20
|
-
reset_password_for
|
19
|
+
scenario "with non-user account" do
|
20
|
+
reset_password_for "unknown.email@example.com"
|
21
21
|
|
22
22
|
page_should_display_change_password_message
|
23
23
|
mailer_should_have_no_deliveries
|
@@ -26,16 +26,16 @@ feature 'Visitor resets password' do
|
|
26
26
|
private
|
27
27
|
|
28
28
|
def reset_notification_should_be_sent_to(user)
|
29
|
-
user.confirmation_token.
|
30
|
-
mailer_should_have_delivery user.email,
|
29
|
+
expect(user.confirmation_token).not_to be_blank
|
30
|
+
mailer_should_have_delivery user.email, "password", user.confirmation_token
|
31
31
|
end
|
32
32
|
|
33
33
|
def page_should_display_change_password_message
|
34
|
-
page.
|
34
|
+
expect(page).to have_content I18n.t("passwords.create.description")
|
35
35
|
end
|
36
36
|
|
37
37
|
def mailer_should_have_delivery(recipient, subject, body)
|
38
|
-
ActionMailer::Base.deliveries.
|
38
|
+
expect(ActionMailer::Base.deliveries).not_to be_empty
|
39
39
|
|
40
40
|
message = ActionMailer::Base.deliveries.any? do |email|
|
41
41
|
email.to == [recipient] &&
|
@@ -43,10 +43,10 @@ feature 'Visitor resets password' do
|
|
43
43
|
email.body =~ /#{body}/
|
44
44
|
end
|
45
45
|
|
46
|
-
message.
|
46
|
+
expect(message).to be
|
47
47
|
end
|
48
48
|
|
49
49
|
def mailer_should_have_no_deliveries
|
50
|
-
ActionMailer::Base.deliveries.
|
50
|
+
expect(ActionMailer::Base.deliveries).to be_empty
|
51
51
|
end
|
52
52
|
end
|
@@ -1,30 +1,30 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
feature
|
4
|
-
scenario
|
5
|
-
create_user
|
6
|
-
sign_in_with
|
3
|
+
feature "Visitor signs in" do
|
4
|
+
scenario "with valid email and password" do
|
5
|
+
create_user "user@example.com", "password"
|
6
|
+
sign_in_with "user@example.com", "password"
|
7
7
|
|
8
8
|
user_should_be_signed_in
|
9
9
|
end
|
10
10
|
|
11
|
-
scenario
|
12
|
-
create_user
|
13
|
-
sign_in_with
|
11
|
+
scenario "with valid mixed-case email and password " do
|
12
|
+
create_user "user.name@example.com", "password"
|
13
|
+
sign_in_with "User.Name@example.com", "password"
|
14
14
|
|
15
15
|
user_should_be_signed_in
|
16
16
|
end
|
17
17
|
|
18
|
-
scenario
|
19
|
-
create_user
|
20
|
-
sign_in_with
|
18
|
+
scenario "tries with invalid password" do
|
19
|
+
create_user "user@example.com", "password"
|
20
|
+
sign_in_with "user@example.com", "wrong_password"
|
21
21
|
|
22
22
|
page_should_display_sign_in_error
|
23
23
|
user_should_be_signed_out
|
24
24
|
end
|
25
25
|
|
26
|
-
scenario
|
27
|
-
sign_in_with
|
26
|
+
scenario "tries with invalid email" do
|
27
|
+
sign_in_with "unknown.email@example.com", "password"
|
28
28
|
|
29
29
|
page_should_display_sign_in_error
|
30
30
|
user_should_be_signed_out
|
@@ -37,8 +37,8 @@ feature 'Visitor signs in' do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def page_should_display_sign_in_error
|
40
|
-
page.body.
|
41
|
-
I18n.t(
|
40
|
+
expect(page.body).to include(
|
41
|
+
I18n.t("flashes.failure_after_create", sign_up_path: sign_up_path)
|
42
42
|
)
|
43
43
|
end
|
44
44
|
end
|
@@ -1,28 +1,28 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
feature
|
4
|
-
scenario
|
3
|
+
feature "Visitor signs up" do
|
4
|
+
scenario "by navigating to the page" do
|
5
5
|
visit sign_in_path
|
6
6
|
|
7
|
-
click_link I18n.t(
|
7
|
+
click_link I18n.t("sessions.form.sign_up")
|
8
8
|
|
9
|
-
current_path.
|
9
|
+
expect(current_path).to eq sign_up_path
|
10
10
|
end
|
11
11
|
|
12
|
-
scenario
|
13
|
-
sign_up_with
|
12
|
+
scenario "with valid email and password" do
|
13
|
+
sign_up_with "valid@example.com", "password"
|
14
14
|
|
15
15
|
user_should_be_signed_in
|
16
16
|
end
|
17
17
|
|
18
|
-
scenario
|
19
|
-
sign_up_with
|
18
|
+
scenario "tries with invalid email" do
|
19
|
+
sign_up_with "invalid_email", "password"
|
20
20
|
|
21
21
|
user_should_be_signed_out
|
22
22
|
end
|
23
23
|
|
24
|
-
scenario
|
25
|
-
sign_up_with
|
24
|
+
scenario "tries with blank password" do
|
25
|
+
sign_up_with "valid@example.com", ""
|
26
26
|
|
27
27
|
user_should_be_signed_out
|
28
28
|
end
|
data/lib/generators/clearance/specs/templates/features/clearance/visitor_updates_password_spec.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
feature
|
4
|
-
scenario
|
3
|
+
feature "Visitor updates password" do
|
4
|
+
scenario "with valid password" do
|
5
5
|
user = user_with_reset_password
|
6
|
-
update_password user,
|
6
|
+
update_password user, "newpassword"
|
7
7
|
|
8
8
|
user_should_be_signed_in
|
9
9
|
end
|
10
10
|
|
11
|
-
scenario
|
11
|
+
scenario "signs in with new password" do
|
12
12
|
user = user_with_reset_password
|
13
|
-
update_password user,
|
13
|
+
update_password user, "newpassword"
|
14
14
|
sign_out
|
15
|
-
sign_in_with user.email,
|
15
|
+
sign_in_with user.email, "newpassword"
|
16
16
|
|
17
17
|
user_should_be_signed_in
|
18
18
|
end
|
19
19
|
|
20
|
-
scenario
|
20
|
+
scenario "tries with a blank password" do
|
21
21
|
user = user_with_reset_password
|
22
22
|
visit_password_reset_page_for user
|
23
|
-
change_password_to
|
23
|
+
change_password_to ""
|
24
24
|
|
25
|
-
page.
|
25
|
+
expect(page).to have_content I18n.t("flashes.failure_after_update")
|
26
26
|
user_should_be_signed_out
|
27
27
|
end
|
28
28
|
|
@@ -41,7 +41,7 @@ feature 'Visitor updates password' do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def change_password_to(password)
|
44
|
-
fill_in
|
45
|
-
click_button I18n.t(
|
44
|
+
fill_in "password_reset_password", with: password
|
45
|
+
click_button I18n.t("helpers.submit.password_reset.submit")
|
46
46
|
end
|
47
47
|
end
|
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require "clearance/rspec"
|
@@ -1,37 +1,42 @@
|
|
1
1
|
module Features
|
2
2
|
module ClearanceHelpers
|
3
|
-
def
|
4
|
-
visit
|
5
|
-
fill_in
|
6
|
-
|
7
|
-
|
3
|
+
def reset_password_for(email)
|
4
|
+
visit new_password_path
|
5
|
+
fill_in "password_email", with: email
|
6
|
+
click_button I18n.t("helpers.submit.password.submit")
|
7
|
+
end
|
8
|
+
|
9
|
+
def sign_in
|
10
|
+
password = "password"
|
11
|
+
user = create(:user, password: password)
|
12
|
+
sign_in_with user.email, password
|
8
13
|
end
|
9
14
|
|
10
15
|
def sign_in_with(email, password)
|
11
16
|
visit sign_in_path
|
12
|
-
fill_in
|
13
|
-
fill_in
|
14
|
-
click_button I18n.t(
|
17
|
+
fill_in "session_email", with: email
|
18
|
+
fill_in "session_password", with: password
|
19
|
+
click_button I18n.t("helpers.submit.session.submit")
|
15
20
|
end
|
16
21
|
|
17
|
-
def
|
18
|
-
|
19
|
-
user = create(:user, password: password)
|
20
|
-
sign_in_with user.email, password
|
21
|
-
user
|
22
|
+
def sign_out
|
23
|
+
click_button I18n.t("layouts.application.sign_out")
|
22
24
|
end
|
23
25
|
|
24
|
-
def
|
25
|
-
visit
|
26
|
-
|
26
|
+
def sign_up_with(email, password)
|
27
|
+
visit sign_up_path
|
28
|
+
fill_in "user_email", with: email
|
29
|
+
fill_in "user_password", with: password
|
30
|
+
click_button I18n.t("helpers.submit.user.create")
|
27
31
|
end
|
28
32
|
|
29
|
-
def
|
30
|
-
|
33
|
+
def user_should_be_signed_in
|
34
|
+
visit root_path
|
35
|
+
expect(page).to have_button I18n.t("layouts.application.sign_out")
|
31
36
|
end
|
32
37
|
|
33
38
|
def user_should_be_signed_out
|
34
|
-
page.
|
39
|
+
expect(page).to have_content I18n.t("layouts.application.sign_in")
|
35
40
|
end
|
36
41
|
|
37
42
|
def user_with_reset_password
|
@@ -40,10 +45,5 @@ module Features
|
|
40
45
|
user.reload
|
41
46
|
end
|
42
47
|
|
43
|
-
def reset_password_for(email)
|
44
|
-
visit new_password_path
|
45
|
-
fill_in 'password_email', with: email
|
46
|
-
click_button I18n.t('helpers.submit.password.submit')
|
47
|
-
end
|
48
48
|
end
|
49
49
|
end
|
data/spec/models/bcrypt_spec.rb
CHANGED
@@ -41,14 +41,25 @@ describe Clearance::PasswordStrategies::BCrypt do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
describe '#authenticated?' do
|
44
|
-
let(:password) { 'password' }
|
45
44
|
|
46
45
|
before do
|
47
46
|
subject.password = password
|
48
47
|
end
|
49
48
|
|
50
|
-
|
51
|
-
|
49
|
+
context 'given a password' do
|
50
|
+
let(:password) { 'password' }
|
51
|
+
|
52
|
+
it 'is authenticated with BCrypt' do
|
53
|
+
subject.should be_authenticated(password)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'given no password' do
|
58
|
+
let(:password) { nil }
|
59
|
+
|
60
|
+
it 'is not authenticated' do
|
61
|
+
subject.should_not be_authenticated(password)
|
62
|
+
end
|
52
63
|
end
|
53
64
|
end
|
54
65
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clearance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Croak
|
@@ -25,7 +25,7 @@ authors:
|
|
25
25
|
autorequire:
|
26
26
|
bindir: bin
|
27
27
|
cert_chain: []
|
28
|
-
date: 2014-
|
28
|
+
date: 2014-09-08 00:00:00.000000000 Z
|
29
29
|
dependencies:
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bcrypt
|