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
7b88dca7
Commit
7b88dca7
authored
May 15, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update JwtController specs
parent
e8f7e551
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
36 deletions
+21
-36
spec/requests/jwt_controller_spec.rb
spec/requests/jwt_controller_spec.rb
+21
-36
No files found.
spec/requests/jwt_controller_spec.rb
View file @
7b88dca7
require
'spec_helper'
describe
JwtController
do
let
(
:services
)
{
{
'test'
=>
TestService
}
}
let
(
:parameters
)
{
{
service:
'test'
}
}
let
(
:ok_status
)
{
{
status:
'OK'
}
}
let
(
:service
)
{
double
(
execute:
{})
}
let
(
:service_class
)
{
double
(
new:
service
)
}
let
(
:service_name
)
{
'test'
}
let
(
:parameters
)
{
{
service:
service_name
}
}
before
{
allow_any_instance_of
(
JwtController
).
to
receive
(
:SERVICES
).
and_return
services
}
before
{
stub_const
(
'JwtController::SERVICES'
,
service_name
=>
service_class
)
}
context
'existing service'
do
before
{
expect_any_instance_of
(
TestService
).
to
receive
(
:execute
).
and_return
(
ok_status
)
}
subject!
{
get
'/jwt/auth'
,
parameters
}
it
{
expect
(
response
.
status
).
to
eq
(
200
)
}
context
'returning custom http code'
do
let
(
:service
)
{
double
(
execute:
{
http_status:
505
})
}
it
{
expect
(
response
.
status
).
to
eq
(
505
)
}
end
end
context
'when using authorized request'
do
context
'using CI token'
do
let
(
:project
)
{
create
(
:empty_project
,
runners_token:
'token'
,
builds_enabled:
builds_enabled
)
}
let
(
:headers
)
{
{
HTTP_AUTHENTICATION
:
authorize
(
'gitlab-ci-token'
,
project
.
runners_token
)
}
}
let
(
:headers
)
{
{
authorization:
credentials
(
'gitlab_ci_token'
,
project
.
runners_token
)
}
}
subject!
{
get
'/jwt/auth'
,
parameters
,
headers
}
context
'project with enabled CI'
do
let
(
:builds_enabled
)
{
true
}
it
do
expect
(
TestService
).
to
receive
(
:new
).
with
(
project
,
nil
,
parameters
).
and_call_original
get
'/jwt/auth'
,
parameters
,
headers
end
it
{
expect
(
service_class
).
to
have_received
(
:new
).
with
(
project
,
nil
,
parameters
)
}
end
context
'project with disabled CI'
do
let
(
:builds_enabled
)
{
false
}
it
do
expect
(
TestService
).
to
receive
(
:new
).
with
(
project
,
nil
,
parameters
).
and_call_original
get
'/jwt/auth'
,
parameters
,
headers
end
it
{
expect
(
response
.
status
).
to
eq
(
403
)
}
end
end
context
'using User login'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:headers
)
{
{
HTTP_AUTHENTICATION
:
authorize
(
'user'
,
'password'
)
}
}
let
(
:headers
)
{
{
authorization:
credentials
(
'user'
,
'password'
)
}
}
before
{
expect_any_instance_of
(
Gitlab
::
Auth
).
to
receive
(
:find
).
with
(
'user'
,
'password'
).
and_return
(
user
)
}
it
do
expect
(
TestService
).
to
receive
(
:new
).
with
(
nil
,
user
,
parameters
).
and_call_original
subject!
{
get
'/jwt/auth'
,
parameters
,
headers
}
get
'/jwt/auth'
,
parameters
,
headers
end
it
{
expect
(
service_class
).
to
have_received
(
:new
).
with
(
nil
,
user
,
parameters
)
}
end
context
'using invalid login'
do
let
(
:headers
)
{
{
HTTP_AUTHENTICATION
:
authorize
(
'invalid'
,
'password'
)
}
}
let
(
:headers
)
{
{
authorization:
credentials
(
'invalid'
,
'password'
)
}
}
subject!
{
get
'/jwt/auth'
,
parameters
,
headers
}
...
...
@@ -69,19 +66,7 @@ describe JwtController do
it
{
expect
(
response
.
status
).
to
eq
(
404
)
}
end
def
authorize
(
login
,
password
)
def
credentials
(
login
,
password
)
ActionController
::
HttpAuthentication
::
Basic
.
encode_credentials
(
login
,
password
)
end
class
TestService
attr_accessor
:project
,
:current_user
,
:params
def
initialize
(
project
,
user
,
params
=
{})
@project
,
@current_user
,
@params
=
project
,
user
,
params
.
dup
end
def
execute
{
status:
'OK'
}
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