devise-authy 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.travis.yml +4 -0
- data/Gemfile +29 -13
- data/README.md +8 -6
- data/VERSION +1 -1
- data/app/controllers/devise/devise_authy_controller.rb +3 -3
- data/authy-devise-demo/Gemfile +39 -28
- data/authy-devise-demo/Gemfile.lock +166 -113
- data/authy-devise-demo/README.md +1 -1
- data/authy-devise-demo/app/controllers/welcome_controller.rb +2 -2
- data/authy-devise-demo/app/models/admin.rb +0 -3
- data/authy-devise-demo/app/models/user.rb +0 -3
- data/authy-devise-demo/config/application.rb +5 -41
- data/authy-devise-demo/config/environments/development.rb +21 -17
- data/authy-devise-demo/config/environments/production.rb +45 -33
- data/authy-devise-demo/config/environments/test.rb +18 -13
- data/authy-devise-demo/config/initializers/session_store.rb +1 -1
- data/authy-devise-demo/config/locales/devise.authy.en.yml +4 -4
- data/authy-devise-demo/config/secrets.yml +22 -0
- data/authy-devise-demo/db/migrate/20160906221739_add_sessions_table.rb +12 -0
- data/authy-devise-demo/db/schema.rb +32 -22
- data/config/locales/en.yml +4 -4
- data/devise-authy.gemspec +44 -47
- data/lib/devise-authy/controllers/helpers.rb +1 -1
- data/lib/devise-authy/controllers/view_helpers.rb +8 -2
- data/lib/devise-authy/mapping.rb +3 -7
- data/lib/devise-authy/models/authy_authenticatable.rb +1 -1
- data/lib/devise-authy/rails.rb +1 -1
- data/lib/generators/devise_authy/install_generator.rb +7 -0
- data/spec/controllers/devise_authy_controller_spec.rb +61 -60
- data/spec/controllers/passwords_controller_spec.rb +15 -15
- data/spec/features/authy_authenticatable_spec.rb +23 -23
- data/spec/features/authy_lockable_spec.rb +6 -6
- data/spec/generators_spec.rb +11 -9
- data/spec/models/authy_authenticatable_spec.rb +3 -3
- data/spec/models/authy_lockable_spec.rb +7 -7
- data/spec/rails-app/Gemfile +4 -3
- data/spec/rails-app/Gemfile.lock +116 -91
- data/spec/rails-app/app/controllers/welcome_controller.rb +1 -1
- data/spec/rails-app/app/models/user.rb +0 -3
- data/spec/rails-app/config/application.rb +15 -34
- data/spec/rails-app/config/environments/development.rb +21 -17
- data/spec/rails-app/config/environments/production.rb +45 -33
- data/spec/rails-app/config/environments/test.rb +18 -13
- data/spec/rails-app/config/secrets.yml +22 -0
- data/spec/routing/routes_spec.rb +7 -7
- data/spec/spec_helper.rb +17 -0
- data/spec/support/helpers.rb +3 -1
- metadata +34 -59
- data/Gemfile.lock +0 -194
data/config/locales/en.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
en:
|
2
2
|
devise:
|
3
|
-
submit_token:
|
4
|
-
submit_token_title:
|
3
|
+
submit_token: 'Check Token'
|
4
|
+
submit_token_title: 'Please enter your Authy token:'
|
5
5
|
authy_register_title: 'Enable Two factor authentication'
|
6
6
|
enable_authy: 'Enable'
|
7
7
|
cellphone: 'Enter your cellphone'
|
@@ -10,7 +10,7 @@ en:
|
|
10
10
|
request_phone_call: 'Request phone call'
|
11
11
|
remember_device: 'Remember Device'
|
12
12
|
|
13
|
-
authy_verify_installation_title:
|
13
|
+
authy_verify_installation_title: 'Verify your account'
|
14
14
|
enable_my_account: 'Enable my account'
|
15
15
|
|
16
16
|
devise_authy:
|
@@ -20,5 +20,5 @@ en:
|
|
20
20
|
disabled: 'Two factor authentication was disabled'
|
21
21
|
not_disabled: 'Something went wrong while disabling two factor authentication'
|
22
22
|
signed_in: 'Signed in with Authy successfully.'
|
23
|
-
already_enabled:
|
23
|
+
already_enabled: 'Two factor authentication is already enabled.'
|
24
24
|
invalid_token: 'The entered token is invalid'
|
data/devise-authy.gemspec
CHANGED
@@ -2,18 +2,18 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: devise-authy 1.
|
5
|
+
# stub: devise-authy 1.8.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
|
-
s.name = "devise-authy"
|
9
|
-
s.version = "1.
|
8
|
+
s.name = "devise-authy".freeze
|
9
|
+
s.version = "1.8.0"
|
10
10
|
|
11
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
-
s.require_paths = ["lib"]
|
13
|
-
s.authors = ["Authy Inc."]
|
14
|
-
s.date = "
|
15
|
-
s.description = "Authy plugin for Devise"
|
16
|
-
s.email = "support@authy.com"
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib".freeze]
|
13
|
+
s.authors = ["Authy Inc.".freeze]
|
14
|
+
s.date = "2016-10-25"
|
15
|
+
s.description = "Authy plugin for Devise".freeze
|
16
|
+
s.email = "support@authy.com".freeze
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE.txt",
|
19
19
|
"README.md"
|
@@ -21,8 +21,8 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.files = [
|
22
22
|
".document",
|
23
23
|
".rspec",
|
24
|
+
".travis.yml",
|
24
25
|
"Gemfile",
|
25
|
-
"Gemfile.lock",
|
26
26
|
"LICENSE.txt",
|
27
27
|
"README.md",
|
28
28
|
"Rakefile",
|
@@ -85,9 +85,11 @@ Gem::Specification.new do |s|
|
|
85
85
|
"authy-devise-demo/config/locales/devise.en.yml",
|
86
86
|
"authy-devise-demo/config/locales/en.yml",
|
87
87
|
"authy-devise-demo/config/routes.rb",
|
88
|
+
"authy-devise-demo/config/secrets.yml",
|
88
89
|
"authy-devise-demo/db/migrate/20130409234357_devise_create_users.rb",
|
89
90
|
"authy-devise-demo/db/migrate/20141202000744_devise_create_admins.rb",
|
90
91
|
"authy-devise-demo/db/migrate/20141202004246_devise_authy_add_to_admins.rb",
|
92
|
+
"authy-devise-demo/db/migrate/20160906221739_add_sessions_table.rb",
|
91
93
|
"authy-devise-demo/db/schema.rb",
|
92
94
|
"authy-devise-demo/db/seeds.rb",
|
93
95
|
"authy-devise-demo/lib/assets/.gitkeep",
|
@@ -178,6 +180,7 @@ Gem::Specification.new do |s|
|
|
178
180
|
"spec/rails-app/config/locales/devise.en.yml",
|
179
181
|
"spec/rails-app/config/locales/en.yml",
|
180
182
|
"spec/rails-app/config/routes.rb",
|
183
|
+
"spec/rails-app/config/secrets.yml",
|
181
184
|
"spec/rails-app/db/development.sqlite3",
|
182
185
|
"spec/rails-app/db/migrate/20130419164907_devise_create_users.rb",
|
183
186
|
"spec/rails-app/db/migrate/20130419164936_devise_authy_add_to_users.rb",
|
@@ -195,51 +198,45 @@ Gem::Specification.new do |s|
|
|
195
198
|
"spec/spec_helper.rb",
|
196
199
|
"spec/support/helpers.rb"
|
197
200
|
]
|
198
|
-
s.homepage = "https://github.com/authy/authy-devise"
|
199
|
-
s.licenses = ["MIT"]
|
200
|
-
s.rubygems_version = "2.
|
201
|
-
s.summary = "Authy plugin for Devise"
|
201
|
+
s.homepage = "https://github.com/authy/authy-devise".freeze
|
202
|
+
s.licenses = ["MIT".freeze]
|
203
|
+
s.rubygems_version = "2.6.7".freeze
|
204
|
+
s.summary = "Authy plugin for Devise".freeze
|
202
205
|
|
203
206
|
if s.respond_to? :specification_version then
|
204
207
|
s.specification_version = 4
|
205
208
|
|
206
209
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
207
|
-
s.add_runtime_dependency(%q<devise
|
208
|
-
s.add_runtime_dependency(%q<authy
|
209
|
-
s.add_development_dependency(%q<rspec
|
210
|
-
s.add_development_dependency(%q<yard
|
211
|
-
s.add_development_dependency(%q<rdoc
|
212
|
-
s.add_development_dependency(%q<bundler
|
213
|
-
s.add_development_dependency(%q<jeweler
|
214
|
-
s.add_development_dependency(%q<simplecov
|
215
|
-
s.add_development_dependency(%q<
|
216
|
-
s.add_development_dependency(%q<jquery-rails>, [">= 0"])
|
217
|
-
s.add_development_dependency(%q<pry>, [">= 0"])
|
210
|
+
s.add_runtime_dependency(%q<devise>.freeze, [">= 3.0.0"])
|
211
|
+
s.add_runtime_dependency(%q<authy>.freeze, [">= 0"])
|
212
|
+
s.add_development_dependency(%q<rspec>.freeze, ["> 3.0.0"])
|
213
|
+
s.add_development_dependency(%q<yard>.freeze, [">= 0"])
|
214
|
+
s.add_development_dependency(%q<rdoc>.freeze, [">= 0"])
|
215
|
+
s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
|
216
|
+
s.add_development_dependency(%q<jeweler>.freeze, [">= 2.0.1"])
|
217
|
+
s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
|
218
|
+
s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
|
218
219
|
else
|
219
|
-
s.add_dependency(%q<devise
|
220
|
-
s.add_dependency(%q<authy
|
221
|
-
s.add_dependency(%q<rspec
|
222
|
-
s.add_dependency(%q<yard
|
223
|
-
s.add_dependency(%q<rdoc
|
224
|
-
s.add_dependency(%q<bundler
|
225
|
-
s.add_dependency(%q<jeweler
|
226
|
-
s.add_dependency(%q<simplecov
|
227
|
-
s.add_dependency(%q<
|
228
|
-
s.add_dependency(%q<jquery-rails>, [">= 0"])
|
229
|
-
s.add_dependency(%q<pry>, [">= 0"])
|
220
|
+
s.add_dependency(%q<devise>.freeze, [">= 3.0.0"])
|
221
|
+
s.add_dependency(%q<authy>.freeze, [">= 0"])
|
222
|
+
s.add_dependency(%q<rspec>.freeze, ["> 3.0.0"])
|
223
|
+
s.add_dependency(%q<yard>.freeze, [">= 0"])
|
224
|
+
s.add_dependency(%q<rdoc>.freeze, [">= 0"])
|
225
|
+
s.add_dependency(%q<bundler>.freeze, [">= 0"])
|
226
|
+
s.add_dependency(%q<jeweler>.freeze, [">= 2.0.1"])
|
227
|
+
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
228
|
+
s.add_dependency(%q<byebug>.freeze, [">= 0"])
|
230
229
|
end
|
231
230
|
else
|
232
|
-
s.add_dependency(%q<devise
|
233
|
-
s.add_dependency(%q<authy
|
234
|
-
s.add_dependency(%q<rspec
|
235
|
-
s.add_dependency(%q<yard
|
236
|
-
s.add_dependency(%q<rdoc
|
237
|
-
s.add_dependency(%q<bundler
|
238
|
-
s.add_dependency(%q<jeweler
|
239
|
-
s.add_dependency(%q<simplecov
|
240
|
-
s.add_dependency(%q<
|
241
|
-
s.add_dependency(%q<jquery-rails>, [">= 0"])
|
242
|
-
s.add_dependency(%q<pry>, [">= 0"])
|
231
|
+
s.add_dependency(%q<devise>.freeze, [">= 3.0.0"])
|
232
|
+
s.add_dependency(%q<authy>.freeze, [">= 0"])
|
233
|
+
s.add_dependency(%q<rspec>.freeze, ["> 3.0.0"])
|
234
|
+
s.add_dependency(%q<yard>.freeze, [">= 0"])
|
235
|
+
s.add_dependency(%q<rdoc>.freeze, [">= 0"])
|
236
|
+
s.add_dependency(%q<bundler>.freeze, [">= 0"])
|
237
|
+
s.add_dependency(%q<jeweler>.freeze, [">= 2.0.1"])
|
238
|
+
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
239
|
+
s.add_dependency(%q<byebug>.freeze, [">= 0"])
|
243
240
|
end
|
244
241
|
end
|
245
242
|
|
@@ -2,6 +2,9 @@ module DeviseAuthy
|
|
2
2
|
module Views
|
3
3
|
module Helpers
|
4
4
|
def authy_request_phone_call_link(opts = {})
|
5
|
+
title = opts.delete(:title) do
|
6
|
+
I18n.t('request_phone_call', { :scope => 'devise' })
|
7
|
+
end
|
5
8
|
opts = {
|
6
9
|
:id => "authy-request-phone-call-link",
|
7
10
|
:method => :post,
|
@@ -9,13 +12,16 @@ module DeviseAuthy
|
|
9
12
|
}.merge(opts)
|
10
13
|
|
11
14
|
link_to(
|
12
|
-
|
15
|
+
title,
|
13
16
|
url_for([resource_name, :request_phone_call]),
|
14
17
|
opts
|
15
18
|
)
|
16
19
|
end
|
17
20
|
|
18
21
|
def authy_request_sms_link(opts = {})
|
22
|
+
title = opts.delete(:title) do
|
23
|
+
I18n.t('request_sms', scope: 'devise')
|
24
|
+
end
|
19
25
|
opts = {
|
20
26
|
:id => "authy-request-sms-link",
|
21
27
|
:method => :post,
|
@@ -23,7 +29,7 @@ module DeviseAuthy
|
|
23
29
|
}.merge(opts)
|
24
30
|
|
25
31
|
link_to(
|
26
|
-
|
32
|
+
title,
|
27
33
|
url_for([resource_name, :request_sms]),
|
28
34
|
opts
|
29
35
|
)
|
data/lib/devise-authy/mapping.rb
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
module DeviseAuthy
|
2
2
|
module Mapping
|
3
|
-
def self.included(base)
|
4
|
-
base.alias_method_chain :default_controllers, :authy_authenticatable
|
5
|
-
end
|
6
|
-
|
7
3
|
private
|
8
|
-
def
|
4
|
+
def default_controllers(options)
|
9
5
|
options[:controllers] ||= {}
|
10
6
|
options[:controllers][:passwords] ||= "devise_authy/passwords"
|
11
|
-
|
7
|
+
super
|
12
8
|
end
|
13
9
|
end
|
14
|
-
end
|
10
|
+
end
|
data/lib/devise-authy/rails.rb
CHANGED
@@ -16,6 +16,13 @@ module DeviseAuthy
|
|
16
16
|
" # config.authy_remember_device = 1.month\n\n", :after => "Devise.setup do |config|\n"
|
17
17
|
end
|
18
18
|
|
19
|
+
def add_initializer
|
20
|
+
initializer("authy.rb") do
|
21
|
+
"Authy.api_key = ENV[\"AUTHY_API_KEY\"]\n" \
|
22
|
+
"Authy.api_uri = \"https://api.authy.com/\""
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
19
26
|
def copy_locale
|
20
27
|
copy_file "../../../config/locales/en.yml", "config/locales/devise.authy.en.yml"
|
21
28
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Devise::DeviseAuthyController do
|
4
|
-
include Devise::
|
3
|
+
describe Devise::DeviseAuthyController, type: :controller do
|
4
|
+
include Devise::Test::ControllerHelpers
|
5
5
|
|
6
6
|
before :each do
|
7
7
|
request.env["devise.mapping"] = Devise.mappings[:user]
|
@@ -13,18 +13,18 @@ describe Devise::DeviseAuthyController do
|
|
13
13
|
request.session["user_id"] = @user.id
|
14
14
|
request.session["user_password_checked"] = true
|
15
15
|
get :GET_verify_authy
|
16
|
-
response.
|
16
|
+
expect(response).to render_template('verify_authy')
|
17
17
|
end
|
18
18
|
|
19
19
|
it "Should no render the second step of authentication if first step is incomplete" do
|
20
20
|
request.session["user_id"] = @user.id
|
21
21
|
get :GET_verify_authy
|
22
|
-
response.
|
22
|
+
expect(response).to redirect_to(root_url)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should redirect to root_url" do
|
26
26
|
get :GET_verify_authy
|
27
|
-
response.
|
27
|
+
expect(response).to redirect_to(root_url)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -35,12 +35,12 @@ describe Devise::DeviseAuthyController do
|
|
35
35
|
|
36
36
|
post :POST_verify_authy, :token => '0000000'
|
37
37
|
@user.reload
|
38
|
-
@user.last_sign_in_with_authy.
|
38
|
+
expect(@user.last_sign_in_with_authy).not_to be_nil
|
39
39
|
|
40
|
-
response.cookies["remember_device"].
|
41
|
-
response.
|
42
|
-
flash.now[:notice].
|
43
|
-
session["user_authy_token_checked"].
|
40
|
+
expect(response.cookies["remember_device"]).to be_nil
|
41
|
+
expect(response).to redirect_to(root_url)
|
42
|
+
expect(flash.now[:notice]).not_to be_nil
|
43
|
+
expect(session["user_authy_token_checked"]).to be_truthy
|
44
44
|
end
|
45
45
|
|
46
46
|
it "Should set remember_device if selected" do
|
@@ -49,11 +49,11 @@ describe Devise::DeviseAuthyController do
|
|
49
49
|
|
50
50
|
post :POST_verify_authy, :token => '0000000', :remember_device => '1'
|
51
51
|
@user.reload
|
52
|
-
@user.last_sign_in_with_authy.
|
52
|
+
expect(@user.last_sign_in_with_authy).not_to be_nil
|
53
53
|
|
54
|
-
response.cookies["remember_device"].
|
55
|
-
response.
|
56
|
-
flash.now[:notice].
|
54
|
+
expect(response.cookies["remember_device"]).not_to be_nil
|
55
|
+
expect(response).to redirect_to(root_url)
|
56
|
+
expect(flash.now[:notice]).not_to be_nil
|
57
57
|
end
|
58
58
|
|
59
59
|
it "Shouldn't login the user if token is invalid" do
|
@@ -61,7 +61,7 @@ describe Devise::DeviseAuthyController do
|
|
61
61
|
request.session["user_password_checked"] = true
|
62
62
|
|
63
63
|
post :POST_verify_authy, :token => '5678900'
|
64
|
-
response.
|
64
|
+
expect(response).to render_template('verify_authy')
|
65
65
|
end
|
66
66
|
|
67
67
|
context 'User is lockable' do
|
@@ -69,7 +69,7 @@ describe Devise::DeviseAuthyController do
|
|
69
69
|
let(:user) { create_lockable_user authy_id: 2 }
|
70
70
|
|
71
71
|
before do
|
72
|
-
controller.
|
72
|
+
allow(controller).to receive(:find_resource).and_return user
|
73
73
|
controller.instance_variable_set :@resource, user
|
74
74
|
end
|
75
75
|
|
@@ -82,7 +82,7 @@ describe Devise::DeviseAuthyController do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
user.reload
|
85
|
-
expect(user.access_locked?).to
|
85
|
+
expect(user.access_locked?).to be_truthy
|
86
86
|
end
|
87
87
|
|
88
88
|
end
|
@@ -110,26 +110,26 @@ describe Devise::DeviseAuthyController do
|
|
110
110
|
user2 = create_user
|
111
111
|
sign_in user2
|
112
112
|
get :GET_enable_authy
|
113
|
-
response.
|
113
|
+
expect(response).to render_template('enable_authy')
|
114
114
|
end
|
115
115
|
|
116
116
|
it "Shouldn't render enable authy view" do
|
117
117
|
get :GET_enable_authy
|
118
|
-
response.
|
118
|
+
expect(response).to redirect_to(new_user_session_url)
|
119
119
|
end
|
120
120
|
|
121
121
|
it "should redirect if user has authy enabled" do
|
122
122
|
@user.update_attribute(:authy_enabled, true)
|
123
123
|
sign_in @user
|
124
124
|
get :GET_enable_authy
|
125
|
-
response.
|
126
|
-
flash.now[:notice].
|
125
|
+
expect(response).to redirect_to(root_url)
|
126
|
+
expect(flash.now[:notice]).to eq("Two factor authentication is already enabled.")
|
127
127
|
end
|
128
128
|
|
129
129
|
it "Should render enable authy view if authy enabled is false" do
|
130
130
|
sign_in @user
|
131
131
|
get :GET_enable_authy
|
132
|
-
response.
|
132
|
+
expect(response).to render_template('enable_authy')
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
@@ -138,11 +138,11 @@ describe Devise::DeviseAuthyController do
|
|
138
138
|
user2 = create_user
|
139
139
|
sign_in user2
|
140
140
|
|
141
|
-
post :POST_enable_authy, :cellphone => '
|
141
|
+
post :POST_enable_authy, :cellphone => '3010008090', :country_code => '57'
|
142
142
|
user2.reload
|
143
|
-
user2.authy_id.
|
144
|
-
flash.now[:notice].
|
145
|
-
response.
|
143
|
+
expect(user2.authy_id).not_to be_nil
|
144
|
+
expect(flash.now[:notice]).to eq("Two factor authentication was enabled")
|
145
|
+
expect(response).to redirect_to(user_verify_authy_installation_url)
|
146
146
|
end
|
147
147
|
|
148
148
|
it "Should not create user register user failed" do
|
@@ -150,13 +150,13 @@ describe Devise::DeviseAuthyController do
|
|
150
150
|
sign_in user2
|
151
151
|
|
152
152
|
post :POST_enable_authy, :cellphone => '22222', :country_code => "57"
|
153
|
-
response.
|
154
|
-
flash[:error].
|
153
|
+
expect(response).to render_template('enable_authy')
|
154
|
+
expect(flash[:error]).to eq("Something went wrong while enabling two factor authentication")
|
155
155
|
end
|
156
156
|
|
157
157
|
it "Should redirect if user isn't authenticated" do
|
158
158
|
post :POST_enable_authy, :cellphone => '3010008090', :country_code => '57'
|
159
|
-
response.
|
159
|
+
expect(response).to redirect_to(new_user_session_url)
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
@@ -167,30 +167,30 @@ describe Devise::DeviseAuthyController do
|
|
167
167
|
|
168
168
|
post :POST_disable_authy
|
169
169
|
@user.reload
|
170
|
-
@user.authy_id.
|
171
|
-
@user.authy_enabled.
|
172
|
-
flash.now[:notice].
|
173
|
-
response.
|
170
|
+
expect(@user.authy_id).to be_nil
|
171
|
+
expect(@user.authy_enabled).to be_falsey
|
172
|
+
expect(flash.now[:notice]).to eq("Two factor authentication was disabled")
|
173
|
+
expect(response).to redirect_to(root_url)
|
174
174
|
end
|
175
175
|
|
176
176
|
it "Should not disable 2FA" do
|
177
177
|
sign_in @user
|
178
178
|
@user.update_attribute(:authy_enabled, true)
|
179
179
|
|
180
|
-
authy_response =
|
181
|
-
authy_response.
|
182
|
-
Authy::API.
|
180
|
+
authy_response = double('authy_response')
|
181
|
+
allow(authy_response).to receive(:ok?).and_return(false)
|
182
|
+
expect(Authy::API).to receive(:delete_user).with(:id => @user.authy_id.to_s).and_return(authy_response)
|
183
183
|
|
184
184
|
post :POST_disable_authy
|
185
185
|
@user.reload
|
186
|
-
@user.authy_id.
|
187
|
-
@user.authy_enabled.
|
188
|
-
flash[:error].
|
186
|
+
expect(@user.authy_id).not_to be_nil
|
187
|
+
expect(@user.authy_enabled).to be_truthy
|
188
|
+
expect(flash[:error]).to eq("Something went wrong while disabling two factor authentication")
|
189
189
|
end
|
190
190
|
|
191
191
|
it "Should redirect if user isn't authenticated" do
|
192
192
|
post :POST_disable_authy
|
193
|
-
response.
|
193
|
+
expect(response).to redirect_to(new_user_session_url)
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
@@ -198,12 +198,12 @@ describe Devise::DeviseAuthyController do
|
|
198
198
|
it "Should render the authy installation page" do
|
199
199
|
sign_in @user
|
200
200
|
get :GET_verify_authy_installation
|
201
|
-
response.
|
201
|
+
expect(response).to render_template('verify_authy_installation')
|
202
202
|
end
|
203
203
|
|
204
204
|
it "Should redirect if user isn't authenticated" do
|
205
205
|
get :GET_verify_authy_installation
|
206
|
-
response.
|
206
|
+
expect(response).to redirect_to(new_user_session_url)
|
207
207
|
end
|
208
208
|
end
|
209
209
|
|
@@ -211,23 +211,23 @@ describe Devise::DeviseAuthyController do
|
|
211
211
|
it "Should enable authy for user" do
|
212
212
|
sign_in @user
|
213
213
|
post :POST_verify_authy_installation, :token => "0000000"
|
214
|
-
response.
|
215
|
-
flash[:notice].
|
214
|
+
expect(response).to redirect_to(root_url)
|
215
|
+
expect(flash[:notice]).to eq('Two factor authentication was enabled')
|
216
216
|
|
217
217
|
@user.reload
|
218
|
-
@user.authy_enabled.
|
218
|
+
expect(@user.authy_enabled).to be_truthy
|
219
219
|
end
|
220
220
|
|
221
221
|
it "should not enable authy for user" do
|
222
222
|
sign_in @user
|
223
223
|
post :POST_verify_authy_installation, :token => "0007777"
|
224
|
-
response.
|
225
|
-
flash[:error].
|
224
|
+
expect(response).to render_template('verify_authy_installation')
|
225
|
+
expect(flash[:error]).to eq('Something went wrong while enabling two factor authentication')
|
226
226
|
end
|
227
227
|
|
228
228
|
it "Should redirect if user isn't authenticated" do
|
229
229
|
get :GET_verify_authy_installation
|
230
|
-
response.
|
230
|
+
expect(response).to redirect_to(new_user_session_url)
|
231
231
|
end
|
232
232
|
end
|
233
233
|
|
@@ -235,18 +235,19 @@ describe Devise::DeviseAuthyController do
|
|
235
235
|
it "Should send sms if user is logged" do
|
236
236
|
sign_in @user
|
237
237
|
post :request_sms
|
238
|
-
response.content_type.
|
238
|
+
expect(response.content_type).to eq('application/json')
|
239
239
|
body = JSON.parse(response.body)
|
240
|
-
|
241
|
-
body['
|
240
|
+
|
241
|
+
expect(body['sent']).to be_truthy
|
242
|
+
expect(body['message']).to eq("SMS token was sent")
|
242
243
|
end
|
243
244
|
|
244
245
|
it "Shoul not send sms if user couldn't be found" do
|
245
246
|
post :request_sms
|
246
|
-
response.content_type.
|
247
|
+
expect(response.content_type).to eq('application/json')
|
247
248
|
body = JSON.parse(response.body)
|
248
|
-
body['sent'].
|
249
|
-
body['message'].
|
249
|
+
expect(body['sent']).to be_falsey
|
250
|
+
expect(body['message']).to eq("User couldn't be found.")
|
250
251
|
end
|
251
252
|
end
|
252
253
|
|
@@ -254,18 +255,18 @@ describe Devise::DeviseAuthyController do
|
|
254
255
|
it "Should send phone call if user is logged" do
|
255
256
|
sign_in @user
|
256
257
|
post :request_phone_call
|
257
|
-
response.content_type.
|
258
|
+
expect(response.content_type).to eq('application/json')
|
258
259
|
body = JSON.parse(response.body)
|
259
|
-
body['sent'].
|
260
|
-
body['message'].
|
260
|
+
expect(body['sent']).to be_truthy
|
261
|
+
expect(body['message']).to eq("Call started...")
|
261
262
|
end
|
262
263
|
|
263
264
|
it "Shoul not send phone call if user couldn't be found" do
|
264
265
|
post :request_phone_call
|
265
|
-
response.content_type.
|
266
|
+
expect(response.content_type).to eq('application/json')
|
266
267
|
body = JSON.parse(response.body)
|
267
|
-
body['sent'].
|
268
|
-
body['message'].
|
268
|
+
expect(body['sent']).to be_falsey
|
269
|
+
expect(body['message']).to eq("User couldn't be found.")
|
269
270
|
end
|
270
271
|
end
|
271
272
|
end
|