two_factor_authentication 1.1.5 → 2.0.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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +21 -0
  3. data/.rubocop.yml +295 -0
  4. data/.travis.yml +4 -5
  5. data/CHANGELOG.md +24 -14
  6. data/README.md +57 -65
  7. data/app/controllers/devise/two_factor_authentication_controller.rb +28 -12
  8. data/app/views/devise/two_factor_authentication/show.html.erb +10 -1
  9. data/config/locales/en.yml +1 -0
  10. data/config/locales/es.yml +8 -0
  11. data/config/locales/fr.yml +1 -0
  12. data/config/locales/ru.yml +1 -0
  13. data/lib/generators/active_record/templates/migration.rb +3 -0
  14. data/lib/two_factor_authentication.rb +9 -0
  15. data/lib/two_factor_authentication/controllers/helpers.rb +1 -1
  16. data/lib/two_factor_authentication/hooks/two_factor_authenticatable.rb +4 -23
  17. data/lib/two_factor_authentication/models/two_factor_authenticatable.rb +68 -19
  18. data/lib/two_factor_authentication/routes.rb +3 -1
  19. data/lib/two_factor_authentication/schema.rb +12 -0
  20. data/lib/two_factor_authentication/version.rb +1 -1
  21. data/spec/controllers/two_factor_authentication_controller_spec.rb +2 -2
  22. data/spec/features/two_factor_authenticatable_spec.rb +36 -73
  23. data/spec/lib/two_factor_authentication/models/two_factor_authenticatable_spec.rb +137 -80
  24. data/spec/rails_app/app/controllers/home_controller.rb +1 -1
  25. data/spec/rails_app/app/models/admin.rb +6 -0
  26. data/spec/rails_app/app/models/encrypted_user.rb +2 -1
  27. data/spec/rails_app/app/models/guest_user.rb +8 -1
  28. data/spec/rails_app/app/models/user.rb +2 -2
  29. data/spec/rails_app/config/initializers/devise.rb +2 -2
  30. data/spec/rails_app/config/routes.rb +1 -0
  31. data/spec/rails_app/db/migrate/20140403184646_devise_create_users.rb +1 -1
  32. data/spec/rails_app/db/migrate/20160209032439_devise_create_admins.rb +42 -0
  33. data/spec/rails_app/db/schema.rb +19 -1
  34. data/spec/support/authenticated_model_helper.rb +22 -15
  35. data/spec/support/controller_helper.rb +1 -1
  36. data/spec/support/totp_helper.rb +11 -0
  37. data/two_factor_authentication.gemspec +1 -1
  38. metadata +74 -7
@@ -9,6 +9,10 @@ module AuthenticatedModelHelper
9
9
  User.create!(valid_attributes(attributes))
10
10
  end
11
11
 
12
+ def create_admin
13
+ Admin.create!(valid_attributes.except(:nickname))
14
+ end
15
+
12
16
  def valid_attributes(attributes={})
