devise-authy 1.8.3 → 1.9.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 (157) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +44 -0
  3. data/CHANGELOG.md +11 -0
  4. data/Gemfile +1 -12
  5. data/README.md +5 -3
  6. data/Rakefile +1 -14
  7. data/devise-authy.gemspec +34 -237
  8. data/lib/devise-authy.rb +1 -0
  9. data/lib/devise-authy/version.rb +5 -0
  10. data/lib/generators/active_record/devise_authy_generator.rb +11 -1
  11. data/lib/generators/active_record/templates/migration.rb +1 -1
  12. metadata +42 -195
  13. data/VERSION +0 -1
  14. data/authy-devise-demo/.gitignore +0 -15
  15. data/authy-devise-demo/Gemfile +0 -51
  16. data/authy-devise-demo/Gemfile.lock +0 -194
  17. data/authy-devise-demo/README.md +0 -64
  18. data/authy-devise-demo/Rakefile +0 -7
  19. data/authy-devise-demo/app/assets/images/rails.png +0 -0
  20. data/authy-devise-demo/app/assets/javascripts/application.js +0 -15
  21. data/authy-devise-demo/app/assets/javascripts/devise_authy.js +0 -12
  22. data/authy-devise-demo/app/assets/javascripts/welcome.js.coffee +0 -3
  23. data/authy-devise-demo/app/assets/stylesheets/application.css +0 -13
  24. data/authy-devise-demo/app/assets/stylesheets/devise_authy.css +0 -26
  25. data/authy-devise-demo/app/assets/stylesheets/welcome.css.scss +0 -3
  26. data/authy-devise-demo/app/controllers/application_controller.rb +0 -3
  27. data/authy-devise-demo/app/controllers/welcome_controller.rb +0 -15
  28. data/authy-devise-demo/app/helpers/application_helper.rb +0 -2
  29. data/authy-devise-demo/app/helpers/welcome_helper.rb +0 -2
  30. data/authy-devise-demo/app/mailers/.gitkeep +0 -0
  31. data/authy-devise-demo/app/models/.gitkeep +0 -0
  32. data/authy-devise-demo/app/models/admin.rb +0 -7
  33. data/authy-devise-demo/app/models/user.rb +0 -7
  34. data/authy-devise-demo/app/views/devise/devise_authy/enable_authy.html.erb +0 -7
  35. data/authy-devise-demo/app/views/devise/devise_authy/verify_authy.html.erb +0 -38
  36. data/authy-devise-demo/app/views/devise/devise_authy/verify_authy_installation.html.erb +0 -10
  37. data/authy-devise-demo/app/views/layouts/application.html.erb +0 -28
  38. data/authy-devise-demo/app/views/welcome/admin_page.html.erb +0 -12
  39. data/authy-devise-demo/app/views/welcome/index.html.erb +0 -5
  40. data/authy-devise-demo/app/views/welcome/user_page.html.erb +0 -5
  41. data/authy-devise-demo/config.ru +0 -4
  42. data/authy-devise-demo/config/application.rb +0 -26
  43. data/authy-devise-demo/config/boot.rb +0 -6
  44. data/authy-devise-demo/config/database.yml +0 -25
  45. data/authy-devise-demo/config/environment.rb +0 -5
  46. data/authy-devise-demo/config/environments/development.rb +0 -43
  47. data/authy-devise-demo/config/environments/production.rb +0 -79
  48. data/authy-devise-demo/config/environments/test.rb +0 -42
  49. data/authy-devise-demo/config/initializers/authy.rb +0 -1
  50. data/authy-devise-demo/config/initializers/backtrace_silencers.rb +0 -7
  51. data/authy-devise-demo/config/initializers/devise.rb +0 -240
  52. data/authy-devise-demo/config/initializers/inflections.rb +0 -15
  53. data/authy-devise-demo/config/initializers/mime_types.rb +0 -5
  54. data/authy-devise-demo/config/initializers/secret_token.rb +0 -7
  55. data/authy-devise-demo/config/initializers/session_store.rb +0 -8
  56. data/authy-devise-demo/config/initializers/wrap_parameters.rb +0 -14
  57. data/authy-devise-demo/config/locales/devise.authy.en.yml +0 -24
  58. data/authy-devise-demo/config/locales/devise.en.yml +0 -58
  59. data/authy-devise-demo/config/locales/en.yml +0 -5
  60. data/authy-devise-demo/config/routes.rb +0 -65
  61. data/authy-devise-demo/config/secrets.yml +0 -22
  62. data/authy-devise-demo/db/migrate/20130409234357_devise_create_users.rb +0 -46
  63. data/authy-devise-demo/db/migrate/20141202000744_devise_create_admins.rb +0 -46
  64. data/authy-devise-demo/db/migrate/20141202004246_devise_authy_add_to_admins.rb +0 -21
  65. data/authy-devise-demo/db/migrate/20160906221739_add_sessions_table.rb +0 -12
  66. data/authy-devise-demo/db/schema.rb +0 -72
  67. data/authy-devise-demo/db/seeds.rb +0 -7
  68. data/authy-devise-demo/lib/assets/.gitkeep +0 -0
  69. data/authy-devise-demo/lib/tasks/.gitkeep +0 -0
  70. data/authy-devise-demo/log/.gitkeep +0 -0
  71. data/authy-devise-demo/public/404.html +0 -26
  72. data/authy-devise-demo/public/422.html +0 -26
  73. data/authy-devise-demo/public/500.html +0 -25
  74. data/authy-devise-demo/public/favicon.ico +0 -0
  75. data/authy-devise-demo/public/robots.txt +0 -5
  76. data/authy-devise-demo/script/rails +0 -6
  77. data/authy-devise-demo/test/fixtures/.gitkeep +0 -0
  78. data/authy-devise-demo/test/fixtures/users.yml +0 -11
  79. data/authy-devise-demo/test/functional/.gitkeep +0 -0
  80. data/authy-devise-demo/test/functional/welcome_controller_test.rb +0 -9
  81. data/authy-devise-demo/test/integration/.gitkeep +0 -0
  82. data/authy-devise-demo/test/performance/browsing_test.rb +0 -12
  83. data/authy-devise-demo/test/test_helper.rb +0 -13
  84. data/authy-devise-demo/test/unit/.gitkeep +0 -0
  85. data/authy-devise-demo/test/unit/helpers/welcome_helper_test.rb +0 -4
  86. data/authy-devise-demo/test/unit/user_test.rb +0 -7
  87. data/authy-devise-demo/vendor/assets/javascripts/.gitkeep +0 -0
  88. data/authy-devise-demo/vendor/assets/stylesheets/.gitkeep +0 -0
  89. data/authy-devise-demo/vendor/plugins/.gitkeep +0 -0
  90. data/spec/controllers/devise_authy_controller_spec.rb +0 -360
  91. data/spec/controllers/passwords_controller_spec.rb +0 -48
  92. data/spec/features/authy_authenticatable_spec.rb +0 -108
  93. data/spec/features/authy_lockable_spec.rb +0 -70
  94. data/spec/generators_spec.rb +0 -32
  95. data/spec/models/authy_authenticatable_spec.rb +0 -17
  96. data/spec/models/authy_lockable_spec.rb +0 -81
  97. data/spec/orm/active_record.rb +0 -4
  98. data/spec/rails-app/Gemfile +0 -10
  99. data/spec/rails-app/Gemfile.lock +0 -141
  100. data/spec/rails-app/Rakefile +0 -7
  101. data/spec/rails-app/app/assets/images/rails.png +0 -0
  102. data/spec/rails-app/app/assets/javascripts/application.js +0 -15
  103. data/spec/rails-app/app/assets/javascripts/devise_authy.js +0 -12
  104. data/spec/rails-app/app/assets/javascripts/welcome.js +0 -2
  105. data/spec/rails-app/app/assets/stylesheets/application.css +0 -13
  106. data/spec/rails-app/app/assets/stylesheets/devise_authy.css +0 -26
  107. data/spec/rails-app/app/assets/stylesheets/welcome.css.scss +0 -3
  108. data/spec/rails-app/app/controllers/application_controller.rb +0 -3
  109. data/spec/rails-app/app/controllers/welcome_controller.rb +0 -13
  110. data/spec/rails-app/app/helpers/application_helper.rb +0 -2
  111. data/spec/rails-app/app/helpers/welcome_helper.rb +0 -2
  112. data/spec/rails-app/app/mailers/.gitkeep +0 -0
  113. data/spec/rails-app/app/models/.gitkeep +0 -0
  114. data/spec/rails-app/app/models/lockable_user.rb +0 -7
  115. data/spec/rails-app/app/models/user.rb +0 -8
  116. data/spec/rails-app/app/views/devise/devise_authy/enable_authy.html.erb +0 -7
  117. data/spec/rails-app/app/views/devise/devise_authy/verify_authy.html.erb +0 -37
  118. data/spec/rails-app/app/views/devise/devise_authy/verify_authy_installation.html.erb +0 -10
  119. data/spec/rails-app/app/views/layouts/application.html.erb +0 -28
  120. data/spec/rails-app/app/views/welcome/index.html.erb +0 -5
  121. data/spec/rails-app/config.ru +0 -4
  122. data/spec/rails-app/config/application.rb +0 -30
  123. data/spec/rails-app/config/boot.rb +0 -6
  124. data/spec/rails-app/config/database.yml +0 -25
  125. data/spec/rails-app/config/environment.rb +0 -5
  126. data/spec/rails-app/config/environments/development.rb +0 -43
  127. data/spec/rails-app/config/environments/production.rb +0 -79
  128. data/spec/rails-app/config/environments/test.rb +0 -44
  129. data/spec/rails-app/config/initializers/authy.rb +0 -2
  130. data/spec/rails-app/config/initializers/backtrace_silencers.rb +0 -7
  131. data/spec/rails-app/config/initializers/devise.rb +0 -256
  132. data/spec/rails-app/config/initializers/inflections.rb +0 -15
  133. data/spec/rails-app/config/initializers/mime_types.rb +0 -5
  134. data/spec/rails-app/config/initializers/secret_token.rb +0 -7
  135. data/spec/rails-app/config/initializers/session_store.rb +0 -8
  136. data/spec/rails-app/config/initializers/wrap_parameters.rb +0 -14
  137. data/spec/rails-app/config/locales/devise.authy.en.yml +0 -24
  138. data/spec/rails-app/config/locales/devise.en.yml +0 -59
  139. data/spec/rails-app/config/locales/en.yml +0 -5
  140. data/spec/rails-app/config/routes.rb +0 -8
  141. data/spec/rails-app/config/secrets.yml +0 -22
  142. data/spec/rails-app/db/development.sqlite3 +0 -0
  143. data/spec/rails-app/db/migrate/20130419164907_devise_create_users.rb +0 -46
  144. data/spec/rails-app/db/migrate/20130419164936_devise_authy_add_to_users.rb +0 -18
  145. data/spec/rails-app/db/schema.rb +0 -41
  146. data/spec/rails-app/db/seeds.rb +0 -7
  147. data/spec/rails-app/lib/assets/.gitkeep +0 -0
  148. data/spec/rails-app/lib/tasks/.gitkeep +0 -0
  149. data/spec/rails-app/public/404.html +0 -26
  150. data/spec/rails-app/public/422.html +0 -26
  151. data/spec/rails-app/public/500.html +0 -25
  152. data/spec/rails-app/public/favicon.ico +0 -0
  153. data/spec/rails-app/public/robots.txt +0 -5
  154. data/spec/rails-app/script/rails +0 -6
  155. data/spec/routing/routes_spec.rb +0 -35
  156. data/spec/spec_helper.rb +0 -46
  157. data/spec/support/helpers.rb +0 -80
