clearance 1.5.1 → 1.6.0
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/Appraisals +7 -13
- data/Gemfile +1 -1
- data/Gemfile.lock +88 -69
- data/NEWS.md +4 -0
- data/app/controllers/clearance/passwords_controller.rb +7 -1
- data/features/step_definitions/configuration_steps.rb +6 -0
- data/features/step_definitions/gem_file_steps.rb +1 -1
- data/lib/clearance/testing/application.rb +2 -1
- data/lib/clearance/version.rb +1 -1
- data/spec/clearance/back_door_spec.rb +4 -4
- data/spec/clearance/default_sign_in_guard_spec.rb +2 -2
- data/spec/clearance/rack_session_spec.rb +3 -3
- data/spec/clearance/session_spec.rb +18 -16
- data/spec/clearance/sign_in_guard_spec.rb +10 -8
- data/spec/clearance/testing/helpers_spec.rb +3 -2
- data/spec/clearance/token_spec.rb +1 -1
- data/spec/controllers/apis_controller_spec.rb +0 -2
- data/spec/controllers/forgeries_controller_spec.rb +2 -2
- data/spec/models/bcrypt_migration_from_sha1_spec.rb +3 -3
- data/spec/models/bcrypt_spec.rb +4 -3
- data/spec/models/user_spec.rb +1 -1
- data/spec/spec_helper.rb +9 -2
- 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: fbf88ab9f935fc17b80bd9901390e94c0f7ab684
|
4
|
+
data.tar.gz: a522250322d628529f2056ec9de17ef2eaceb608
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71ff65519b2a7ed783aa0341f7a3f8adb657029810748fafd8ddecfc4e14a5517b8bbab31773bd23f13f64d1439bc94bc401f756fc8774d0d98c6d952e376cbe
|
7
|
+
data.tar.gz: 3c25517857b86f5bfe43241d1c6e03abf814849418bc5d25da6ff47e36c3640d911dfcbed9a96be736eb15fe47d5523a56ac58322978d92696d806ca586a6d32
|
data/Appraisals
CHANGED
@@ -1,21 +1,15 @@
|
|
1
|
-
# These are the various versions of rails we want to test against.
|
2
|
-
# The non-rails gems (jbuilder, sdoc, etc) are dependencies introduced
|
3
|
-
# in the default rails gemfiles used in the clearance features.
|
4
1
|
appraise 'rails3.2' do
|
5
|
-
gem '
|
6
|
-
gem 'rails', '~> 3.2.17'
|
7
|
-
gem 'sdoc'
|
2
|
+
gem 'rails', '~> 3.2.21'
|
8
3
|
end
|
9
4
|
|
10
5
|
appraise 'rails4.0' do
|
11
|
-
gem '
|
12
|
-
gem 'rails', '~> 4.0.4'
|
13
|
-
gem 'sdoc'
|
6
|
+
gem 'rails', '~> 4.0.12'
|
14
7
|
end
|
15
8
|
|
16
9
|
appraise 'rails4.1' do
|
17
|
-
gem '
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
gem 'rails', '~> 4.1.8'
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise 'rails4.2' do
|
14
|
+
gem 'rails', '~> 4.2.0'
|
21
15
|
end
|
data/Gemfile
CHANGED
@@ -4,7 +4,6 @@ gemspec
|
|
4
4
|
|
5
5
|
gem 'appraisal', '~> 1.0'
|
6
6
|
gem 'aruba', '~> 0.5'
|
7
|
-
gem 'bourne', '~> 1.4'
|
8
7
|
gem 'bundler', '~> 1.3'
|
9
8
|
gem 'capybara', '~> 2.2.0'
|
10
9
|
gem 'cucumber-rails', '~> 1.3', require: false
|
@@ -15,3 +14,4 @@ gem 'shoulda-matchers', '~> 2.4'
|
|
15
14
|
gem 'sqlite3', '~> 1.3'
|
16
15
|
gem 'timecop', '~> 0.6'
|
17
16
|
gem 'rspec', '~> 2.14'
|
17
|
+
gem 'pry', require: false
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
clearance (1.
|
4
|
+
clearance (1.6.0)
|
5
5
|
bcrypt
|
6
6
|
email_validator (~> 1.4)
|
7
7
|
rails (>= 3.1)
|
@@ -9,44 +9,51 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
actionmailer (4.
|
13
|
-
actionpack (= 4.
|
14
|
-
actionview (= 4.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
actionmailer (4.2.0)
|
13
|
+
actionpack (= 4.2.0)
|
14
|
+
actionview (= 4.2.0)
|
15
|
+
activejob (= 4.2.0)
|
16
|
+
mail (~> 2.5, >= 2.5.4)
|
17
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
18
|
+
actionpack (4.2.0)
|
19
|
+
actionview (= 4.2.0)
|
20
|
+
activesupport (= 4.2.0)
|
21
|
+
rack (~> 1.6.0)
|
20
22
|
rack-test (~> 0.6.2)
|
21
|
-
|
22
|
-
|
23
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
24
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
25
|
+
actionview (4.2.0)
|
26
|
+
activesupport (= 4.2.0)
|
23
27
|
builder (~> 3.1)
|
24
28
|
erubis (~> 2.7.0)
|
25
|
-
|
26
|
-
|
29
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
30
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
31
|
+
activejob (4.2.0)
|
32
|
+
activesupport (= 4.2.0)
|
33
|
+
globalid (>= 0.3.0)
|
34
|
+
activemodel (4.2.0)
|
35
|
+
activesupport (= 4.2.0)
|
27
36
|
builder (~> 3.1)
|
28
|
-
activerecord (4.
|
29
|
-
activemodel (= 4.
|
30
|
-
activesupport (= 4.
|
31
|
-
arel (~>
|
32
|
-
activesupport (4.
|
33
|
-
i18n (~> 0.
|
37
|
+
activerecord (4.2.0)
|
38
|
+
activemodel (= 4.2.0)
|
39
|
+
activesupport (= 4.2.0)
|
40
|
+
arel (~> 6.0)
|
41
|
+
activesupport (4.2.0)
|
42
|
+
i18n (~> 0.7)
|
34
43
|
json (~> 1.7, >= 1.7.7)
|
35
44
|
minitest (~> 5.1)
|
36
|
-
thread_safe (~> 0.
|
45
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
37
46
|
tzinfo (~> 1.1)
|
38
|
-
appraisal (1.0.
|
47
|
+
appraisal (1.0.2)
|
39
48
|
bundler
|
40
49
|
rake
|
41
50
|
thor (>= 0.14.0)
|
42
|
-
arel (
|
51
|
+
arel (6.0.0)
|
43
52
|
aruba (0.6.1)
|
44
53
|
childprocess (>= 0.3.6)
|
45
54
|
cucumber (>= 1.1.1)
|
46
55
|
rspec-expectations (>= 2.7.0)
|
47
56
|
bcrypt (3.1.9)
|
48
|
-
bourne (1.5.0)
|
49
|
-
mocha (>= 0.13.2, < 0.15)
|
50
57
|
builder (3.2.2)
|
51
58
|
capybara (2.2.1)
|
52
59
|
mime-types (>= 1.16)
|
@@ -54,18 +61,19 @@ GEM
|
|
54
61
|
rack (>= 1.0.0)
|
55
62
|
rack-test (>= 0.5.4)
|
56
63
|
xpath (~> 2.0)
|
57
|
-
childprocess (0.5.
|
64
|
+
childprocess (0.5.5)
|
58
65
|
ffi (~> 1.0, >= 1.0.11)
|
59
|
-
|
66
|
+
coderay (1.1.0)
|
67
|
+
cucumber (1.3.17)
|
60
68
|
builder (>= 2.1.2)
|
61
69
|
diff-lcs (>= 1.1.3)
|
62
70
|
gherkin (~> 2.12)
|
63
71
|
multi_json (>= 1.7.5, < 2.0)
|
64
72
|
multi_test (>= 0.1.1)
|
65
|
-
cucumber-rails (1.4.
|
73
|
+
cucumber-rails (1.4.2)
|
66
74
|
capybara (>= 1.1.2, < 3)
|
67
75
|
cucumber (>= 1.3.8, < 2)
|
68
|
-
mime-types (
|
76
|
+
mime-types (>= 1.16, < 3)
|
69
77
|
nokogiri (~> 1.5)
|
70
78
|
rails (>= 3, < 5)
|
71
79
|
database_cleaner (1.3.0)
|
@@ -73,55 +81,68 @@ GEM
|
|
73
81
|
email_validator (1.5.0)
|
74
82
|
activemodel
|
75
83
|
erubis (2.7.0)
|
76
|
-
factory_girl (4.
|
84
|
+
factory_girl (4.5.0)
|
77
85
|
activesupport (>= 3.0.0)
|
78
|
-
factory_girl_rails (4.
|
79
|
-
factory_girl (~> 4.
|
86
|
+
factory_girl_rails (4.5.0)
|
87
|
+
factory_girl (~> 4.5.0)
|
80
88
|
railties (>= 3.0.0)
|
81
|
-
ffi (1.9.
|
89
|
+
ffi (1.9.6)
|
82
90
|
gherkin (2.12.2)
|
83
91
|
multi_json (~> 1.3)
|
92
|
+
globalid (0.3.0)
|
93
|
+
activesupport (>= 4.1.0)
|
84
94
|
hike (1.2.3)
|
85
|
-
i18n (0.
|
95
|
+
i18n (0.7.0)
|
86
96
|
json (1.8.1)
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
metaclass (~> 0.0.1)
|
97
|
+
loofah (2.0.1)
|
98
|
+
nokogiri (>= 1.5.9)
|
99
|
+
mail (2.6.3)
|
100
|
+
mime-types (>= 1.16, < 3)
|
101
|
+
method_source (0.8.2)
|
102
|
+
mime-types (2.4.3)
|
103
|
+
mini_portile (0.6.1)
|
104
|
+
minitest (5.5.0)
|
96
105
|
multi_json (1.10.1)
|
97
106
|
multi_test (0.1.1)
|
98
|
-
nokogiri (1.6.
|
99
|
-
mini_portile (
|
100
|
-
|
101
|
-
|
107
|
+
nokogiri (1.6.5)
|
108
|
+
mini_portile (~> 0.6.0)
|
109
|
+
pry (0.10.1)
|
110
|
+
coderay (~> 1.1.0)
|
111
|
+
method_source (~> 0.8.1)
|
112
|
+
slop (~> 3.4)
|
113
|
+
rack (1.6.0)
|
102
114
|
rack-test (0.6.2)
|
103
115
|
rack (>= 1.0)
|
104
|
-
rails (4.
|
105
|
-
actionmailer (= 4.
|
106
|
-
actionpack (= 4.
|
107
|
-
actionview (= 4.
|
108
|
-
|
109
|
-
|
110
|
-
|
116
|
+
rails (4.2.0)
|
117
|
+
actionmailer (= 4.2.0)
|
118
|
+
actionpack (= 4.2.0)
|
119
|
+
actionview (= 4.2.0)
|
120
|
+
activejob (= 4.2.0)
|
121
|
+
activemodel (= 4.2.0)
|
122
|
+
activerecord (= 4.2.0)
|
123
|
+
activesupport (= 4.2.0)
|
111
124
|
bundler (>= 1.3.0, < 2.0)
|
112
|
-
railties (= 4.
|
113
|
-
sprockets-rails
|
114
|
-
|
115
|
-
|
116
|
-
|
125
|
+
railties (= 4.2.0)
|
126
|
+
sprockets-rails
|
127
|
+
rails-deprecated_sanitizer (1.0.3)
|
128
|
+
activesupport (>= 4.2.0.alpha)
|
129
|
+
rails-dom-testing (1.0.5)
|
130
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
131
|
+
nokogiri (~> 1.6.0)
|
132
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
133
|
+
rails-html-sanitizer (1.0.1)
|
134
|
+
loofah (~> 2.0)
|
135
|
+
railties (4.2.0)
|
136
|
+
actionpack (= 4.2.0)
|
137
|
+
activesupport (= 4.2.0)
|
117
138
|
rake (>= 0.8.7)
|
118
139
|
thor (>= 0.18.1, < 2.0)
|
119
|
-
rake (10.
|
140
|
+
rake (10.4.2)
|
120
141
|
rspec (2.99.0)
|
121
142
|
rspec-core (~> 2.99.0)
|
122
143
|
rspec-expectations (~> 2.99.0)
|
123
144
|
rspec-mocks (~> 2.99.0)
|
124
|
-
rspec-collection_matchers (1.
|
145
|
+
rspec-collection_matchers (1.1.2)
|
125
146
|
rspec-expectations (>= 2.99.0.beta1)
|
126
147
|
rspec-core (2.99.2)
|
127
148
|
rspec-expectations (2.99.2)
|
@@ -136,25 +157,23 @@ GEM
|
|
136
157
|
rspec-core (~> 2.99.0)
|
137
158
|
rspec-expectations (~> 2.99.0)
|
138
159
|
rspec-mocks (~> 2.99.0)
|
139
|
-
shoulda-matchers (2.
|
160
|
+
shoulda-matchers (2.7.0)
|
140
161
|
activesupport (>= 3.0.0)
|
141
|
-
|
162
|
+
slop (3.6.0)
|
163
|
+
sprockets (2.12.3)
|
142
164
|
hike (~> 1.2)
|
143
165
|
multi_json (~> 1.0)
|
144
166
|
rack (~> 1.0)
|
145
167
|
tilt (~> 1.1, != 1.3.0)
|
146
|
-
sprockets-rails (2.
|
168
|
+
sprockets-rails (2.2.2)
|
147
169
|
actionpack (>= 3.0)
|
148
170
|
activesupport (>= 3.0)
|
149
|
-
sprockets (
|
150
|
-
sqlite3 (1.3.
|
171
|
+
sprockets (>= 2.8, < 4.0)
|
172
|
+
sqlite3 (1.3.10)
|
151
173
|
thor (0.19.1)
|
152
174
|
thread_safe (0.3.4)
|
153
175
|
tilt (1.4.1)
|
154
176
|
timecop (0.7.1)
|
155
|
-
treetop (1.4.15)
|
156
|
-
polyglot
|
157
|
-
polyglot (>= 0.3.1)
|
158
177
|
tzinfo (1.2.2)
|
159
178
|
thread_safe (~> 0.1)
|
160
179
|
xpath (2.0.0)
|
@@ -166,13 +185,13 @@ PLATFORMS
|
|
166
185
|
DEPENDENCIES
|
167
186
|
appraisal (~> 1.0)
|
168
187
|
aruba (~> 0.5)
|
169
|
-
bourne (~> 1.4)
|
170
188
|
bundler (~> 1.3)
|
171
189
|
capybara (~> 2.2.0)
|
172
190
|
clearance!
|
173
191
|
cucumber-rails (~> 1.3)
|
174
192
|
database_cleaner (~> 1.0)
|
175
193
|
factory_girl_rails (~> 4.2)
|
194
|
+
pry
|
176
195
|
rspec (~> 2.14)
|
177
196
|
rspec-rails
|
178
197
|
shoulda-matchers (~> 2.4)
|
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.6.0 (December 20, 2014)
|
4
|
+
* When using Rails 4.2, password reset emails are sent with the
|
5
|
+
ActiveJob-compatible `#deliver_later` method.
|
6
|
+
|
3
7
|
New for 1.5.1 (December 19, 2014)
|
4
8
|
* Blowfish password strategy fixed
|
5
9
|
* Specs generated with `rails generate clearance:specs` now work properly in
|
@@ -37,7 +37,13 @@ class Clearance::PasswordsController < Clearance::BaseController
|
|
37
37
|
private
|
38
38
|
|
39
39
|
def deliver_email(user)
|
40
|
-
::ClearanceMailer.change_password(user)
|
40
|
+
mail = ::ClearanceMailer.change_password(user)
|
41
|
+
|
42
|
+
if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("4.2.0")
|
43
|
+
mail.deliver_later
|
44
|
+
else
|
45
|
+
mail.deliver
|
46
|
+
end
|
41
47
|
end
|
42
48
|
|
43
49
|
def password_reset_params
|
@@ -26,6 +26,12 @@ When "I have a project with clearance" do
|
|
26
26
|
And I configure ActionMailer to use "localhost" as a host
|
27
27
|
And I configure a root route
|
28
28
|
And I remove the "turn" gem from this project
|
29
|
+
And I remove the "web-console" gem from this project
|
30
|
+
And I remove the "jbuilder" gem from this project
|
31
|
+
And I remove the "sdoc" gem from this project
|
32
|
+
And I remove the "byebug" gem from this project
|
33
|
+
And I remove the "debugger" gem from this project
|
34
|
+
And I remove the "spring" gem from this project
|
29
35
|
And I add the "clearance" gem from this project
|
30
36
|
}
|
31
37
|
end
|
@@ -9,7 +9,7 @@ end
|
|
9
9
|
When /^I remove the "([^"]*)" gem from this project$/ do |gem_name|
|
10
10
|
in_current_dir do
|
11
11
|
content = File.read('Gemfile')
|
12
|
-
content.
|
12
|
+
content.sub!(/^.*gem '#{gem_name}'.*\n/, "")
|
13
13
|
File.open('Gemfile', 'w') { |file| file.write(content) }
|
14
14
|
end
|
15
15
|
end
|
@@ -5,7 +5,7 @@ module Clearance
|
|
5
5
|
APP_ROOT = File.expand_path('..', __FILE__).freeze
|
6
6
|
|
7
7
|
def self.rails4?
|
8
|
-
Rails::VERSION::MAJOR
|
8
|
+
Rails::VERSION::MAJOR >= 4
|
9
9
|
end
|
10
10
|
|
11
11
|
I18n.enforce_available_locales = true
|
@@ -27,6 +27,7 @@ module Clearance
|
|
27
27
|
config.paths['config/database'] = "#{APP_ROOT}/config/database.yml"
|
28
28
|
config.paths['log'] = 'tmp/log/development.log'
|
29
29
|
config.secret_token = 'SECRET_TOKEN_IS_MIN_30_CHARS_LONG'
|
30
|
+
config.active_support.test_order = :random
|
30
31
|
|
31
32
|
if Clearance::Testing.rails4?
|
32
33
|
config.paths.add 'config/routes.rb', with: "#{APP_ROOT}/config/routes.rb"
|
data/lib/clearance/version.rb
CHANGED
@@ -3,8 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe Clearance::BackDoor do
|
4
4
|
it 'signs in as a given user' do
|
5
5
|
user_id = '123'
|
6
|
-
user =
|
7
|
-
User.
|
6
|
+
user = double("user")
|
7
|
+
allow(User).to receive(:find).with(user_id).and_return(user)
|
8
8
|
env = env_for_user_id(user_id)
|
9
9
|
back_door = Clearance::BackDoor.new(mock_app)
|
10
10
|
|
@@ -20,7 +20,7 @@ describe Clearance::BackDoor do
|
|
20
20
|
|
21
21
|
result = back_door.call(env)
|
22
22
|
|
23
|
-
expect(env[:clearance]).
|
23
|
+
expect(env[:clearance]).not_to have_received(:sign_in)
|
24
24
|
expect(result).to eq mock_app.call(env)
|
25
25
|
end
|
26
26
|
|
@@ -29,7 +29,7 @@ describe Clearance::BackDoor do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def env_for_user_id(user_id)
|
32
|
-
clearance =
|
32
|
+
clearance = double("clearance", sign_in: true)
|
33
33
|
Rack::MockRequest.env_for("/?as=#{user_id}").merge(clearance: clearance)
|
34
34
|
end
|
35
35
|
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Clearance::DefaultSignInGuard do
|
4
4
|
context 'session is signed in' do
|
5
5
|
it 'returns success' do
|
6
|
-
session =
|
6
|
+
session = double("Session", signed_in?: true)
|
7
7
|
guard = Clearance::DefaultSignInGuard.new(session)
|
8
8
|
|
9
9
|
expect(guard.call).to be_a Clearance::SuccessStatus
|
@@ -12,7 +12,7 @@ describe Clearance::DefaultSignInGuard do
|
|
12
12
|
|
13
13
|
context 'session is not signed in' do
|
14
14
|
it 'returns failure' do
|
15
|
-
session =
|
15
|
+
session = double("Session", signed_in?: false)
|
16
16
|
guard = Clearance::DefaultSignInGuard.new(session)
|
17
17
|
|
18
18
|
response = guard.call
|
@@ -3,8 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe Clearance::RackSession do
|
4
4
|
it 'injects a clearance session into the environment' do
|
5
5
|
expected_session = 'the session'
|
6
|
-
expected_session.
|
7
|
-
Clearance::Session.
|
6
|
+
allow(expected_session).to receive(:add_cookie_to_headers)
|
7
|
+
allow(Clearance::Session).to receive(:new).and_return(expected_session)
|
8
8
|
headers = { 'X-Roaring-Lobster' => 'Red' }
|
9
9
|
|
10
10
|
app = Rack::Builder.new do
|
@@ -19,6 +19,6 @@ describe Clearance::RackSession do
|
|
19
19
|
expect(Clearance::Session).to have_received(:new).with(env)
|
20
20
|
expect(response.body).to eq expected_session
|
21
21
|
expect(expected_session).to have_received(:add_cookie_to_headers).
|
22
|
-
with(
|
22
|
+
with(hash_including(headers))
|
23
23
|
end
|
24
24
|
end
|
@@ -59,14 +59,14 @@ describe Clearance::Session do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def stub_status(status_class, success)
|
62
|
-
|
63
|
-
status_class.
|
62
|
+
double("status", success?: success).tap do |status|
|
63
|
+
allow(status_class).to receive(:new).and_return(status)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
def stub_callable
|
68
68
|
lambda {}.tap do |callable|
|
69
|
-
callable.
|
69
|
+
allow(callable).to receive(:call)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
@@ -104,27 +104,29 @@ describe Clearance::Session do
|
|
104
104
|
def stub_sign_in_guard(options)
|
105
105
|
session_status = stub_status(options.fetch(:succeed))
|
106
106
|
|
107
|
-
|
107
|
+
double("guard", call: session_status).tap do |guard|
|
108
108
|
Clearance.configuration.sign_in_guards << stub_guard_class(guard)
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
112
|
def stub_default_sign_in_guard
|
113
|
-
|
114
|
-
Clearance::DefaultSignInGuard.
|
115
|
-
|
113
|
+
double("default_sign_in_guard").tap do |sign_in_guard|
|
114
|
+
allow(Clearance::DefaultSignInGuard).to receive(:new).
|
115
|
+
with(session).
|
116
|
+
and_return(sign_in_guard)
|
116
117
|
end
|
117
118
|
end
|
118
119
|
|
119
120
|
def stub_guard_class(guard)
|
120
|
-
|
121
|
-
guard_class.
|
122
|
-
|
121
|
+
double("guard_class").tap do |guard_class|
|
122
|
+
allow(guard_class).to receive(:new).
|
123
|
+
with(session, stub_default_sign_in_guard).
|
124
|
+
and_return(guard)
|
123
125
|
end
|
124
126
|
end
|
125
127
|
|
126
128
|
def stub_status(success)
|
127
|
-
|
129
|
+
double("status", success?: success)
|
128
130
|
end
|
129
131
|
|
130
132
|
after do
|
@@ -163,7 +165,7 @@ describe Clearance::Session do
|
|
163
165
|
describe 'remember token cookie expiration' do
|
164
166
|
context 'default configuration' do
|
165
167
|
it 'is set to 1 year from now' do
|
166
|
-
user =
|
168
|
+
user = double("User", remember_token: "123abc")
|
167
169
|
headers = {}
|
168
170
|
session = Clearance::Session.new(env_without_remember_token)
|
169
171
|
session.sign_in user
|
@@ -181,7 +183,7 @@ describe Clearance::Session do
|
|
181
183
|
expiration = -> { Time.now }
|
182
184
|
with_custom_expiration expiration do
|
183
185
|
session = Clearance::Session.new(env_without_remember_token)
|
184
|
-
session.
|
186
|
+
allow(session).to receive(:warn)
|
185
187
|
session.add_cookie_to_headers headers
|
186
188
|
|
187
189
|
expect(session).to have_received(:warn).once
|
@@ -191,11 +193,11 @@ describe Clearance::Session do
|
|
191
193
|
it 'is set to the value of the evaluated lambda' do
|
192
194
|
expires_at = -> { 1.day.from_now }
|
193
195
|
with_custom_expiration expires_at do
|
194
|
-
user =
|
196
|
+
user = double("User", remember_token: "123abc")
|
195
197
|
headers = {}
|
196
198
|
session = Clearance::Session.new(env_without_remember_token)
|
197
199
|
session.sign_in user
|
198
|
-
session.
|
200
|
+
allow(session).to receive(:warn)
|
199
201
|
session.add_cookie_to_headers headers
|
200
202
|
|
201
203
|
expect(headers).to set_cookie(
|
@@ -213,7 +215,7 @@ describe Clearance::Session do
|
|
213
215
|
cookies['remember_me'] ? remembered_expires : nil
|
214
216
|
end
|
215
217
|
with_custom_expiration expires_at do
|
216
|
-
user =
|
218
|
+
user = double("User", remember_token: "123abc")
|
217
219
|
headers = {}
|
218
220
|
environment = env_with_cookies(remember_me: 'true')
|
219
221
|
session = Clearance::Session.new(environment)
|
@@ -3,25 +3,27 @@ require 'spec_helper'
|
|
3
3
|
module Clearance
|
4
4
|
describe SignInGuard do
|
5
5
|
it 'handles success' do
|
6
|
-
sign_in_guard = SignInGuard.new(
|
7
|
-
status =
|
8
|
-
SuccessStatus.
|
6
|
+
sign_in_guard = SignInGuard.new(double("session"))
|
7
|
+
status = double("status")
|
8
|
+
allow(SuccessStatus).to receive(:new).and_return(status)
|
9
9
|
|
10
10
|
expect(sign_in_guard.success).to eq(status)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'handles failure' do
|
14
|
-
sign_in_guard = SignInGuard.new(
|
15
|
-
status =
|
14
|
+
sign_in_guard = SignInGuard.new(double("session"))
|
15
|
+
status = double("status")
|
16
16
|
failure_message = "Failed"
|
17
|
-
FailureStatus.
|
17
|
+
allow(FailureStatus).to receive(:new).
|
18
|
+
with(failure_message).
|
19
|
+
and_return(status)
|
18
20
|
|
19
21
|
expect(sign_in_guard.failure(failure_message)).to eq(status)
|
20
22
|
end
|
21
23
|
|
22
24
|
it 'can proceed to the next guard' do
|
23
|
-
guards =
|
24
|
-
sign_in_guard = SignInGuard.new(
|
25
|
+
guards = double("guards", call: true)
|
26
|
+
sign_in_guard = SignInGuard.new(double("session"), guards)
|
25
27
|
sign_in_guard.next_guard
|
26
28
|
expect(guards).to have_received(:call)
|
27
29
|
end
|
@@ -16,8 +16,9 @@ describe Clearance::Testing::Helpers do
|
|
16
16
|
describe '#sign_in' do
|
17
17
|
it 'creates an instance of the clearance user model with FactoryGirl' do
|
18
18
|
MyUserModel = Class.new
|
19
|
-
FactoryGirl.
|
20
|
-
Clearance.configuration.
|
19
|
+
allow(FactoryGirl).to receive(:create)
|
20
|
+
allow(Clearance.configuration).to receive(:user_model).
|
21
|
+
and_return(MyUserModel)
|
21
22
|
|
22
23
|
TestClass.new.sign_in
|
23
24
|
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Clearance::Token do
|
4
4
|
it 'is a random hex string' do
|
5
5
|
token = 'my_token'
|
6
|
-
SecureRandom.
|
6
|
+
allow(SecureRandom).to receive(:hex).with(20).and_return(token)
|
7
7
|
|
8
8
|
expect(Clearance::Token.new).to eq token
|
9
9
|
end
|
@@ -25,7 +25,6 @@ describe ForgeriesController do
|
|
25
25
|
@user = create(:user)
|
26
26
|
@user.update_attribute(:remember_token, 'old-token')
|
27
27
|
@request.cookies['remember_token'] = 'old-token'
|
28
|
-
@request.session[:_csrf_token] = 'golden-ticket'
|
29
28
|
end
|
30
29
|
|
31
30
|
after do
|
@@ -33,7 +32,8 @@ describe ForgeriesController do
|
|
33
32
|
end
|
34
33
|
|
35
34
|
it 'succeeds with authentic token' do
|
36
|
-
|
35
|
+
token = controller.send(:form_authenticity_token)
|
36
|
+
post :create, authenticity_token: token
|
37
37
|
expect(subject).to redirect_to(action: 'index')
|
38
38
|
end
|
39
39
|
|
@@ -10,13 +10,13 @@ describe Clearance::PasswordStrategies::BCryptMigrationFromSHA1 do
|
|
10
10
|
describe '#password=' do
|
11
11
|
let(:salt) { 'salt' }
|
12
12
|
let(:password) { 'password' }
|
13
|
-
let(:encrypted_password) {
|
13
|
+
let(:encrypted_password) { double("encrypted password") }
|
14
14
|
|
15
15
|
before do
|
16
16
|
subject.salt = salt
|
17
17
|
digestable = "--#{salt}--#{password}--"
|
18
18
|
subject.encrypted_password = Digest::SHA1.hexdigest(digestable)
|
19
|
-
BCrypt::Password.
|
19
|
+
allow(BCrypt::Password).to receive(:create).and_return(encrypted_password)
|
20
20
|
subject.password = password
|
21
21
|
end
|
22
22
|
|
@@ -43,7 +43,7 @@ describe Clearance::PasswordStrategies::BCryptMigrationFromSHA1 do
|
|
43
43
|
before do
|
44
44
|
subject.salt = salt
|
45
45
|
subject.encrypted_password = sha1_hash
|
46
|
-
subject.
|
46
|
+
allow(subject).to receive(:save).and_return(true)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'is authenticated' do
|
data/spec/models/bcrypt_spec.rb
CHANGED
@@ -7,10 +7,10 @@ describe Clearance::PasswordStrategies::BCrypt do
|
|
7
7
|
|
8
8
|
describe '#password=' do
|
9
9
|
let(:password) { 'password' }
|
10
|
-
let(:encrypted_password) {
|
10
|
+
let(:encrypted_password) { double("encrypted password") }
|
11
11
|
|
12
12
|
before do
|
13
|
-
BCrypt::Password.
|
13
|
+
allow(BCrypt::Password).to receive(:create).and_return(encrypted_password)
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'encrypts the password into encrypted_password' do
|
@@ -20,7 +20,8 @@ describe Clearance::PasswordStrategies::BCrypt do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'encrypts with BCrypt using default cost in non test environments' do
|
23
|
-
Rails.
|
23
|
+
allow(Rails).to receive(:env).
|
24
|
+
and_return(ActiveSupport::StringInquirer.new("production"))
|
24
25
|
|
25
26
|
subject.password = password
|
26
27
|
|
data/spec/models/user_spec.rb
CHANGED
@@ -84,7 +84,7 @@ describe User do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'does not generate same remember token for users with same password at same time' do
|
87
|
-
Time.
|
87
|
+
allow(Time).to receive(:now).and_return(Time.now)
|
88
88
|
password = 'secret'
|
89
89
|
first_user = create(:user, password: password)
|
90
90
|
second_user = create(:user, password: password)
|
data/spec/spec_helper.rb
CHANGED
@@ -10,7 +10,6 @@ Bundler.require
|
|
10
10
|
|
11
11
|
require 'clearance/testing/application'
|
12
12
|
require 'rspec/rails'
|
13
|
-
require 'bourne'
|
14
13
|
require 'factory_girl_rails'
|
15
14
|
require 'shoulda-matchers'
|
16
15
|
require 'clearance/rspec'
|
@@ -22,9 +21,17 @@ Clearance::Testing::Application.initialize!
|
|
22
21
|
|
23
22
|
RSpec.configure do |config|
|
24
23
|
config.include FactoryGirl::Syntax::Methods
|
25
|
-
config.mock_with :mocha
|
26
24
|
config.use_transactional_fixtures = true
|
25
|
+
config.order = :random
|
27
26
|
config.infer_spec_type_from_file_location!
|
27
|
+
|
28
|
+
config.expect_with :rspec do |expectations|
|
29
|
+
expectations.syntax = :expect
|
30
|
+
end
|
31
|
+
|
32
|
+
config.mock_with :rspec do |mocks|
|
33
|
+
mocks.syntax = :expect
|
34
|
+
end
|
28
35
|
end
|
29
36
|
|
30
37
|
def restore_default_config
|
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
|
+
version: 1.6.0
|
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-12-
|
28
|
+
date: 2014-12-20 00:00:00.000000000 Z
|
29
29
|
dependencies:
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bcrypt
|