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
fe62fb88
Commit
fe62fb88
authored
Jan 23, 2020
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '10io-fix-nuget-upload' into 'master'
Fix nuget uploads See merge request gitlab-org/gitlab!23599
parents
1a5eb7d6
6a9e9f29
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
57 additions
and
20 deletions
+57
-20
ee/app/services/packages/nuget/create_package_service.rb
ee/app/services/packages/nuget/create_package_service.rb
+9
-3
ee/lib/api/conan_packages.rb
ee/lib/api/conan_packages.rb
+2
-2
ee/lib/api/helpers/packages_helpers.rb
ee/lib/api/helpers/packages_helpers.rb
+7
-2
ee/lib/api/helpers/packages_manager_clients_helpers.rb
ee/lib/api/helpers/packages_manager_clients_helpers.rb
+2
-2
ee/lib/api/nuget_packages.rb
ee/lib/api/nuget_packages.rb
+2
-2
ee/spec/lib/api/helpers/packages_helpers_spec.rb
ee/spec/lib/api/helpers/packages_helpers_spec.rb
+15
-1
ee/spec/requests/api/nuget_packages_spec.rb
ee/spec/requests/api/nuget_packages_spec.rb
+2
-2
ee/spec/services/packages/nuget/create_package_service_spec.rb
...ec/services/packages/nuget/create_package_service_spec.rb
+14
-2
ee/spec/support/shared_examples/requests/api/nuget_packages_shared_examples.rb
...d_examples/requests/api/nuget_packages_shared_examples.rb
+4
-4
No files found.
ee/app/services/packages/nuget/create_package_service.rb
View file @
fe62fb88
...
@@ -3,15 +3,21 @@
...
@@ -3,15 +3,21 @@
module
Packages
module
Packages
module
Nuget
module
Nuget
class
CreatePackageService
<
BaseService
class
CreatePackageService
<
BaseService
PACKAGE_NAME
=
'NuGet
.Package'
TEMPORARY_PACKAGE_NAME
=
'NuGet.Temporary
.Package'
PACKAGE_VERSION
=
'0.0.0'
PACKAGE_VERSION
=
'0.0.0'
def
execute
def
execute
project
.
packages
.
nuget
.
create!
(
project
.
packages
.
nuget
.
create!
(
name:
PACKAGE_NAME
,
name:
TEMPORARY_
PACKAGE_NAME
,
version:
PACKAGE_VERSION
version:
"
#{
PACKAGE_VERSION
}
-
#{
uuid
}
"
)
)
end
end
private
def
uuid
SecureRandom
.
uuid
end
end
end
end
end
end
end
ee/lib/api/conan_packages.rb
View file @
fe62fb88
...
@@ -250,7 +250,7 @@ module API
...
@@ -250,7 +250,7 @@ module API
end
end
route_setting
:authentication
,
job_token_allowed:
true
route_setting
:authentication
,
job_token_allowed:
true
put
'authorize'
do
put
'authorize'
do
authorize_workhorse!
(
project
)
authorize_workhorse!
(
subject:
project
)
end
end
end
end
...
@@ -273,7 +273,7 @@ module API
...
@@ -273,7 +273,7 @@ module API
end
end
route_setting
:authentication
,
job_token_allowed:
true
route_setting
:authentication
,
job_token_allowed:
true
put
'authorize'
do
put
'authorize'
do
authorize_workhorse!
(
project
)
authorize_workhorse!
(
subject:
project
)
end
end
desc
'Upload package files'
do
desc
'Upload package files'
do
...
...
ee/lib/api/helpers/packages_helpers.rb
View file @
fe62fb88
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
module
API
module
API
module
Helpers
module
Helpers
module
PackagesHelpers
module
PackagesHelpers
MAX_PACKAGE_FILE_SIZE
=
50
.
megabytes
.
freeze
def
require_packages_enabled!
def
require_packages_enabled!
not_found!
unless
::
Gitlab
.
config
.
packages
.
enabled
not_found!
unless
::
Gitlab
.
config
.
packages
.
enabled
end
end
...
@@ -29,14 +31,17 @@ module API
...
@@ -29,14 +31,17 @@ module API
authorize_read_package!
(
subject
)
authorize_read_package!
(
subject
)
end
end
def
authorize_workhorse!
(
subject
=
user_project
)
def
authorize_workhorse!
(
subject
:
user_project
,
has_length:
true
,
maximum_size:
MAX_PACKAGE_FILE_SIZE
)
authorize_upload!
(
subject
)
authorize_upload!
(
subject
)
Gitlab
::
Workhorse
.
verify_api_request!
(
headers
)
Gitlab
::
Workhorse
.
verify_api_request!
(
headers
)
status
200
status
200
content_type
Gitlab
::
Workhorse
::
INTERNAL_API_CONTENT_TYPE
content_type
Gitlab
::
Workhorse
::
INTERNAL_API_CONTENT_TYPE
::
Packages
::
PackageFileUploader
.
workhorse_authorize
(
has_length:
true
)
params
=
{
has_length:
has_length
}
params
[
:maximum_size
]
=
maximum_size
unless
has_length
::
Packages
::
PackageFileUploader
.
workhorse_authorize
(
params
)
end
end
def
authorize_upload!
(
subject
=
user_project
)
def
authorize_upload!
(
subject
=
user_project
)
...
...
ee/lib/api/helpers/packages_manager_clients_helpers.rb
View file @
fe62fb88
...
@@ -36,8 +36,8 @@ module API
...
@@ -36,8 +36,8 @@ module API
::
Ci
::
Build
.
find_by_token
(
token
)
::
Ci
::
Build
.
find_by_token
(
token
)
end
end
def
uploaded_package_file
def
uploaded_package_file
(
param_name
=
:file
)
uploaded_file
=
UploadedFile
.
from_params
(
params
,
:fil
e
,
::
Packages
::
PackageFileUploader
.
workhorse_local_upload_path
)
uploaded_file
=
UploadedFile
.
from_params
(
params
,
param_nam
e
,
::
Packages
::
PackageFileUploader
.
workhorse_local_upload_path
)
bad_request!
(
'Missing package file!'
)
unless
uploaded_file
bad_request!
(
'Missing package file!'
)
unless
uploaded_file
uploaded_file
uploaded_file
end
end
...
...
ee/lib/api/nuget_packages.rb
View file @
fe62fb88
...
@@ -96,7 +96,7 @@ module API
...
@@ -96,7 +96,7 @@ module API
package
=
::
Packages
::
Nuget
::
CreatePackageService
.
new
(
authorized_user_project
,
current_user
).
execute
package
=
::
Packages
::
Nuget
::
CreatePackageService
.
new
(
authorized_user_project
,
current_user
).
execute
file_params
=
params
.
merge
(
file_params
=
params
.
merge
(
file:
uploaded_package_file
,
file:
uploaded_package_file
(
:package
)
,
file_name:
PACKAGE_FILENAME
,
file_name:
PACKAGE_FILENAME
,
file_type:
PACKAGE_FILETYPE
file_type:
PACKAGE_FILETYPE
)
)
...
@@ -112,7 +112,7 @@ module API
...
@@ -112,7 +112,7 @@ module API
forbidden!
forbidden!
end
end
put
'authorize'
do
put
'authorize'
do
authorize_workhorse!
(
authorized_user_project
)
authorize_workhorse!
(
subject:
authorized_user_project
,
has_length:
false
)
end
end
end
end
end
end
...
...
ee/spec/lib/api/helpers/packages_helpers_spec.rb
View file @
fe62fb88
...
@@ -89,7 +89,7 @@ describe API::Helpers::PackagesHelpers do
...
@@ -89,7 +89,7 @@ describe API::Helpers::PackagesHelpers do
describe
'#authorize_workhorse!'
do
describe
'#authorize_workhorse!'
do
let_it_be
(
:headers
)
{
{}
}
let_it_be
(
:headers
)
{
{}
}
subject
{
helper
.
authorize_workhorse!
(
project
)
}
subject
{
helper
.
authorize_workhorse!
(
subject:
project
)
}
before
do
before
do
allow
(
helper
).
to
receive
(
:headers
).
and_return
(
headers
)
allow
(
helper
).
to
receive
(
:headers
).
and_return
(
headers
)
...
@@ -104,6 +104,20 @@ describe API::Helpers::PackagesHelpers do
...
@@ -104,6 +104,20 @@ describe API::Helpers::PackagesHelpers do
expect
(
subject
).
to
eq
nil
expect
(
subject
).
to
eq
nil
end
end
context
'without length'
do
subject
{
helper
.
authorize_workhorse!
(
subject:
project
,
has_length:
false
)
}
it
'authorizes workhorse'
do
expect
(
helper
).
to
receive
(
:authorize_upload!
).
with
(
project
)
expect
(
helper
).
to
receive
(
:status
).
with
(
200
)
expect
(
helper
).
to
receive
(
:content_type
).
with
(
Gitlab
::
Workhorse
::
INTERNAL_API_CONTENT_TYPE
)
expect
(
Gitlab
::
Workhorse
).
to
receive
(
:verify_api_request!
).
with
(
headers
)
expect
(
::
Packages
::
PackageFileUploader
).
to
receive
(
:workhorse_authorize
).
with
(
has_length:
false
,
maximum_size:
::
API
::
Helpers
::
PackagesHelpers
::
MAX_PACKAGE_FILE_SIZE
)
expect
(
subject
).
to
eq
nil
end
end
end
end
describe
'#authorize_upload!'
do
describe
'#authorize_upload!'
do
...
...
ee/spec/requests/api/nuget_packages_spec.rb
View file @
fe62fb88
...
@@ -177,13 +177,13 @@ describe API::NugetPackages do
...
@@ -177,13 +177,13 @@ describe API::NugetPackages do
let_it_be
(
:file_name
)
{
'package.nupkg'
}
let_it_be
(
:file_name
)
{
'package.nupkg'
}
let
(
:url
)
{
"/projects/
#{
project
.
id
}
/packages/nuget"
}
let
(
:url
)
{
"/projects/
#{
project
.
id
}
/packages/nuget"
}
let
(
:headers
)
{
{}
}
let
(
:headers
)
{
{}
}
let
(
:params
)
{
{
fil
e:
temp_file
(
file_name
)
}
}
let
(
:params
)
{
{
packag
e:
temp_file
(
file_name
)
}
}
subject
do
subject
do
workhorse_finalize
(
workhorse_finalize
(
api
(
url
),
api
(
url
),
method: :put
,
method: :put
,
file_key: :
fil
e
,
file_key: :
packag
e
,
params:
params
,
params:
params
,
headers:
headers
headers:
headers
)
)
...
...
ee/spec/services/packages/nuget/create_package_service_spec.rb
View file @
fe62fb88
...
@@ -14,8 +14,20 @@ describe Packages::Nuget::CreatePackageService do
...
@@ -14,8 +14,20 @@ describe Packages::Nuget::CreatePackageService do
package
=
Packages
::
Package
.
last
package
=
Packages
::
Package
.
last
expect
(
package
).
to
be_valid
expect
(
package
).
to
be_valid
expect
(
package
.
name
).
to
eq
(
Packages
::
Nuget
::
CreatePackageService
::
PACKAGE_NAME
)
expect
(
package
.
name
).
to
eq
(
Packages
::
Nuget
::
CreatePackageService
::
TEMPORARY_PACKAGE_NAME
)
expect
(
package
.
version
).
to
eq
(
Packages
::
Nuget
::
CreatePackageService
::
PACKAGE_VERSION
)
expect
(
package
.
version
).
to
start_with
(
Packages
::
Nuget
::
CreatePackageService
::
PACKAGE_VERSION
)
expect
(
package
.
package_type
).
to
eq
(
'nuget'
)
end
it
'can create two packages in a row'
do
expect
{
subject
}.
to
change
{
Packages
::
Package
.
count
}.
by
(
1
)
expect
{
described_class
.
new
(
project
,
user
,
params
).
execute
}.
to
change
{
Packages
::
Package
.
count
}.
by
(
1
)
package
=
Packages
::
Package
.
last
expect
(
package
).
to
be_valid
expect
(
package
.
name
).
to
eq
(
Packages
::
Nuget
::
CreatePackageService
::
TEMPORARY_PACKAGE_NAME
)
expect
(
package
.
version
).
to
start_with
(
Packages
::
Nuget
::
CreatePackageService
::
PACKAGE_VERSION
)
expect
(
package
.
package_type
).
to
eq
(
'nuget'
)
expect
(
package
.
package_type
).
to
eq
(
'nuget'
)
end
end
end
end
...
...
ee/spec/support/shared_examples/requests/api/nuget_packages_shared_examples.rb
View file @
fe62fb88
...
@@ -98,7 +98,7 @@ RSpec.shared_examples 'process nuget upload' do |user_type, status, add_member =
...
@@ -98,7 +98,7 @@ RSpec.shared_examples 'process nuget upload' do |user_type, status, add_member =
context
'with object storage disabled'
do
context
'with object storage disabled'
do
context
'without a file from workhorse'
do
context
'without a file from workhorse'
do
let
(
:params
)
{
{
fil
e:
nil
}
}
let
(
:params
)
{
{
packag
e:
nil
}
}
it_behaves_like
'returning response status'
,
:bad_request
it_behaves_like
'returning response status'
,
:bad_request
end
end
...
@@ -121,7 +121,7 @@ RSpec.shared_examples 'process nuget upload' do |user_type, status, add_member =
...
@@ -121,7 +121,7 @@ RSpec.shared_examples 'process nuget upload' do |user_type, status, add_member =
)
)
end
end
let
(
:fog_file
)
{
fog_to_uploaded_file
(
tmp_object
)
}
let
(
:fog_file
)
{
fog_to_uploaded_file
(
tmp_object
)
}
let
(
:params
)
{
{
file:
fog_file
,
'fil
e.remote_id'
=>
file_name
}
}
let
(
:params
)
{
{
package:
fog_file
,
'packag
e.remote_id'
=>
file_name
}
}
it_behaves_like
'creates nuget package files'
it_behaves_like
'creates nuget package files'
...
@@ -129,8 +129,8 @@ RSpec.shared_examples 'process nuget upload' do |user_type, status, add_member =
...
@@ -129,8 +129,8 @@ RSpec.shared_examples 'process nuget upload' do |user_type, status, add_member =
context
"with invalid remote_id:
#{
remote_id
}
"
do
context
"with invalid remote_id:
#{
remote_id
}
"
do
let
(
:params
)
do
let
(
:params
)
do
{
{
fil
e:
fog_file
,
packag
e:
fog_file
,
'
fil
e.remote_id'
=>
remote_id
'
packag
e.remote_id'
=>
remote_id
}
}
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