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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
1541d1de
Commit
1541d1de
authored
Apr 18, 2016
by
Timothy Andrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename `api_helpers_spec` to `api_authentication_spec`
- And fix all tests.
parent
6d76f14f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
14 deletions
+16
-14
spec/requests/api/api_authentication_spec.rb
spec/requests/api/api_authentication_spec.rb
+16
-14
No files found.
spec/requests/api/api_
helpers
_spec.rb
→
spec/requests/api/api_
authentication
_spec.rb
View file @
1541d1de
require
'spec_helper'
describe
API
,
api:
true
do
include
API
::
Helpers
describe
API
::
Helpers
::
Authentication
,
api:
true
do
include
API
::
Helpers
::
Authentication
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:key
)
{
create
(
:key
,
user:
user
)
}
...
...
@@ -13,25 +15,25 @@ describe API, api: true do
def
set_env
(
token_usr
,
identifier
)
clear_env
clear_param
env
[
API
::
Helpers
::
PRIVATE_TOKEN_HEADER
]
=
token_usr
.
private_token
env
[
API
::
Helpers
::
SUDO_HEADER
]
=
identifier
env
[
API
::
Helpers
::
Authentication
::
PRIVATE_TOKEN_HEADER
]
=
token_usr
.
private_token
env
[
API
::
Helpers
::
Authentication
::
SUDO_HEADER
]
=
identifier
end
def
set_param
(
token_usr
,
identifier
)
clear_env
clear_param
params
[
API
::
Helpers
::
PRIVATE_TOKEN_PARAM
]
=
token_usr
.
private_token
params
[
API
::
Helpers
::
SUDO_PARAM
]
=
identifier
params
[
API
::
Helpers
::
Authentication
::
PRIVATE_TOKEN_PARAM
]
=
token_usr
.
private_token
params
[
API
::
Helpers
::
Authentication
::
SUDO_PARAM
]
=
identifier
end
def
clear_env
env
.
delete
(
API
::
Helpers
::
PRIVATE_TOKEN_HEADER
)
env
.
delete
(
API
::
Helpers
::
SUDO_HEADER
)
env
.
delete
(
API
::
Helpers
::
Authentication
::
PRIVATE_TOKEN_HEADER
)
env
.
delete
(
API
::
Helpers
::
Authentication
::
SUDO_HEADER
)
end
def
clear_param
params
.
delete
(
API
::
Helpers
::
PRIVATE_TOKEN_PARAM
)
params
.
delete
(
API
::
Helpers
::
SUDO_PARAM
)
params
.
delete
(
API
::
Helpers
::
Authentication
::
PRIVATE_TOKEN_PARAM
)
params
.
delete
(
API
::
Helpers
::
Authentication
::
SUDO_PARAM
)
end
def
error!
(
message
,
status
)
...
...
@@ -40,22 +42,22 @@ describe API, api: true do
describe
".current_user"
do
it
"should return nil for an invalid token"
do
env
[
API
::
Helpers
::
PRIVATE_TOKEN_HEADER
]
=
'invalid token'
env
[
API
::
Helpers
::
Authentication
::
PRIVATE_TOKEN_HEADER
]
=
'invalid token'
allow_any_instance_of
(
self
.
class
).
to
receive
(
:doorkeeper_guard
){
false
}
expect
(
current_user
).
to
be_nil
end
it
"should return nil for a user without access"
do
env
[
API
::
Helpers
::
PRIVATE_TOKEN_HEADER
]
=
user
.
private_token
env
[
API
::
Helpers
::
Authentication
::
PRIVATE_TOKEN_HEADER
]
=
user
.
private_token
allow
(
Gitlab
::
UserAccess
).
to
receive
(
:allowed?
).
and_return
(
false
)
expect
(
current_user
).
to
be_nil
end
it
"should leave user as is when sudo not specified"
do
env
[
API
::
Helpers
::
PRIVATE_TOKEN_HEADER
]
=
user
.
private_token
env
[
API
::
Helpers
::
Authentication
::
PRIVATE_TOKEN_HEADER
]
=
user
.
private_token
expect
(
current_user
).
to
eq
(
user
)
clear_env
params
[
API
::
Helpers
::
PRIVATE_TOKEN_PARAM
]
=
user
.
private_token
params
[
API
::
Helpers
::
Authentication
::
PRIVATE_TOKEN_PARAM
]
=
user
.
private_token
expect
(
current_user
).
to
eq
(
user
)
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