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
3485d4d1
Commit
3485d4d1
authored
Jan 14, 2022
by
Darby Frey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding an API test for unexpected validation errors
parent
873cfffe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
7 deletions
+24
-7
lib/api/ci/secure_files.rb
lib/api/ci/secure_files.rb
+1
-1
spec/requests/api/ci/secure_files_spec.rb
spec/requests/api/ci/secure_files_spec.rb
+23
-6
No files found.
lib/api/ci/secure_files.rb
View file @
3485d4d1
...
...
@@ -56,7 +56,7 @@ module API
desc
'Upload a Secure File'
params
do
requires
:name
,
type:
String
,
desc:
'The name of the file'
requires
:file
,
types:
[
Rack
::
Multipart
::
UploadedFile
,
::
API
::
Validations
::
Types
::
WorkhorseFile
],
desc:
'The secure file
file
to be uploaded'
requires
:file
,
types:
[
Rack
::
Multipart
::
UploadedFile
,
::
API
::
Validations
::
Types
::
WorkhorseFile
],
desc:
'The secure file to be uploaded'
optional
:permissions
,
type:
String
,
desc:
'The file permissions'
end
...
...
spec/requests/api/ci/secure_files_spec.rb
View file @
3485d4d1
...
...
@@ -7,12 +7,12 @@ RSpec.describe API::Ci::SecureFiles do
stub_ci_secure_file_object_storage
end
let
(
:user
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
let
!
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let
!
(
:maintainer
)
{
create
(
:project_member
,
:maintainer
,
user:
user
,
project:
project
)
}
let
!
(
:developer
)
{
create
(
:project_member
,
:developer
,
user:
user2
,
project:
project
)
}
let
!
(
:secure_file
)
{
create
(
:ci_secure_file
,
project:
project
)
}
let
_it_be
(
:user
)
{
create
(
:user
)
}
let
_it_be
(
:user2
)
{
create
(
:user
)
}
let
_it_be
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let
_it_be
(
:maintainer
)
{
create
(
:project_member
,
:maintainer
,
user:
user
,
project:
project
)
}
let
_it_be
(
:developer
)
{
create
(
:project_member
,
:developer
,
user:
user2
,
project:
project
)
}
let
_it_be
(
:secure_file
)
{
create
(
:ci_secure_file
,
project:
project
)
}
describe
'GET /projects/:id/secure_files'
do
context
'authorized user with proper permissions'
do
...
...
@@ -158,6 +158,23 @@ RSpec.describe API::Ci::SecureFiles do
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
[
'error'
]).
to
eq
(
'name is missing'
)
end
it
'retuns an error when an unexpected validation failure happens'
do
allow_next_instance_of
(
Ci
::
SecureFile
)
do
|
instance
|
allow
(
instance
).
to
receive
(
:valid?
).
and_return
(
false
)
allow
(
instance
).
to
receive_message_chain
(
:errors
,
:any?
).
and_return
(
true
)
allow
(
instance
).
to
receive_message_chain
(
:errors
,
:messages
).
and_return
([
'Error 1'
,
'Error 2'
])
end
post_params
=
{
file:
fixture_file_upload
(
'spec/fixtures/ci_secure_files/upload-keystore.jks'
),
name:
'upload-keystore.jks'
}
post
api
(
"/projects/
#{
project
.
id
}
/secure_files"
,
user
),
params:
post_params
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
end
context
'authorized user with invalid permissions'
do
...
...
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