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
iv
gitlab-ce
Commits
28233e00
Commit
28233e00
authored
May 15, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'docker-registry' into docker-registry-view
parents
c275c913
7b88dca7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
1 deletion
+73
-1
app/controllers/jwt_controller.rb
app/controllers/jwt_controller.rb
+1
-1
spec/requests/jwt_controller_spec.rb
spec/requests/jwt_controller_spec.rb
+72
-0
No files found.
app/controllers/jwt_controller.rb
View file @
28233e00
...
...
@@ -9,7 +9,7 @@ class JwtController < ApplicationController
def
auth
service
=
SERVICES
[
params
[
:service
]]
head
:not_found
unless
service
return
head
:not_found
unless
service
result
=
service
.
new
(
@project
,
@user
,
auth_params
).
execute
...
...
spec/requests/jwt_controller_spec.rb
0 → 100644
View file @
28233e00
require
'spec_helper'
describe
JwtController
do
let
(
:service
)
{
double
(
execute:
{})
}
let
(
:service_class
)
{
double
(
new:
service
)
}
let
(
:service_name
)
{
'test'
}
let
(
:parameters
)
{
{
service:
service_name
}
}
before
{
stub_const
(
'JwtController::SERVICES'
,
service_name
=>
service_class
)
}
context
'existing service'
do
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
)
{
{
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
{
expect
(
service_class
).
to
have_received
(
:new
).
with
(
project
,
nil
,
parameters
)
}
end
context
'project with disabled CI'
do
let
(
:builds_enabled
)
{
false
}
it
{
expect
(
response
.
status
).
to
eq
(
403
)
}
end
end
context
'using User login'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:headers
)
{
{
authorization:
credentials
(
'user'
,
'password'
)
}
}
before
{
expect_any_instance_of
(
Gitlab
::
Auth
).
to
receive
(
:find
).
with
(
'user'
,
'password'
).
and_return
(
user
)
}
subject!
{
get
'/jwt/auth'
,
parameters
,
headers
}
it
{
expect
(
service_class
).
to
have_received
(
:new
).
with
(
nil
,
user
,
parameters
)
}
end
context
'using invalid login'
do
let
(
:headers
)
{
{
authorization:
credentials
(
'invalid'
,
'password'
)
}
}
subject!
{
get
'/jwt/auth'
,
parameters
,
headers
}
it
{
expect
(
response
.
status
).
to
eq
(
403
)
}
end
end
context
'unknown service'
do
subject!
{
get
'/jwt/auth'
,
service:
'unknown'
}
it
{
expect
(
response
.
status
).
to
eq
(
404
)
}
end
def
credentials
(
login
,
password
)
ActionController
::
HttpAuthentication
::
Basic
.
encode_credentials
(
login
,
password
)
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