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
Léo-Paul Géneau
gitlab-ce
Commits
460065b7
Commit
460065b7
authored
Aug 04, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move deploy_key tests to deploy_key_spec.rb
Also, fix the failing test in the process
parent
2b6bd6a3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
78 deletions
+81
-78
lib/api/deploy_keys.rb
lib/api/deploy_keys.rb
+6
-5
spec/requests/api/deploy_keys_spec.rb
spec/requests/api/deploy_keys_spec.rb
+74
-0
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+1
-73
No files found.
lib/api/deploy_keys.rb
View file @
460065b7
...
...
@@ -38,15 +38,16 @@ module API
present
key
,
with:
Entities
::
SSHKey
end
# TODO: for 9.0 we should check if params are there with the params block
# grape provides, at this point we'd change behaviour so we can't
# Behaviour now if you don't provide all required params: it renders a
# validation error or two.
desc
'Add new deploy key to currently authenticated user'
do
success
Entities
::
SSHKey
end
params
do
requires
:key
,
type:
String
,
desc:
"The new deploy key"
requires
:title
,
type:
String
,
desc:
'The title to identify the key from'
end
post
":id/
#{
path
}
"
do
attrs
=
declared
(
params
,
include_parent_namespaces:
false
).
to_h
attrs
=
attributes_for_keys
[
:title
,
:key
]
attrs
[
:key
].
strip!
if
attrs
[
:key
]
key
=
user_project
.
deploy_keys
.
find_by
(
key:
attrs
[
:key
])
present
key
,
with:
Entities
::
SSHKey
if
key
...
...
spec/requests/api/deploy_keys_spec.rb
View file @
460065b7
...
...
@@ -37,6 +37,80 @@ describe API::API, api: true do
end
end
describe
'GET /projects/:id/deploy_keys'
do
before
{
deploy_key
}
it
'should return array of ssh keys'
do
get
api
(
"/projects/
#{
project
.
id
}
/deploy_keys"
,
admin
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
deploy_key
.
title
)
end
end
describe
'GET /projects/:id/deploy_keys/:key_id'
do
it
'should return a single key'
do
get
api
(
"/projects/
#{
project
.
id
}
/deploy_keys/
#{
deploy_key
.
id
}
"
,
admin
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
deploy_key
.
title
)
end
it
'should return 404 Not Found with invalid ID'
do
get
api
(
"/projects/
#{
project
.
id
}
/deploy_keys/404"
,
admin
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
describe
'POST /projects/:id/deploy_keys'
do
it
'should not create an invalid ssh key'
do
post
api
(
"/projects/
#{
project
.
id
}
/deploy_keys"
,
admin
),
{
title:
'invalid key'
}
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'key'
]).
to
eq
([
'can\'t be blank'
,
'is too short (minimum is 0 characters)'
,
'is invalid'
])
end
it
'should not create a key without title'
do
post
api
(
"/projects/
#{
project
.
id
}
/deploy_keys"
,
admin
),
key:
'some key'
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'title'
]).
to
eq
([
'can\'t be blank'
,
'is too short (minimum is 0 characters)'
])
end
it
'should create new ssh key'
do
key_attrs
=
attributes_for
:another_key
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/deploy_keys"
,
admin
),
key_attrs
end
.
to
change
{
project
.
deploy_keys
.
count
}.
by
(
1
)
end
end
describe
'DELETE /projects/:id/deploy_keys/:key_id'
do
before
{
deploy_key
}
it
'should delete existing key'
do
expect
do
delete
api
(
"/projects/
#{
project
.
id
}
/deploy_keys/
#{
deploy_key
.
id
}
"
,
admin
)
end
.
to
change
{
project
.
deploy_keys
.
count
}.
by
(
-
1
)
end
it
'should return 404 Not Found with invalid ID'
do
delete
api
(
"/projects/
#{
project
.
id
}
/deploy_keys/404"
,
admin
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
describe
'POST /projects/:id/deploy_keys/:key_id/enable'
do
let
(
:project2
)
{
create
(
:empty_project
)
}
...
...
spec/requests/api/projects_spec.rb
View file @
460065b7
...
...
@@ -642,78 +642,6 @@ describe API::API, api: true do
end
end
describe
:deploy_keys
do
let
(
:deploy_keys_project
)
{
create
(
:deploy_keys_project
,
project:
project
)
}
let
(
:deploy_key
)
{
deploy_keys_project
.
deploy_key
}
describe
'GET /projects/:id/deploy_keys'
do
before
{
deploy_key
}
it
'should return array of ssh keys'
do
get
api
(
"/projects/
#{
project
.
id
}
/deploy_keys"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
deploy_key
.
title
)
end
end
describe
'GET /projects/:id/deploy_keys/:key_id'
do
it
'should return a single key'
do
get
api
(
"/projects/
#{
project
.
id
}
/deploy_keys/
#{
deploy_key
.
id
}
"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
deploy_key
.
title
)
end
it
'should return 404 Not Found with invalid ID'
do
get
api
(
"/projects/
#{
project
.
id
}
/deploy_keys/404"
,
user
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
describe
'POST /projects/:id/deploy_keys'
do
it
'should not create an invalid ssh key'
do
post
api
(
"/projects/
#{
project
.
id
}
/deploy_keys"
,
user
),
{
title:
'invalid key'
}
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'key'
]).
to
eq
([
'can\'t be blank'
,
'is too short (minimum is 0 characters)'
,
'is invalid'
])
end
it
'should not create a key without title'
do
post
api
(
"/projects/
#{
project
.
id
}
/deploy_keys"
,
user
),
key:
'some key'
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'title'
]).
to
eq
([
'can\'t be blank'
,
'is too short (minimum is 0 characters)'
])
end
it
'should create new ssh key'
do
key_attrs
=
attributes_for
:key
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/deploy_keys"
,
user
),
key_attrs
end
.
to
change
{
project
.
deploy_keys
.
count
}.
by
(
1
)
end
end
describe
'DELETE /projects/:id/deploy_keys/:key_id'
do
before
{
deploy_key
}
it
'should delete existing key'
do
expect
do
delete
api
(
"/projects/
#{
project
.
id
}
/deploy_keys/
#{
deploy_key
.
id
}
"
,
user
)
end
.
to
change
{
project
.
deploy_keys
.
count
}.
by
(
-
1
)
end
it
'should return 404 Not Found with invalid ID'
do
delete
api
(
"/projects/
#{
project
.
id
}
/deploy_keys/404"
,
user
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
describe
:fork_admin
do
let
(
:project_fork_target
)
{
create
(
:project
)
}
let
(
:project_fork_source
)
{
create
(
:project
,
:public
)
}
...
...
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