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
bd5a45cc
Commit
bd5a45cc
authored
Mar 30, 2020
by
David Fernandez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up duplicated code
API::NugetPackages will now use API::Helpers::Packages::BasicAuthHelpers
parent
f0d2d2a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
37 deletions
+2
-37
ee/lib/api/nuget_packages.rb
ee/lib/api/nuget_packages.rb
+1
-36
ee/spec/support/shared_examples/requests/api/nuget_packages_shared_examples.rb
...d_examples/requests/api/nuget_packages_shared_examples.rb
+1
-1
No files found.
ee/lib/api/nuget_packages.rb
View file @
bd5a45cc
...
...
@@ -8,10 +8,8 @@
module
API
class
NugetPackages
<
Grape
::
API
helpers
::
API
::
Helpers
::
PackagesManagerClientsHelpers
helpers
::
API
::
Helpers
::
Packages
::
BasicAuthHelpers
AUTHORIZATION_HEADER
=
'Authorization'
AUTHENTICATE_REALM_HEADER
=
'Www-Authenticate: Basic realm'
AUTHENTICATE_REALM_NAME
=
'GitLab Nuget Package Registry'
POSITIVE_INTEGER_REGEX
=
%r{
\A
[1-9]
\d
*
\z
}
.
freeze
NON_NEGATIVE_INTEGER_REGEX
=
%r{
\A
0|[1-9]
\d
*
\z
}
.
freeze
...
...
@@ -24,39 +22,6 @@ module API
end
helpers
do
def
find_personal_access_token
find_personal_access_token_from_http_basic_auth
end
def
authorized_user_project
@authorized_user_project
||=
authorized_project_find!
(
params
[
:id
])
end
def
authorized_project_find!
(
id
)
project
=
find_project
(
id
)
unless
project
&&
can?
(
current_user
,
:read_project
,
project
)
return
unauthorized_or!
{
not_found!
}
end
project
end
def
authorize!
(
action
,
subject
=
:global
,
reason
=
nil
)
return
if
can?
(
current_user
,
action
,
subject
)
unauthorized_or!
{
forbidden!
(
reason
)
}
end
def
unauthorized_or!
current_user
?
yield
:
unauthorized_with_header!
end
def
unauthorized_with_header!
header
(
AUTHENTICATE_REALM_HEADER
,
AUTHENTICATE_REALM_NAME
)
unauthorized!
end
def
find_packages
packages
=
package_finder
.
execute
...
...
ee/spec/support/shared_examples/requests/api/nuget_packages_shared_examples.rb
View file @
bd5a45cc
...
...
@@ -12,7 +12,7 @@ RSpec.shared_examples 'rejects nuget packages access' do |user_type, status, add
it
'has the correct response header'
do
subject
expect
(
response
.
headers
[
'Www-Authenticate: Basic realm'
]).
to
eq
'GitLab
Nuget Package
Registry'
expect
(
response
.
headers
[
'Www-Authenticate: Basic realm'
]).
to
eq
'GitLab
Packages
Registry'
end
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