13
17
  {
14
18
  nickname: 'Marissa',
@@ -28,21 +32,24 @@ module AuthenticatedModelHelper
28
32
  silence_stream(STDOUT) do
29
33
  ActiveRecord::Schema.define(version: 1) do
30
34
  create_table 'users', force: :cascade do |t|
31
- t.string 'email', default: '', null: false
32
- t.string 'encrypted_password', default: '', null: false
33
- t.string 'reset_password_token'
34
- t.datetime 'reset_password_sent_at'
35
- t.datetime 'remember_created_at'
36
- t.integer 'sign_in_count', default: 0, null: false
37
- t.datetime 'current_sign_in_at'
38
- t.datetime 'last_sign_in_at'
39
- t.string 'current_sign_in_ip'
40
- t.string 'last_sign_in_ip'
41
- t.datetime 'created_at', null: false
42
- t.datetime 'updated_at', null: false
43
- t.integer 'second_factor_attempts_count', default: 0
44
- t.string 'nickname', limit: 64
45
- t.string 'otp_secret_key'
35
+ t.string 'email', default: '', null: false
36
+ t.string 'encrypted_password', default: '', null: false
37
+ t.string 'reset_password_token'
38
+ t.datetime 'reset_password_sent_at'
39
+ t.datetime 'remember_created_at'
40
+ t.integer 'sign_in_count', default: 0, null: false
41
+ t.datetime 'current_sign_in_at'
42
+ t.datetime 'last_sign_in_at'
43
+ t.string 'current_sign_in_ip'
44
+ t.string 'last_sign_in_ip'
45
+ t.datetime 'created_at', null: false
46
+ t.datetime 'updated_at', null: false
47
+ t.integer 'second_factor_attempts_count', default: 0
48
+ t.string 'nickname', limit: 64
49
+ t.string 'otp_secret_key'
50
+ t.string 'direct_otp'
51
+ t.datetime 'direct_otp_sent_at'
52
+ t.timestamp 'totp_timestamp'
46
53
  end
47
54
  end
48
55
  end
@@ -7,7 +7,7 @@ module ControllerHelper
7
7
  end
8
8
 
9
9
  RSpec.configure do |config|
10
- config.include Devise::TestHelpers, type: :controller
10
+ config.include Devise::Test::ControllerHelpers, type: :controller
11
11
  config.include ControllerHelper, type: :controller
12
12
 
13
13
  config.before(:example, type: :controller) do
@@ -0,0 +1,11 @@
1
+ # Helper class to simulate a user generating TOTP codes from a secret key
2
+ class TotpHelper
3
+ def initialize(secret_key, otp_length)
4
+ @secret_key = secret_key
5
+ @otp_length = otp_length
6
+ end
7
+
8
+ def totp_code(time = Time.now)
9
+ ROTP::TOTP.new(@secret_key, digits: @otp_length).at(time, true)
10
+ end
11
+ end
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.add_runtime_dependency 'rails', '>= 3.1.1'
28
28
  s.add_runtime_dependency 'devise'
29
29
  s.add_runtime_dependency 'randexp'
30
- s.add_runtime_dependency 'rotp'
30
+ s.add_runtime_dependency 'rotp', '>= 3.2.0'
31
31
  s.add_runtime_dependency 'encryptor'
32
32
 
33
33
  s.add_development_dependency 'bundler'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: two_factor_authentication
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitrii Golub
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-01 00:00:00.000000000 Z
11
+ date: 2017-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 3.2.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 3.2.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: encryptor
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -176,7 +176,9 @@ executables: []
176
176
  extensions: []
177
177
  extra_rdoc_files: []
178
178
  files:
179
+ - ".codeclimate.yml"
179
180
  - ".gitignore"
181
+ - ".rubocop.yml"
180
182
  - ".travis.yml"
181
183
  - CHANGELOG.md
182
184
  - Gemfile
@@ -187,6 +189,7 @@ files:
187
189
  - app/views/devise/two_factor_authentication/max_login_attempts_reached.html.erb
188
190
  - app/views/devise/two_factor_authentication/show.html.erb
189
191
  - config/locales/en.yml
192
+ - config/locales/es.yml
190
193
  - config/locales/fr.yml
191
194
  - config/locales/ru.yml
192
195
  - lib/generators/active_record/templates/migration.rb
@@ -215,6 +218,7 @@ files:
215
218
  - spec/rails_app/app/helpers/application_helper.rb
216
219
  - spec/rails_app/app/mailers/.gitkeep
217
220
  - spec/rails_app/app/models/.gitkeep
221
+ - spec/rails_app/app/models/admin.rb
218
222
  - spec/rails_app/app/models/encrypted_user.rb
219
223
  - spec/rails_app/app/models/guest_user.rb
220
224
  - spec/rails_app/app/models/user.rb
@@ -246,6 +250,7 @@ files:
246
250
  - spec/rails_app/db/migrate/20151224171231_add_encrypted_columns_to_user.rb
247
251
  - spec/rails_app/db/migrate/20151224180310_populate_otp_column.rb
248
252
  - spec/rails_app/db/migrate/20151228230340_remove_otp_secret_key_from_user.rb
253
+ - spec/rails_app/db/migrate/20160209032439_devise_create_admins.rb
249
254
  - spec/rails_app/db/schema.rb
250
255
  - spec/rails_app/lib/assets/.gitkeep
251
256
  - spec/rails_app/lib/sms_provider.rb
@@ -260,6 +265,7 @@ files:
260
265
  - spec/support/controller_helper.rb
261
266
  - spec/support/features_spec_helper.rb
262
267
  - spec/support/sms_provider.rb
268
+ - spec/support/totp_helper.rb
263
269
  - two_factor_authentication.gemspec
264
270
  homepage: https://github.com/Houdini/two_factor_authentication
265
271
  licenses: []
@@ -280,9 +286,70 @@ required_rubygems_version: !ruby/object:Gem::Requirement
280
286
  version: '0'
281
287
  requirements: []
282
288
  rubyforge_project: two_factor_authentication
283
- rubygems_version: 2.5.0
289
+ rubygems_version: 2.6.12
284
290
  signing_key:
285
291
  specification_version: 4
286
292
  summary: Two factor authentication plugin for devise
287
- test_files: []
288
- has_rdoc:
293
+ test_files:
294
+ - spec/controllers/two_factor_authentication_controller_spec.rb
295
+ - spec/features/two_factor_authenticatable_spec.rb
296
+ - spec/generators/active_record/two_factor_authentication_generator_spec.rb
297
+ - spec/lib/two_factor_authentication/models/two_factor_authenticatable_spec.rb
298
+ - spec/rails_app/.gitignore
299
+ - spec/rails_app/README.md
300
+ - spec/rails_app/Rakefile
301
+ - spec/rails_app/app/assets/javascripts/application.js
302
+ - spec/rails_app/app/assets/stylesheets/application.css
303
+ - spec/rails_app/app/controllers/application_controller.rb
304
+ - spec/rails_app/app/controllers/home_controller.rb
305
+ - spec/rails_app/app/helpers/application_helper.rb
306
+ - spec/rails_app/app/mailers/.gitkeep
307
+ - spec/rails_app/app/models/.gitkeep
308
+ - spec/rails_app/app/models/admin.rb
309
+ - spec/rails_app/app/models/encrypted_user.rb
310
+ - spec/rails_app/app/models/guest_user.rb
311
+ - spec/rails_app/app/models/user.rb
312
+ - spec/rails_app/app/views/home/dashboard.html.erb
313
+ - spec/rails_app/app/views/home/index.html.erb
314
+ - spec/rails_app/app/views/layouts/application.html.erb
315
+ - spec/rails_app/config.ru
316
+ - spec/rails_app/config/application.rb
317
+ - spec/rails_app/config/boot.rb
318
+ - spec/rails_app/config/database.yml
319
+ - spec/rails_app/config/environment.rb
320
+ - spec/rails_app/config/environments/development.rb
321
+ - spec/rails_app/config/environments/production.rb
322
+ - spec/rails_app/config/environments/test.rb
323
+ - spec/rails_app/config/initializers/backtrace_silencers.rb
324
+ - spec/rails_app/config/initializers/cookies_serializer.rb
325
+ - spec/rails_app/config/initializers/devise.rb
326
+ - spec/rails_app/config/initializers/inflections.rb
327
+ - spec/rails_app/config/initializers/mime_types.rb
328
+ - spec/rails_app/config/initializers/secret_token.rb
329
+ - spec/rails_app/config/initializers/session_store.rb
330
+ - spec/rails_app/config/initializers/wrap_parameters.rb
331
+ - spec/rails_app/config/locales/devise.en.yml
332
+ - spec/rails_app/config/locales/en.yml
333
+ - spec/rails_app/config/routes.rb
334
+ - spec/rails_app/db/migrate/20140403184646_devise_create_users.rb
335
+ - spec/rails_app/db/migrate/20140407172619_two_factor_authentication_add_to_users.rb
336
+ - spec/rails_app/db/migrate/20140407215513_add_nickanme_to_users.rb
337
+ - spec/rails_app/db/migrate/20151224171231_add_encrypted_columns_to_user.rb
338
+ - spec/rails_app/db/migrate/20151224180310_populate_otp_column.rb
339
+ - spec/rails_app/db/migrate/20151228230340_remove_otp_secret_key_from_user.rb
340
+ - spec/rails_app/db/migrate/20160209032439_devise_create_admins.rb
341
+ - spec/rails_app/db/schema.rb
342
+ - spec/rails_app/lib/assets/.gitkeep
343
+ - spec/rails_app/lib/sms_provider.rb
344
+ - spec/rails_app/public/404.html
345
+ - spec/rails_app/public/422.html
346
+ - spec/rails_app/public/500.html
347
+ - spec/rails_app/public/favicon.ico
348
+ - spec/rails_app/script/rails
349
+ - spec/spec_helper.rb
350
+ - spec/support/authenticated_model_helper.rb
351
+ - spec/support/capybara.rb
352
+ - spec/support/controller_helper.rb
353
+ - spec/support/features_spec_helper.rb
354
+ - spec/support/sms_provider.rb
355
+ - spec/support/totp_helper.rb