authenticate 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,12 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  ENV['RAILS_ENV'] ||= 'test'
3
3
 
4
4
  require File.expand_path('../dummy/config/environment.rb', __FILE__)
5
+
6
+ # nasty hacky catch of environment data wiped out by tests run in rails 4 via appraisal
7
+ if ActiveRecord::VERSION::STRING >= '5.0'
8
+ system('bin/rails dummy:db:environment:set RAILS_ENV=test')
9
+ end
10
+
5
11
  require 'rspec/rails'
6
12
  require 'shoulda-matchers'
7
13
  require 'capybara/rails'
@@ -9,14 +15,11 @@ require 'capybara/rspec'
9
15
  require 'database_cleaner'
10
16
  require 'factory_girl'
11
17
  require 'timecop'
18
+ require 'support/mailer'
12
19
 
13
20
  Rails.backtrace_cleaner.remove_silencers!
14
21
  DatabaseCleaner.strategy = :truncation
15
22
 
16
- # No longer autoloading support, individually requiring instead.
17
- #
18
- # Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
19
-
20
23
  # Load factory girl factories.
21
24
  Dir[File.join(File.dirname(__FILE__), 'factories/**/*.rb')].each { |f| require f }
22
25
 
@@ -27,6 +30,12 @@ else
27
30
  ActiveRecord::Migration.check_pending! # rails 4.0
28
31
  end
29
32
 
33
+ if ActiveRecord::VERSION::STRING >= '4.2' && ActiveRecord::VERSION::STRING < '5.0'
34
+ ActiveRecord::Base.raise_in_transactional_callbacks = true
35
+ end
36
+
37
+ puts 'MAJOR:' + Rails::VERSION::MAJOR.to_s
38
+
30
39
  RSpec.configure do |config|
31
40
  config.include FactoryGirl::Syntax::Methods
32
41
  config.infer_spec_type_from_file_location!
@@ -54,3 +63,36 @@ def mock_request(params = {})
54
63
  allow(req).to receive(:remote_ip).and_return('111.111.111.111')
55
64
  req
56
65
  end
66
+
67
+ #
68
+ # Dumb glue method, deal with rails 4 vs rails 5 get/post methods.
69
+ #
70
+ def do_post(path, *args)
71
+ if Rails::VERSION::MAJOR >= 5
72
+ post path, *args
73
+ else
74
+ post path, *(args.collect{|i| i.values}.flatten)
75
+ end
76
+ end
77
+
78
+ def do_get(path, *args)
79
+ if Rails::VERSION::MAJOR >= 5
80
+ get path, *args
81
+ else
82
+ get path, *(args.collect{|i| i.values}.flatten)
83
+ end
84
+ end
85
+
86
+ def do_put(path, *args)
87
+ if Rails::VERSION::MAJOR >= 5
88
+ put path, *args
89
+ else
90
+ put path, *(args.collect{|i| i.values}.flatten)
91
+ end
92
+ end
93
+
94
+ # class ActionMailer::MessageDelivery
95
+ # def deliver_later
96
+ # deliver_now
97
+ # end
98
+ # end
@@ -20,12 +20,16 @@ module Features
20
20
  end
21
21
 
22
22
  def expect_page_to_display_sign_in_error
23
- expect(page).to have_content 'Invalid id or password'
23
+ expect(page).to have_content I18n.t('callbacks.authenticatable.failure')
24
24
  end
25
25
 
26
26
  def expect_user_to_be_signed_out
27
27
  expect(page).to have_content 'Sign in'
28
28
  end
29
+
30
+ def expect_path_is_redirect_url
31
+ expect(current_path).to eq(Authenticate.configuration.redirect_url)
32
+ end
29
33
  end
30
34
  end
31
35
 
