Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
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
0
Merge Requests
0
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-shell
Commits
de1446d3
Commit
de1446d3
authored
Oct 05, 2017
by
Ahmad Sherif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add relative git object dir envvars to check access request
parent
bbda5bd1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
140 additions
and
7 deletions
+140
-7
CHANGELOG
CHANGELOG
+3
-0
VERSION
VERSION
+1
-1
lib/gitlab_access.rb
lib/gitlab_access.rb
+2
-6
lib/object_dirs_helper.rb
lib/object_dirs_helper.rb
+39
-0
spec/object_dirs_helper_spec.rb
spec/object_dirs_helper_spec.rb
+95
-0
No files found.
CHANGELOG
View file @
de1446d3
v5.9.4
- Add relative git object dir envvars to check access request
v5.9.3
- Expose GitLab username to hooks in `GL_USERNAME` environment variable
...
...
VERSION
View file @
de1446d3
5.9.
3
5.9.
4
lib/gitlab_access.rb
View file @
de1446d3
...
...
@@ -3,6 +3,7 @@ require_relative 'gitlab_net'
require_relative
'gitlab_access_status'
require_relative
'names_helper'
require_relative
'gitlab_metrics'
require_relative
'object_dirs_helper'
require
'json'
class
GitlabAccess
...
...
@@ -23,12 +24,7 @@ class GitlabAccess
def
exec
status
=
GitlabMetrics
.
measure
(
'check-access:git-receive-pack'
)
do
env
=
{
"GIT_ALTERNATE_OBJECT_DIRECTORIES"
=>
ENV
[
"GIT_ALTERNATE_OBJECT_DIRECTORIES"
],
"GIT_OBJECT_DIRECTORY"
=>
ENV
[
"GIT_OBJECT_DIRECTORY"
]
}
api
.
check_access
(
'git-receive-pack'
,
@gl_repository
,
@repo_path
,
@actor
,
@changes
,
@protocol
,
env:
env
.
to_json
)
api
.
check_access
(
'git-receive-pack'
,
@gl_repository
,
@repo_path
,
@actor
,
@changes
,
@protocol
,
env:
ObjectDirsHelper
.
all_attributes
.
to_json
)
end
raise
AccessDeniedError
,
status
.
message
unless
status
.
allowed?
...
...
lib/object_dirs_helper.rb
0 → 100644
View file @
de1446d3
require
'pathname'
class
ObjectDirsHelper
class
<<
self
def
all_attributes
{
"GIT_ALTERNATE_OBJECT_DIRECTORIES"
=>
absolute_alt_object_dirs
,
"GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE"
=>
relative_alt_object_dirs
,
"GIT_OBJECT_DIRECTORY"
=>
absolute_object_dir
,
"GIT_OBJECT_DIRECTORY_RELATIVE"
=>
relative_object_dir
}
end
def
absolute_object_dir
ENV
[
'GIT_OBJECT_DIRECTORY'
]
end
def
relative_object_dir
relative_path
(
absolute_object_dir
)
end
def
absolute_alt_object_dirs
ENV
[
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
].
to_s
.
split
(
File
::
PATH_SEPARATOR
)
end
def
relative_alt_object_dirs
absolute_alt_object_dirs
.
map
{
|
dir
|
relative_path
(
dir
)
}.
compact
end
private
def
relative_path
(
absolute_path
)
return
if
absolute_path
.
nil?
repo_dir
=
Dir
.
pwd
Pathname
.
new
(
absolute_path
).
relative_path_from
(
Pathname
.
new
(
repo_dir
)).
to_s
end
end
end
spec/object_dirs_helper_spec.rb
0 → 100644
View file @
de1446d3
require_relative
'spec_helper'
require_relative
'../lib/object_dirs_helper'
describe
ObjectDirsHelper
do
before
do
allow
(
Dir
).
to
receive
(
:pwd
).
and_return
(
'/home/git/repositories/foo/bar.git'
)
end
describe
'.all_attributes'
do
it
do
expect
(
described_class
.
all_attributes
.
keys
).
to
include
(
*
%w[
GIT_OBJECT_DIRECTORY
GIT_OBJECT_DIRECTORY_RELATIVE
GIT_ALTERNATE_OBJECT_DIRECTORIES
GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE
]
)
end
end
describe
'.absolute_object_dir'
do
subject
{
described_class
.
absolute_object_dir
}
context
'when GIT_OBJECT_DIRECTORY is set'
do
let
(
:dir
)
{
'/home/git/repositories/foo/bar.git/./objects'
}
before
do
allow
(
ENV
).
to
receive
(
:[]
).
with
(
'GIT_OBJECT_DIRECTORY'
).
and_return
(
dir
)
end
it
{
expect
(
subject
).
to
eq
(
dir
)
}
end
context
'when GIT_OBJECT_DIRECTORY is not set'
do
it
{
expect
(
subject
).
to
be_nil
}
end
end
describe
'.absolute_alt_object_dirs'
do
subject
{
described_class
.
absolute_alt_object_dirs
}
context
'when GIT_ALTERNATE_OBJECT_DIRECTORIES is set'
do
let
(
:dirs
)
{
[
'/home/git/repositories/foo/bar.git/./incoming-UKU6Gl'
,
'/home/git/repositories/foo/bar.git/./incoming-AcU7Qr'
]
}
before
do
allow
(
ENV
).
to
receive
(
:[]
).
with
(
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
).
and_return
(
dirs
.
join
(
File
::
PATH_SEPARATOR
))
end
it
{
expect
(
subject
).
to
eq
(
dirs
)
}
end
context
'when GIT_ALTERNATE_OBJECT_DIRECTORIES is not set'
do
it
{
expect
(
subject
).
to
eq
([])
}
end
end
describe
'.relative_alt_object_dirs'
do
subject
{
described_class
.
relative_alt_object_dirs
}
context
'when GIT_ALTERNATE_OBJECT_DIRECTORIES is set'
do
let
(
:dirs
)
{
[
'/home/git/repositories/foo/bar.git/./objects/incoming-UKU6Gl'
,
'/home/git/repositories/foo/bar.git/./objects/incoming-AcU7Qr'
]
}
before
do
allow
(
ENV
).
to
receive
(
:[]
).
with
(
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
).
and_return
(
dirs
.
join
(
File
::
PATH_SEPARATOR
))
end
it
{
expect
(
subject
).
to
eq
([
'objects/incoming-UKU6Gl'
,
'objects/incoming-AcU7Qr'
])
}
end
context
'when GIT_ALTERNATE_OBJECT_DIRECTORIES is not set'
do
it
{
expect
(
subject
).
to
eq
([])
}
end
end
describe
'.relative_object_dir'
do
subject
{
described_class
.
relative_object_dir
}
context
'when GIT_OBJECT_DIRECTORY is set'
do
before
do
allow
(
ENV
).
to
receive
(
:[]
).
with
(
'GIT_OBJECT_DIRECTORY'
).
and_return
(
'/home/git/repositories/foo/bar.git/./objects'
)
end
it
{
expect
(
subject
).
to
eq
(
'objects'
)
}
end
context
'when GIT_OBJECT_DIRECTORY is not set'
do
it
{
expect
(
subject
).
to
be_nil
}
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