Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
mamot
Commits
b48f2cbc
Commit
b48f2cbc
authored
Apr 27, 2017
by
Matt Jankowski
Committed by
Eugen Rochko
Apr 27, 2017
Browse files
Catch error when server decryption fails on 2FA (#2512)
parent
1736badf
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/controllers/auth/sessions_controller.rb
View file @
b48f2cbc
...
...
@@ -51,6 +51,8 @@ class Auth::SessionsController < Devise::SessionsController
def
valid_otp_attempt?
(
user
)
user
.
validate_and_consume_otp!
(
user_params
[
:otp_attempt
])
||
user
.
invalidate_otp_backup_code!
(
user_params
[
:otp_attempt
])
rescue
OpenSSL
::
Cipher
::
CipherError
=>
error
false
end
def
authenticate_with_two_factor
...
...
spec/controllers/auth/sessions_controller_spec.rb
View file @
b48f2cbc
# frozen_string_literal: true
require
'rails_helper'
RSpec
.
describe
Auth
::
SessionsController
,
type: :controller
do
...
...
@@ -90,6 +92,21 @@ RSpec.describe Auth::SessionsController, type: :controller do
end
end
context
'when the server has an decryption error'
do
before
do
allow_any_instance_of
(
User
).
to
receive
(
:validate_and_consume_otp!
).
and_raise
(
OpenSSL
::
Cipher
::
CipherError
)
post
:create
,
params:
{
user:
{
otp_attempt:
user
.
current_otp
}
},
session:
{
otp_user_id:
user
.
id
}
end
it
'shows a login error'
do
expect
(
flash
[
:alert
]).
to
match
I18n
.
t
(
'users.invalid_otp_token'
)
end
it
"doesn't log the user in"
do
expect
(
controller
.
current_user
).
to
be_nil
end
end
context
'using a valid recovery code'
do
before
do
post
:create
,
params:
{
user:
{
otp_attempt:
recovery_codes
.
first
}
},
session:
{
otp_user_id:
user
.
id
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment