BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
8e57cc7e
Commit
8e57cc7e
authored
Nov 09, 2017
by
Francisco Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added RequestAuthenticator spec
parent
21153a4f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
0 deletions
+67
-0
request_authenticator_spec.rb
spec/lib/gitlab/auth/request_authenticator_spec.rb
+67
-0
No files found.
spec/lib/gitlab/auth/request_authenticator_spec.rb
0 → 100644
View file @
8e57cc7e
require
'spec_helper'
describe
Gitlab
::
Auth
::
RequestAuthenticator
do
let
(
:env
)
do
{
'rack.input'
=>
''
,
'REQUEST_METHOD'
=>
'GET'
}
end
let
(
:request
)
{
ActionDispatch
::
Request
.
new
(
env
)
}
subject
{
described_class
.
new
(
request
)
}
describe
'.user'
do
let!
(
:sessionless_user
)
{
build
(
:user
)
}
let!
(
:session_user
)
{
build
(
:user
)
}
it
'returns sessionless user first'
do
allow_any_instance_of
(
described_class
).
to
receive
(
:find_sessionless_user
).
and_return
(
sessionless_user
)
allow_any_instance_of
(
described_class
).
to
receive
(
:find_user_from_warden
).
and_return
(
session_user
)
expect
(
subject
.
user
).
to
eq
sessionless_user
end
it
'returns session user if no sessionless user found'
do
allow_any_instance_of
(
described_class
).
to
receive
(
:find_user_from_warden
).
and_return
(
session_user
)
expect
(
subject
.
user
).
to
eq
session_user
end
it
'returns nil if no user found'
do
expect
(
subject
.
user
).
to
be_blank
end
it
'bubbles up exceptions'
do
allow_any_instance_of
(
described_class
).
to
receive
(
:find_user_from_warden
).
and_raise
(
API
::
APIGuard
::
UnauthorizedError
)
end
end
describe
'.find_sessionless_user'
do
let!
(
:access_token_user
)
{
build
(
:user
)
}
let!
(
:rss_token_user
)
{
build
(
:user
)
}
it
'returns access_token user first'
do
allow_any_instance_of
(
described_class
).
to
receive
(
:find_user_from_access_token
).
and_return
(
access_token_user
)
allow_any_instance_of
(
described_class
).
to
receive
(
:find_user_from_rss_token
).
and_return
(
rss_token_user
)
expect
(
subject
.
find_sessionless_user
).
to
eq
access_token_user
end
it
'returns rss_token user if no access_token user found'
do
allow_any_instance_of
(
described_class
).
to
receive
(
:find_user_from_rss_token
).
and_return
(
rss_token_user
)
expect
(
subject
.
find_sessionless_user
).
to
eq
rss_token_user
end
it
'returns nil if no user found'
do
expect
(
subject
.
find_sessionless_user
).
to
be_blank
end
it
'rescue StandardError exceptions'
do
allow_any_instance_of
(
described_class
).
to
receive
(
:find_user_from_access_token
).
and_raise
(
API
::
APIGuard
::
UnauthorizedError
)
expect
(
subject
.
find_sessionless_user
).
to
be_blank
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