File without changes
@@ -1,5 +0,0 @@
1
- # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
- #
3
- # To ban all spiders from the entire site uncomment the next two lines:
4
- # User-Agent: *
5
- # Disallow: /
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
-
4
- APP_PATH = File.expand_path('../../config/application', __FILE__)
5
- require File.expand_path('../../config/boot', __FILE__)
6
- require 'rails/commands'
File without changes
@@ -1,11 +0,0 @@
1
- # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
-
3
- # This model initially had no columns defined. If you add columns to the
4
- # model remove the '{}' from the fixture names and add the columns immediately
5
- # below each fixture, per the syntax in the comments below
6
- #
7
- one: {}
8
- # column: value
9
- #
10
- two: {}
11
- # column: value
@@ -1,9 +0,0 @@
1
- require 'test_helper'
2
-
3
- class WelcomeControllerTest < ActionController::TestCase
4
- test "should get index" do
5
- get :index
6
- assert_response :success
7
- end
8
-
9
- end
@@ -1,12 +0,0 @@
1
- require 'test_helper'
2
- require 'rails/performance_test_help'
3
-
4
- class BrowsingTest < ActionDispatch::PerformanceTest
5
- # Refer to the documentation for all available options
6
- # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
7
- # :output => 'tmp/performance', :formats => [:flat] }
8
-
9
- def test_homepage
10
- get '/'
11
- end
12
- end
@@ -1,13 +0,0 @@
1
- ENV["RAILS_ENV"] = "test"
2
- require File.expand_path('../../config/environment', __FILE__)
3
- require 'rails/test_help'
4
-
5
- class ActiveSupport::TestCase
6
- # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
7
- #
8
- # Note: You'll currently still have to declare fixtures explicitly in integration tests
9
- # -- they do not yet inherit this setting
10
- fixtures :all
11
-
12
- # Add more helper methods to be used by all tests here...
13
- end
File without changes
@@ -1,4 +0,0 @@
1
- require 'test_helper'
2
-
3
- class WelcomeHelperTest < ActionView::TestCase
4
- end
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class UserTest < ActiveSupport::TestCase
4
- # test "the truth" do
5
- # assert true
6
- # end
7
- end
File without changes
@@ -1,360 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Devise::DeviseAuthyController, type: :controller do
4
- include Devise::Test::ControllerHelpers
5
-
6
- before :each do
7
- request.env["devise.mapping"] = Devise.mappings[:user]
8
- @user = create_user(:authy_id => 2)
9
- end
10
-
11
- describe "GET #verify_authy" do
12
- describe "when the first step of authentication is complete" do
13
- before do
14
- request.session["user_id"] = @user.id
15
- request.session["user_password_checked"] = true
16
- end
17
-
18
- it "Should render the second step of authentication" do
19
- get :GET_verify_authy
20
- expect(response).to render_template('verify_authy')
21
- end
22
-
23
- it "should not make a OneTouch request" do
24
- expect(Authy::OneTouch).not_to receive(:send_approval_request)
25
- get :GET_verify_authy
26
- end
27
-
28
- describe "when OneTouch is enabled" do
29
- before do
30
- allow(User).to receive(:authy_enable_onetouch).and_return(true)
31
- end
32
-
33
- it "should make a OneTouch request" do
34
- expect(Authy::OneTouch).to receive(:send_approval_request)
35
- .with(id: @user.authy_id, message: 'Request to Login')
36
- .and_return('approval_request' => { 'uuid' => 'uuid' }).once
37
- get :GET_verify_authy
38
- end
39
- end
40
- end
41
-
42
- it "Should no render the second step of authentication if first step is incomplete" do
43
- request.session["user_id"] = @user.id
44
- get :GET_verify_authy
45
- expect(response).to redirect_to(root_url)
46
- end
47
-
48
- it "should redirect to root_url" do
49
- get :GET_verify_authy
50
- expect(response).to redirect_to(root_url)
51
- end
52
-
53
- it "should not make a OneTouch request" do
54
- expect(Authy::OneTouch).not_to receive(:send_approval_request)
55
- get :GET_verify_authy
56
- end
57
- end
58
-
59
- describe "POST #verify_authy" do
60
- it "Should login the user if token is ok" do
61
- request.session["user_id"] = @user.id
62
- request.session["user_password_checked"] = true
63
-
64
- post :POST_verify_authy, :token => '0000000'
65
- @user.reload
66
- expect(@user.last_sign_in_with_authy).not_to be_nil
67
-
68
- expect(response.cookies["remember_device"]).to be_nil
69
- expect(response).to redirect_to(root_url)
70
- expect(flash.now[:notice]).not_to be_nil
71
- expect(session["user_authy_token_checked"]).to be_truthy
72
- end
73
-
74
- it "Should set remember_device if selected" do
75
- request.session["user_id"] = @user.id
76
- request.session["user_password_checked"] = true
77
-
78
- post :POST_verify_authy, :token => '0000000', :remember_device => '1'
79
- @user.reload
80
- expect(@user.last_sign_in_with_authy).not_to be_nil
81
-
82
- expect(response.cookies["remember_device"]).not_to be_nil
83
- expect(response).to redirect_to(root_url)
84
- expect(flash.now[:notice]).not_to be_nil
85
- end
86
-
87
- it "Shouldn't login the user if token is invalid" do
88
- request.session["user_id"] = @user.id
89
- request.session["user_password_checked"] = true
90
-
91
- post :POST_verify_authy, :token => '5678900'
92
- expect(response).to render_template('verify_authy')
93
- end
94
-
95
- context 'User is lockable' do
96
-
97
- let(:user) { create_lockable_user authy_id: 2 }
98
-
99
- before do
100
- allow(controller).to receive(:find_resource).and_return user
101
- controller.instance_variable_set :@resource, user
102
- end
103
-
104
- it 'locks the account when failed_attempts exceeds maximum' do
105
- request.session['user_id'] = user.id
106
- request.session['user_password_checked'] = true
107
-
108
- too_many_failed_attempts.times do
109
- post :POST_verify_authy, token: invalid_authy_token
110
- end
111
-
112
- user.reload
113
- expect(user.access_locked?).to be_truthy
114
- end
115
-
116
- end
117
-
118
- context 'User is not lockable' do
119
-
120
- it 'does not lock the account when failed_attempts exceeds maximum' do
121
- request.session['user_id'] = @user.id
122
- request.session['user_password_checked'] = true
123
-
124
- too_many_failed_attempts.times do
125
- post :POST_verify_authy, token: invalid_authy_token
126
- end
127
-
128
- @user.reload
129
- expect(@user.locked_at).to be_nil
130
- end
131
-
132
- end
133
-
134
- end
135
-
136
- describe "GET #enable_authy" do
137
- it "Should render enable authy view" do
138
- user2 = create_user
139
- sign_in user2
140
- get :GET_enable_authy
141
- expect(response).to render_template('enable_authy')
142
- end
143
-
144
- it "Shouldn't render enable authy view" do
145
- get :GET_enable_authy
146
- expect(response).to redirect_to(new_user_session_url)
147
- end
148
-
149
- it "should redirect if user has authy enabled" do
150
- @user.update_attribute(:authy_enabled, true)
151
- sign_in @user
152
- get :GET_enable_authy
153
- expect(response).to redirect_to(root_url)
154
- expect(flash.now[:notice]).to eq("Two factor authentication is already enabled.")
155
- end
156
-
157
- it "Should render enable authy view if authy enabled is false" do
158
- sign_in @user
159
- get :GET_enable_authy
160
- expect(response).to render_template('enable_authy')
161
- end
162
- end
163
-
164
- describe "POST #enable_authy" do
165
- it "Should create user in authy application" do
166
- user2 = create_user
167
- sign_in user2
168
-
169
- post :POST_enable_authy, :cellphone => '3010008090', :country_code => '57'
170
- user2.reload
171
- expect(user2.authy_id).not_to be_nil
172
- expect(flash.now[:notice]).to eq("Two factor authentication was enabled")
173
- expect(response).to redirect_to(user_verify_authy_installation_url)
174
- end
175
-
176
- it "Should not create user register user failed" do
177
- user2 = create_user
178
- sign_in user2
179
-
180
- post :POST_enable_authy, :cellphone => '22222', :country_code => "57"
181
- expect(response).to render_template('enable_authy')
182
- expect(flash[:error]).to eq("Something went wrong while enabling two factor authentication")
183
- end
184
-
185
- it "Should redirect if user isn't authenticated" do
186
- post :POST_enable_authy, :cellphone => '3010008090', :country_code => '57'
187
- expect(response).to redirect_to(new_user_session_url)
188
- end
189
- end
190
-
191
- describe "POST #disable_authy" do
192
- it "Should disable 2FA" do
193
- sign_in @user
194
- @user.update_attribute(:authy_enabled, true)
195
-
196
- request.cookies["remember_device"] = {
197
- :value => {expires: Time.now.to_i, id: @user.id}.to_json,
198
- :secure => false,
199
- :expires => User.authy_remember_device.from_now
200
- }
201
-
202
- post :POST_disable_authy
203
-
204
- expect(response.cookies["remember_device"]).to be_nil
205
- @user.reload
206
- expect(@user.authy_id).to be_nil
207
- expect(@user.authy_enabled).to be_falsey
208
- expect(flash.now[:notice]).to eq("Two factor authentication was disabled")
209
- expect(response).to redirect_to(root_url)
210
- end
211
-
212
- it "Should not disable 2FA" do
213
- sign_in @user
214
- @user.update_attribute(:authy_enabled, true)
215
-
216
- authy_response = double('authy_response')
217
- allow(authy_response).to receive(:ok?).and_return(false)
218
- expect(Authy::API).to receive(:delete_user).with(:id => @user.authy_id.to_s).and_return(authy_response)
219
-
220
- post :POST_disable_authy
221
- @user.reload
222
- expect(@user.authy_id).not_to be_nil
223
- expect(@user.authy_enabled).to be_truthy
224
- expect(flash[:error]).to eq("Something went wrong while disabling two factor authentication")
225
- end
226
-
227
- it "Should redirect if user isn't authenticated" do
228
- post :POST_disable_authy
229
- expect(response).to redirect_to(new_user_session_url)
230
- end
231
- end
232
-
233
- describe "GET #verify_authy_installation" do
234
- it "Should render the authy installation page" do
235
- sign_in @user
236
- get :GET_verify_authy_installation
237
- expect(response).to render_template('verify_authy_installation')
238
- end
239
-
240
- it "Should redirect if user isn't authenticated" do
241
- get :GET_verify_authy_installation
242
- expect(response).to redirect_to(new_user_session_url)
243
- end
244
- end
245
-
246
- describe "POST #verify_authy_installation" do
247
- it "Should enable authy for user" do
248
- sign_in @user
249
- post :POST_verify_authy_installation, :token => "0000000"
250
- expect(session["user_authy_token_checked"]).to be_truthy
251
- expect(response).to redirect_to(root_url)
252
- expect(flash[:notice]).to eq('Two factor authentication was enabled')
253
-
254
- @user.reload
255
- expect(@user.authy_enabled).to be_truthy
256
- end
257
-
258
- it "should not enable authy for user" do
259
- sign_in @user
260
- post :POST_verify_authy_installation, :token => "0007777"
261
- expect(response).to render_template('verify_authy_installation')
262
- expect(flash[:error]).to eq('Something went wrong while enabling two factor authentication')
263
- end
264
-
265
- it "Should redirect if user isn't authenticated" do
266
- get :GET_verify_authy_installation
267
- expect(response).to redirect_to(new_user_session_url)
268
- end
269
- end
270
-
271
- describe "POST #request_sms" do
272
- it "Should send sms if user is logged" do
273
- sign_in @user
274
- post :request_sms
275
- expect(response.content_type).to eq('application/json')
276
- body = JSON.parse(response.body)
277
-
278
- expect(body['sent']).to be_truthy
279
- expect(body['message']).to eq("Token was sent.")
280
- end
281
-
282
- it "Shoul not send sms if user couldn't be found" do
283
- post :request_sms
284
- expect(response.content_type).to eq('application/json')
285
- body = JSON.parse(response.body)
286
- expect(body['sent']).to be_falsey
287
- expect(body['message']).to eq("User couldn't be found.")
288
- end
289
- end
290
-
291
- describe "POST #request_phone_call" do
292
- it "Should send phone call if user is logged" do
293
- sign_in @user
294
- post :request_phone_call
295
- expect(response.content_type).to eq('application/json')
296
- body = JSON.parse(response.body)
297
- expect(body['sent']).to be_truthy
298
- expect(body['message']).to eq("Call started...")
299
- end
300
-
301
- it "Shoul not send phone call if user couldn't be found" do
302
- post :request_phone_call
303
- expect(response.content_type).to eq('application/json')
304
- body = JSON.parse(response.body)
305
- expect(body['sent']).to be_falsey
306
- expect(body['message']).to eq("User couldn't be found.")
307
- end
308
- end
309
-
310
- describe "GET #authy_onetouch_status" do
311
- # OneTouch stubbed due to test API key not having OneTouch enabled
312
- before do
313
- allow(Authy::OneTouch).to receive(:send_approval_request).with(id: @user.authy_id) { { 'approval_request' => { 'uuid' => SecureRandom.uuid } } }
314
- @uuid = Authy::OneTouch.send_approval_request(id: @user.authy_id)['approval_request']['uuid']
315
- end
316
-
317
- it "Should return a 202 status code when pending" do
318
- allow(Authy::API).to receive(:get_request).with(/onetouch\/json\/approval_requests\/.+/) { { 'approval_request' => { 'status' => 'pending' } } }
319
- request.session["user_id"] = @user.id
320
- request.session["user_password_checked"] = true
321
- get :GET_authy_onetouch_status, onetouch_uuid: @uuid
322
- expect(response.code).to eq("202")
323
- end
324
-
325
- it "Should return a 401 status code when denied" do
326
- allow(Authy::API).to receive(:get_request).with(/onetouch\/json\/approval_requests\/.+/) { { 'approval_request' => { 'status' => 'denied' } } }
327
- request.session["user_id"] = @user.id
328
- request.session["user_password_checked"] = true
329
- get :GET_authy_onetouch_status, onetouch_uuid: @uuid
330
- expect(response.code).to eq("401")
331
- end
332
-
333
- it "Should return a 200 status code when approved" do
334
- allow(Authy::API).to receive(:get_request).with(/onetouch\/json\/approval_requests\/.+/) { { 'approval_request' => { 'status' => 'approved' } } }
335
- request.session["user_id"] = @user.id
336
- request.session["user_password_checked"] = true
337
- get :GET_authy_onetouch_status, onetouch_uuid: @uuid
338
- expect(response.code).to eq("200")
339
- end
340
-
341
- it "Should render a JSON object with the redirect path when approved" do
342
- allow(Authy::API).to receive(:get_request).with(/onetouch\/json\/approval_requests\/.+/) { { 'approval_request' => { 'status' => 'approved' } } }
343
- request.session["user_id"] = @user.id
344
- request.session["user_password_checked"] = true
345
- get :GET_authy_onetouch_status, onetouch_uuid: @uuid
346
- expect(response.body).to eq({ redirect: root_path }.to_json)
347
- end
348
-
349
- it "Should not render the second step of authentication if first step is incomplete" do
350
- request.session["user_id"] = @user.id
351
- get :GET_authy_onetouch_status
352
- expect(response).to redirect_to(root_url)
353
- end
354
-
355
- it "should redirect to root_url" do
356
- get :GET_authy_onetouch_status
357
- expect(response).to redirect_to(root_url)
358
- end
359
- end
360
- end