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
d8e731f4
Commit
d8e731f4
authored
Oct 07, 2020
by
Steve Abrams
Committed by
Robert Speicher
Oct 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix deploy tokens to respond to #projects
parent
976f5ff8
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
1 deletion
+60
-1
app/models/deploy_token.rb
app/models/deploy_token.rb
+14
-0
app/models/project.rb
app/models/project.rb
+1
-1
changelogs/unreleased/235822-maven-group-token.yml
changelogs/unreleased/235822-maven-group-token.yml
+6
-0
spec/models/deploy_token_spec.rb
spec/models/deploy_token_spec.rb
+25
-0
spec/requests/api/maven_packages_spec.rb
spec/requests/api/maven_packages_spec.rb
+14
-0
No files found.
app/models/deploy_token.rb
View file @
d8e731f4
...
...
@@ -78,6 +78,20 @@ class DeployToken < ApplicationRecord
end
end
def
group
strong_memoize
(
:group
)
do
groups
.
first
end
end
def
accessible_projects
if
project_type?
projects
elsif
group_type?
group
.
all_projects
end
end
def
holder
strong_memoize
(
:holder
)
do
if
project_type?
...
...
app/models/project.rb
View file @
d8e731f4
...
...
@@ -602,7 +602,7 @@ class Project < ApplicationRecord
return
public_to_user
unless
user
if
user
.
is_a?
(
DeployToken
)
user
.
projects
user
.
accessible_
projects
else
where
(
'EXISTS (?) OR projects.visibility_level IN (?)'
,
user
.
authorizations_for_projects
(
min_access_level:
min_access_level
),
...
...
changelogs/unreleased/235822-maven-group-token.yml
0 → 100644
View file @
d8e731f4
---
title
:
Fix group deploy tokens to return all projects and work with the Maven group
endpoint
merge_request
:
43628
author
:
type
:
fixed
spec/models/deploy_token_spec.rb
View file @
d8e731f4
...
...
@@ -353,4 +353,29 @@ RSpec.describe DeployToken do
end
end
end
describe
'#accessible_projects'
do
subject
{
deploy_token
.
accessible_projects
}
context
'when a deploy token is associated to a project'
do
let_it_be
(
:deploy_token
)
{
create
(
:deploy_token
,
:project
)
}
it
'returns only projects directly associated with the token'
do
expect
(
deploy_token
).
to
receive
(
:projects
)
subject
end
end
context
'when a deploy token is associated to a group'
do
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:deploy_token
)
{
create
(
:deploy_token
,
:group
,
groups:
[
group
])
}
it
'returns all projects from the group'
do
expect
(
group
).
to
receive
(
:all_projects
)
subject
end
end
end
end
spec/requests/api/maven_packages_spec.rb
View file @
d8e731f4
...
...
@@ -15,10 +15,13 @@ RSpec.describe API::MavenPackages do
let_it_be
(
:job
,
reload:
true
)
{
create
(
:ci_build
,
user:
user
,
status: :running
)
}
let_it_be
(
:deploy_token
)
{
create
(
:deploy_token
,
read_package_registry:
true
,
write_package_registry:
true
)
}
let_it_be
(
:project_deploy_token
)
{
create
(
:project_deploy_token
,
deploy_token:
deploy_token
,
project:
project
)
}
let_it_be
(
:deploy_token_for_group
)
{
create
(
:deploy_token
,
:group
,
read_package_registry:
true
,
write_package_registry:
true
)
}
let_it_be
(
:group_deploy_token
)
{
create
(
:group_deploy_token
,
deploy_token:
deploy_token_for_group
,
group:
group
)
}
let
(
:workhorse_token
)
{
JWT
.
encode
({
'iss'
=>
'gitlab-workhorse'
},
Gitlab
::
Workhorse
.
secret
,
'HS256'
)
}
let
(
:headers
)
{
{
'GitLab-Workhorse'
=>
'1.0'
,
Gitlab
::
Workhorse
::
INTERNAL_API_REQUEST_HEADER
=>
workhorse_token
}
}
let
(
:headers_with_token
)
{
headers
.
merge
(
'Private-Token'
=>
personal_access_token
.
token
)
}
let
(
:group_deploy_token_headers
)
{
{
Gitlab
::
Auth
::
AuthFinders
::
DEPLOY_TOKEN_HEADER
=>
deploy_token_for_group
.
token
}
}
let
(
:headers_with_deploy_token
)
do
headers
.
merge
(
...
...
@@ -342,6 +345,17 @@ RSpec.describe API::MavenPackages do
it_behaves_like
'downloads with a job token'
it_behaves_like
'downloads with a deploy token'
context
'with group deploy token'
do
subject
{
download_file_with_token
(
package_file
.
file_name
,
{},
group_deploy_token_headers
)
}
it
'returns the file'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
.
media_type
).
to
eq
(
'application/octet-stream'
)
end
end
end
def
download_file
(
file_name
,
params
=
{},
request_headers
=
headers
)
...
...
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