@@ -0,0 +1,6 @@
1
+ # Hacky monkey patch, do later deliveries right now, so
2
+ class ActionMailer::MessageDelivery
3
+ def deliver_later
4
+ deliver_now
5
+ end
6
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authenticate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Tomich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-27 00:00:00.000000000 Z
11
+ date: 2017-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcrypt
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.1'
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.1'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: email_validator
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -64,28 +64,28 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '4.4'
67
+ version: '4.8'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '4.4'
74
+ version: '4.8'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rspec-rails
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '3.1'
81
+ version: '3.6'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '3.1'
88
+ version: '3.6'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: pry
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -134,14 +134,14 @@ dependencies:
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: '2.6'
137
+ version: '2.14'
138
138
  type: :development
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: '2.6'
144
+ version: '2.14'
145
145
  - !ruby/object:Gem::Dependency
146
146
  name: database_cleaner
147
147
  requirement: !ruby/object:Gem::Requirement
@@ -170,6 +170,34 @@ dependencies:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0.8'
173
+ - !ruby/object:Gem::Dependency
174
+ name: appraisal
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ - !ruby/object:Gem::Dependency
188
+ name: rake
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ type: :development
195
+ prerelease: false
196
+ version_requirements: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
173
201
  description: Authentication for Rails applications
174
202
  email:
175
203
  - justin@tomich.org
@@ -186,6 +214,7 @@ files:
186
214
  - ".rubocop.yml"
187
215
  - ".ruby-version"
188
216
  - ".travis.yml"
217
+ - Appraisals
189
218
  - CHANGELOG.md
190
219
  - CONTRIBUTING.md
191
220
  - Gemfile
@@ -206,9 +235,11 @@ files:
206
235
  - app/views/users/new.html.erb
207
236
  - authenticate.gemspec
208
237
  - bin/rails
238
+ - bin/setup
209
239
  - config/locales/authenticate.en.yml
210
240
  - config/routes.rb
211
- - gemfiles/rails42.gemfile
241
+ - gemfiles/4.2.gemfile
242
+ - gemfiles/5.0.gemfile
212
243
  - lib/authenticate.rb
213
244
  - lib/authenticate/callbacks/authenticatable.rb
214
245
  - lib/authenticate/callbacks/brute_force.rb
@@ -253,10 +284,7 @@ files:
253
284
  - lib/generators/authenticate/views/USAGE
254
285
  - lib/generators/authenticate/views/views_generator.rb
255
286
  - lib/tasks/authenticate_tasks.rake
256
- - spec/controllers/passwords_controller_spec.rb
257
287
  - spec/controllers/secured_controller_spec.rb
258
- - spec/controllers/sessions_controller_spec.rb
259
- - spec/controllers/users_controller_spec.rb
260
288
  - spec/dummy/README.rdoc
261
289
  - spec/dummy/Rakefile
262
290
  - spec/dummy/app/assets/images/.keep
@@ -309,7 +337,9 @@ files:
309
337
  - spec/dummy/public/favicon.ico
310
338
  - spec/factories/users.rb
311
339
  - spec/features/brute_force_spec.rb
340
+ - spec/features/create_user_spec.rb
312
341
  - spec/features/max_session_lifetime_spec.rb
342
+ - spec/features/new_user_form_spec.rb
313
343
  - spec/features/password_reset_spec.rb
314
344
  - spec/features/password_update_spec.rb
315
345
  - spec/features/sign_in_spec.rb
@@ -329,9 +359,12 @@ files:
329
359
  - spec/model/trackable_spec.rb
330
360
  - spec/model/user_spec.rb
331
361
  - spec/orm/active_record.rb
362
+ - spec/requests/csrf_rotation_spec.rb
363
+ - spec/requests/session_key_spec.rb
332
364
  - spec/spec_helper.rb
333
365
  - spec/support/controllers/controller_helpers.rb
334
366
  - spec/support/features/feature_helpers.rb
367
+ - spec/support/mailer.rb
335
368
  homepage: http://github.com/tomichj/authenticate
336
369
  licenses:
337
370
  - MIT
@@ -353,7 +386,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
353
386
  version: '0'
354
387
  requirements: []
355
388
  rubyforge_project:
