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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
72b5c9af
Commit
72b5c9af
authored
Aug 21, 2018
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API: Catch empty code content for project snippets
parent
cc9764ac
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
2 deletions
+23
-2
changelogs/unreleased/api-empty-project-snippets.yml
changelogs/unreleased/api-empty-project-snippets.yml
+5
-0
lib/api/project_snippets.rb
lib/api/project_snippets.rb
+2
-2
spec/requests/api/project_snippets_spec.rb
spec/requests/api/project_snippets_spec.rb
+16
-0
No files found.
changelogs/unreleased/api-empty-project-snippets.yml
0 → 100644
View file @
72b5c9af
---
title
:
'
API:
Catch
empty
code
content
for
project
snippets'
merge_request
:
21325
author
:
Robert Schilling
type
:
fixed
lib/api/project_snippets.rb
View file @
72b5c9af
...
@@ -49,7 +49,7 @@ module API
...
@@ -49,7 +49,7 @@ module API
params
do
params
do
requires
:title
,
type:
String
,
desc:
'The title of the snippet'
requires
:title
,
type:
String
,
desc:
'The title of the snippet'
requires
:file_name
,
type:
String
,
desc:
'The file name of the snippet'
requires
:file_name
,
type:
String
,
desc:
'The file name of the snippet'
requires
:code
,
type:
String
,
desc:
'The content of the snippet'
requires
:code
,
type:
String
,
allow_blank:
false
,
desc:
'The content of the snippet'
optional
:description
,
type:
String
,
desc:
'The description of a snippet'
optional
:description
,
type:
String
,
desc:
'The description of a snippet'
requires
:visibility
,
type:
String
,
requires
:visibility
,
type:
String
,
values:
Gitlab
::
VisibilityLevel
.
string_values
,
values:
Gitlab
::
VisibilityLevel
.
string_values
,
...
@@ -78,7 +78,7 @@ module API
...
@@ -78,7 +78,7 @@ module API
requires
:snippet_id
,
type:
Integer
,
desc:
'The ID of a project snippet'
requires
:snippet_id
,
type:
Integer
,
desc:
'The ID of a project snippet'
optional
:title
,
type:
String
,
desc:
'The title of the snippet'
optional
:title
,
type:
String
,
desc:
'The title of the snippet'
optional
:file_name
,
type:
String
,
desc:
'The file name of the snippet'
optional
:file_name
,
type:
String
,
desc:
'The file name of the snippet'
optional
:code
,
type:
String
,
desc:
'The content of the snippet'
optional
:code
,
type:
String
,
allow_blank:
false
,
desc:
'The content of the snippet'
optional
:description
,
type:
String
,
desc:
'The description of a snippet'
optional
:description
,
type:
String
,
desc:
'The description of a snippet'
optional
:visibility
,
type:
String
,
optional
:visibility
,
type:
String
,
values:
Gitlab
::
VisibilityLevel
.
string_values
,
values:
Gitlab
::
VisibilityLevel
.
string_values
,
...
...
spec/requests/api/project_snippets_spec.rb
View file @
72b5c9af
...
@@ -116,6 +116,14 @@ describe API::ProjectSnippets do
...
@@ -116,6 +116,14 @@ describe API::ProjectSnippets do
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
end
it
'returns 400 for empty code field'
do
params
[
:code
]
=
''
post
api
(
"/projects/
#{
project
.
id
}
/snippets/"
,
admin
),
params
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
context
'when the snippet is spam'
do
context
'when the snippet is spam'
do
def
create_snippet
(
project
,
snippet_params
=
{})
def
create_snippet
(
project
,
snippet_params
=
{})
project
.
add_developer
(
user
)
project
.
add_developer
(
user
)
...
@@ -180,6 +188,14 @@ describe API::ProjectSnippets do
...
@@ -180,6 +188,14 @@ describe API::ProjectSnippets do
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
end
it
'returns 400 for empty code field'
do
new_content
=
''
put
api
(
"/projects/
#{
snippet
.
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
,
admin
),
code:
new_content
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
context
'when the snippet is spam'
do
context
'when the snippet is spam'
do
def
update_snippet
(
snippet_params
=
{})
def
update_snippet
(
snippet_params
=
{})
put
api
(
"/projects/
#{
snippet
.
project
.
id
}
/snippets/
#{
snippet
.
id
}
"
,
admin
),
snippet_params
put
api
(
"/projects/
#{
snippet
.
project
.
id
}
/snippets/
#{
snippet
.
id
}
"
,
admin
),
snippet_params
...
...
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