Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
301f4074
Commit
301f4074
authored
Apr 06, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for sessions controller including 2FA
This also contains specs for a bug described in #14900
parent
f76bfed9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
0 deletions
+93
-0
spec/controllers/sessions_controller_spec.rb
spec/controllers/sessions_controller_spec.rb
+93
-0
No files found.
spec/controllers/sessions_controller_spec.rb
0 → 100644
View file @
301f4074
require
'spec_helper'
describe
SessionsController
do
describe
'#create'
do
before
do
@request
.
env
[
'devise.mapping'
]
=
Devise
.
mappings
[
:user
]
end
context
'standard authentications'
do
context
'invalid password'
do
it
'does not authenticate user'
do
post
(
:create
,
user:
{
login:
'invalid'
,
password:
'invalid'
})
expect
(
response
)
.
to
set_flash
.
now
[
:alert
].
to
/Invalid login or password/
end
end
context
'valid password'
do
let
(
:user
)
{
create
(
:user
)
}
it
'authenticates user correctly'
do
post
(
:create
,
user:
{
login:
user
.
username
,
password:
user
.
password
})
expect
(
response
).
to
set_flash
.
to
/Signed in successfully/
expect
(
subject
.
current_user
).
to
eq
user
end
end
end
context
'two-factor authentication'
do
let
(
:user
)
{
create
(
:user
,
:two_factor
)
}
def
authenticate_2fa
(
user_params
)
post
(
:create
,
{
user:
user_params
},
{
otp_user_id:
user
.
id
})
end
##
# See #14900 issue
#
context
'authenticating with login and OTP belonging to another user'
do
let
(
:another_user
)
{
create
(
:user
,
:two_factor
)
}
context
'OTP valid for another user'
do
it
'does not authenticate'
do
authenticate_2fa
(
login:
another_user
.
username
,
otp_attempt:
another_user
.
current_otp
)
expect
(
subject
.
current_user
).
to_not
eq
another_user
end
end
context
'OTP invalid for another user'
do
before
do
authenticate_2fa
(
login:
another_user
.
username
,
otp_attempt:
'invalid'
)
end
it
'does not authenticate'
do
expect
(
subject
.
current_user
).
to_not
eq
another_user
end
it
'does not leak information about 2FA enabled'
do
expect
(
response
).
to_not
set_flash
.
now
[
:alert
].
to
/Invalid two-factor code/
end
end
context
'authenticating with OTP'
do
context
'valid OTP'
do
it
'authenticates correctly'
do
authenticate_2fa
(
otp_attempt:
user
.
current_otp
)
expect
(
subject
.
current_user
).
to
eq
user
end
end
context
'invalid OTP'
do
before
{
authenticate_2fa
(
otp_attempt:
'invalid'
)
}
it
'does not authenticate'
do
expect
(
subject
.
current_user
).
to_not
eq
user
end
it
'warns about invalid OTP code'
do
expect
(
response
).
to
set_flash
.
now
[
:alert
].
to
/Invalid two-factor code/
end
end
end
end
end
end
end
Write
Preview
Markdown
is supported
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