356
- rubygems_version: 2.5.1
389
+ rubygems_version: 2.6.11
357
390
  signing_key:
358
391
  specification_version: 4
359
392
  summary: Authentication for Rails applications
@@ -1,17 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem 'shoulda-matchers', '~> 2.8'
6
- gem 'capybara', '~> 2.6.2'
7
- gem 'database_cleaner', '~> 1.5.1'
8
- gem 'timecop', '~> 0.8.0'
9
-
10
- gem "bundler", "~> 1.3"
11
- gem "factory_girl", "~> 4.4"
12
- gem "rspec-rails", "~> 3.1"
13
- gem "sqlite3", "~> 1.3"
14
- gem "pry", :require => false
15
- gem "rails", "~> 4.2.0"
16
-
17
- gemspec :path => "../"
@@ -1,117 +0,0 @@
1
- require 'spec_helper'
2
- require 'support/controllers/controller_helpers'
3
-
4
- describe Authenticate::PasswordsController, type: :controller do
5
- it { is_expected.to be_a Authenticate::Controller }
6
-
7
- describe 'get to #new' do
8
- it 'renders the new form' do
9
- get :new
10
- expect(response).to be_success
11
- expect(response).to render_template(:new)
12
- end
13
- end
14
-
15
- describe 'post to #create' do
16
- context 'with email for an existing user' do
17
- it 'generates a password_reset_token' do
18
- user = create(:user)
19
- post :create, password: { email: user.email.upcase }
20
- expect(user.reload.password_reset_token).not_to be_nil
21
- end
22
- it 'sends a password reset email' do
23
- ActionMailer::Base.deliveries.clear
24
- user = create(:user)
25
- post :create, password: { email: user.email }
26
- email = ActionMailer::Base.deliveries.last
27
- expect(email.subject).to match(/change your password/i)
28
- end
29
- end
30
- context 'with email that does not belong to an existing user' do
31
- bad_email = 'bunk_email_address@non_existent_domain.com'
32
- it 'does not send an email' do
33
- ActionMailer::Base.deliveries.clear
34
- post :create, password: { email: bad_email }
35
- expect(ActionMailer::Base.deliveries).to be_empty
36
- end
37
- it 'always responds with redirect to avoid leaking user information' do
38
- post :create, password: { email: bad_email }
39
- expect(response).to be_redirect
40
- end
41
- end
42
- end
43
-
44
- describe 'get to #edit' do
45
- context 'with a valid password_reset_token and timestamp' do
46
- it 'renders password update form' do
47
- user = create(:user, :with_password_reset_token_and_timestamp)
48
- get :edit, id: user.id, token: user.password_reset_token
49
- expect(response).to be_success
50
- expect(response).to render_template(:edit)
51
- expect(assigns(:user)).to eq user
52
- end
53
- end
54
- context 'with a valid timestamp but invalid password_reset_token' do
55
- it 'renders #new password form with notice' do
56
- user = create(:user, :with_password_reset_token_and_timestamp)
57
- get :edit, id: user.id, token: 'bad token'
58
- expect(response).to be_success
59
- expect(response).to render_template(:new)
60
- end
61
- end
62
- context 'with a valid password_reset_token but invalid timestamp' do
63
- it 'renders #new password form with notice' do
64
- user = create(:user, :with_password_reset_token_and_timestamp, password_reset_sent_at: 2.years.ago)
65
- get :edit, id: user.id, token: user.password_reset_token
66
- expect(response).to be_redirect
67
- expect(flash[:notice]).to match(/password change request has expired/)
68
- end
69
- end
70
- context 'with a blank password_reset_token' do
71
- it 'renders #new password form with notice' do
72
- user = create(:user)
73
- get :edit, id: user.id, token: nil
74
- expect(response).to be_success
75
- expect(response).to render_template(:new)
76
- end
77
- end
78
- end
79
-
80
- describe 'put to #update' do
81
- context 'with valid password_reset_token and new password' do
82
- it 'updates the user password' do
83
- user = create(:user, :with_password_reset_token_and_timestamp)
84
- old_encrypted_password = user.encrypted_password
85
- put :update, update_params(user, new_password: 'new_password')
86
- expect(user.reload.encrypted_password).not_to eq old_encrypted_password
87
- end
88
- it 'signs in the user' do
89
- user = create(:user, :with_password_reset_token_and_timestamp)
90
- put :update, update_params(user, new_password: 'new_password')
91
- expect(cookies[:authenticate_session_token]).to be_present
92
- expect(cookies[:authenticate_session_token]).to eq user.reload.session_token
93
- end
94
- it 'redirects user' do
95
- user = create(:user, :with_password_reset_token_and_timestamp)
96
- put :update, update_params(user, new_password: 'new_password')
97
- expect(response).to redirect_to(Authenticate.configuration.redirect_url)
98
- end
99
- end
100
- context 'with invalid new password' do
101
- it 're-renders password edit form' do
102
- user = create(:user, :with_password_reset_token_and_timestamp)
103
- put :update, update_params(user, new_password: 'short')
104
- expect(response).to render_template(:edit)
105
- end
106
- end
107
- end
108
-
109
- def update_params(user, options = {})
110
- new_password = options.fetch(:new_password)
111
- {
112
- id: user,
113
- token: user.password_reset_token,
114
- password_reset: { password: new_password }
115
- }
116
- end
117
- end
@@ -1,86 +0,0 @@
1
- require 'spec_helper'
2
- require 'support/controllers/controller_helpers'
3
-
4
- describe Authenticate::SessionsController, type: :controller do
5
- it { is_expected.to be_a Authenticate::Controller }
6
-
7
- describe 'get to #new' do
8
- context 'when user not signed in' do
9
- before do
10
- get :new
11
- end
12
- it { is_expected.to respond_with 200 }
13
- it { is_expected.to render_template :new }
14
- it { is_expected.not_to set_flash }
15
- end
16
-
17
- context 'when user is signed in' do
18
- before do
19
- sign_in
20
- get :new
21
- end
22
-
23
- it { is_expected.not_to set_flash }
24
- it { is_expected.to redirect_to(Authenticate.configuration.redirect_url) }
25
- end
26
- end
27
-
28
- describe 'post to #create' do
29
- context 'without password' do
30
- it 'renders page with error' do
31
- user = create(:user)
32
- post :create, session: { email: user.email }
33
- expect(response).to render_template :new
34
- expect(flash[:notice]).to match(/Invalid id or password/)
35
- end
36
- end
37
- context 'with good password' do
38
- before do
39
- @user = create(:user)
40
- post :create, session: { email: @user.email, password: @user.password }
41
- end
42
- it { is_expected.to respond_with 302 }
43
-
44
- it { is_expected.to redirect_to Authenticate.configuration.redirect_url }
45
-
46
- it 'sets user session token' do
47
- @user.reload
48
- expect(@user.session_token).to_not be_nil
49
- end
50
-
51
- it 'sets user session' do
52
- expect(controller.current_user).to eq(@user)
53
- end
54
- end
55
- end
56
-
57
- describe 'delete to #destroy' do
58
- context 'with a signed out user' do
59
- before do
60
- sign_out
61
- get :destroy
62
- end
63
-
64
- it { is_expected.to redirect_to sign_in_url }
65
- end
66
-
67
- context 'with a session cookie' do
68
- before do
69
- @user = create(:user, session_token: 'old-session-token')
70
- @request.cookies['authenticate_session_token'] = 'old-session-token'
71
- get :destroy
72
- end
73
-
74
- it { is_expected.to redirect_to sign_in_url }
75
-
76
- it 'reset the session token' do
77
- @user.reload
78
- expect(@user.session_token).to_not eq('old-session-token')
79
- end
80
-
81
- it 'unset the current user' do
82
- expect(controller.current_user).to be_nil
83
- end
84
- end
85
- end
86
- end