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
894157ad
Commit
894157ad
authored
May 29, 2019
by
Patrick Bajao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add feature flag enabled by default
parent
6e46fa00
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
45 deletions
+67
-45
ee/lib/ee/gitlab/git_access.rb
ee/lib/ee/gitlab/git_access.rb
+9
-3
ee/spec/lib/gitlab/git_access_spec.rb
ee/spec/lib/gitlab/git_access_spec.rb
+58
-42
No files found.
ee/lib/ee/gitlab/git_access.rb
View file @
894157ad
...
@@ -84,8 +84,6 @@ module EE
...
@@ -84,8 +84,6 @@ module EE
def
check_push_size!
def
check_push_size!
return
unless
check_size_limit?
return
unless
check_size_limit?
git_env
=
::
Gitlab
::
Git
::
HookEnv
.
all
(
repository
.
gl_repository
)
# Use #quarantine_size to get correct push size whenever a lof of changes
# Use #quarantine_size to get correct push size whenever a lof of changes
# gets pushed at the same time containing the same blobs. This is only
# gets pushed at the same time containing the same blobs. This is only
# doable if GIT_OBJECT_DIRECTORY_RELATIVE env var is set and happens
# doable if GIT_OBJECT_DIRECTORY_RELATIVE env var is set and happens
...
@@ -94,13 +92,21 @@ module EE
...
@@ -94,13 +92,21 @@ module EE
# Fallback to determining push size using the changes_list so we can still
# Fallback to determining push size using the changes_list so we can still
# determine the push size if env var isn't set (e.g. changes are made
# determine the push size if env var isn't set (e.g. changes are made
# via UI and API).
# via UI and API).
push_size
=
git_env
[
'GIT_OBJECT_DIRECTORY_RELATIVE'
].
present
?
?
quarantine_size
:
changes_size
push_size
=
check_quarantine_size
?
?
quarantine_size
:
changes_size
if
project
.
changes_will_exceed_size_limit?
(
push_size
)
if
project
.
changes_will_exceed_size_limit?
(
push_size
)
raise
::
Gitlab
::
GitAccess
::
UnauthorizedError
,
::
Gitlab
::
RepositorySizeError
.
new
(
project
).
new_changes_error
raise
::
Gitlab
::
GitAccess
::
UnauthorizedError
,
::
Gitlab
::
RepositorySizeError
.
new
(
project
).
new_changes_error
end
end
end
end
def
check_quarantine_size?
strong_memoize
(
:check_quarantine_size
)
do
git_env
=
::
Gitlab
::
Git
::
HookEnv
.
all
(
repository
.
gl_repository
)
git_env
[
'GIT_OBJECT_DIRECTORY_RELATIVE'
].
present?
&&
::
Feature
.
enabled?
(
:quarantine_push_size_check
,
default_enabled:
true
)
end
end
def
quarantine_size
def
quarantine_size
project
.
repository
.
object_directory_size
project
.
repository
.
object_directory_size
end
end
...
...
ee/spec/lib/gitlab/git_access_spec.rb
View file @
894157ad
...
@@ -220,21 +220,7 @@ describe Gitlab::GitAccess do
...
@@ -220,21 +220,7 @@ describe Gitlab::GitAccess do
end
end
end
end
context
'when GIT_OBJECT_DIRECTORY_RELATIVE env var is set'
do
shared_examples_for
'a push to repository using git-rev-list for checking against repository size limit'
do
let
(
:object_directory_size
)
{
1
.
megabyte
}
before
do
allow
(
Gitlab
::
Git
::
HookEnv
)
.
to
receive
(
:all
)
.
with
(
repository
.
gl_repository
)
.
and_return
({
'GIT_OBJECT_DIRECTORY_RELATIVE'
=>
'objects'
})
# Stub the object directory size to "simulate" quarantine size
allow
(
repository
)
.
to
receive
(
:object_directory_size
)
.
and_return
(
object_directory_size
)
end
context
'when repository size is over limit'
do
context
'when repository size is over limit'
do
let
(
:repository_size
)
{
2
.
megabytes
}
let
(
:repository_size
)
{
2
.
megabytes
}
let
(
:repository_size_limit
)
{
1
.
megabyte
}
let
(
:repository_size_limit
)
{
1
.
megabyte
}
...
@@ -248,18 +234,20 @@ describe Gitlab::GitAccess do
...
@@ -248,18 +234,20 @@ describe Gitlab::GitAccess do
it_behaves_like
'a push to repository below the limit'
it_behaves_like
'a push to repository below the limit'
context
'when object directory (quarantine) size exceeds the limit'
do
context
'when new change exceeds the limit'
do
let
(
:object_directory_size
)
{
2
.
megabytes
}
it
'rejects the push'
do
it
'rejects the push'
do
expect
(
repository
.
new_blobs
(
sha_with_2_mb_file
)).
to
be_present
expect
do
expect
do
push_changes
(
"
#{
Gitlab
::
Git
::
BLANK_SHA
}
#{
sha_with_2_mb_file
}
refs/heads/my_branch_2"
)
push_changes
(
"
#{
Gitlab
::
Git
::
BLANK_SHA
}
#{
sha_with_2_mb_file
}
refs/heads/my_branch_2"
)
end
.
to
raise_error
(
described_class
::
UnauthorizedError
,
/Your push to this repository would cause it to exceed the size limit/
)
end
.
to
raise_error
(
described_class
::
UnauthorizedError
,
/Your push to this repository would cause it to exceed the size limit/
)
end
end
end
end
context
'when
object directory (quarantine) siz
e does not exceed the limit'
do
context
'when
new chang
e does not exceed the limit'
do
it
'accepts the push'
do
it
'accepts the push'
do
expect
(
repository
.
new_blobs
(
sha_with_smallest_changes
)).
to
be_present
expect
do
expect
do
push_changes
(
"
#{
Gitlab
::
Git
::
BLANK_SHA
}
#{
sha_with_smallest_changes
}
refs/heads/my_branch_3"
)
push_changes
(
"
#{
Gitlab
::
Git
::
BLANK_SHA
}
#{
sha_with_smallest_changes
}
refs/heads/my_branch_3"
)
end
.
not_to
raise_error
end
.
not_to
raise_error
...
@@ -268,40 +256,68 @@ describe Gitlab::GitAccess do
...
@@ -268,40 +256,68 @@ describe Gitlab::GitAccess do
end
end
end
end
context
'when GIT_OBJECT_DIRECTORY_RELATIVE env var is
not
set'
do
context
'when GIT_OBJECT_DIRECTORY_RELATIVE env var is set'
do
context
'when repository size is over limit'
do
before
do
let
(
:repository_size
)
{
2
.
megabytes
}
allow
(
Gitlab
::
Git
::
HookEnv
)
let
(
:repository_size_limit
)
{
1
.
megabyte
}
.
to
receive
(
:all
)
.
with
(
repository
.
gl_repository
)
it_behaves_like
'a push to repository over the limit'
.
and_return
({
'GIT_OBJECT_DIRECTORY_RELATIVE'
=>
'objects'
})
end
end
context
'when repository size is below the limit'
do
context
'when quarantine_push_size_check feature is enabled (default)'
do
let
(
:repository_size
)
{
1
.
megabyte
}
let
(
:object_directory_size
)
{
1
.
megabyte
}
let
(
:repository_size_limit
)
{
2
.
megabytes
}
it_behaves_like
'a push to repository below the limit'
before
do
# Stub the object directory size to "simulate" quarantine size
allow
(
repository
)
.
to
receive
(
:object_directory_size
)
.
and_return
(
object_directory_size
)
end
context
'when
new change exceeds the
limit'
do
context
'when
repository size is over
limit'
do
it
'rejects the push'
do
let
(
:repository_size
)
{
2
.
megabytes
}
expect
(
repository
.
new_blobs
(
sha_with_2_mb_file
)).
to
be_present
let
(
:repository_size_limit
)
{
1
.
megabyte
}
expect
do
it_behaves_like
'a push to repository over the limit'
push_changes
(
"
#{
Gitlab
::
Git
::
BLANK_SHA
}
#{
sha_with_2_mb_file
}
refs/heads/my_branch_2"
)
end
.
to
raise_error
(
described_class
::
UnauthorizedError
,
/Your push to this repository would cause it to exceed the size limit/
)
end
end
end
context
'when
new change does not exceed
the limit'
do
context
'when
repository size is below
the limit'
do
it
'accepts the push'
do
let
(
:repository_size
)
{
1
.
megabyte
}
expect
(
repository
.
new_blobs
(
sha_with_smallest_changes
)).
to
be_present
let
(
:repository_size_limit
)
{
2
.
megabytes
}
expect
do
it_behaves_like
'a push to repository below the limit'
push_changes
(
"
#{
Gitlab
::
Git
::
BLANK_SHA
}
#{
sha_with_smallest_changes
}
refs/heads/my_branch_3"
)
end
.
not_to
raise_error
context
'when object directory (quarantine) size exceeds the limit'
do
let
(
:object_directory_size
)
{
2
.
megabytes
}
it
'rejects the push'
do
expect
do
push_changes
(
"
#{
Gitlab
::
Git
::
BLANK_SHA
}
#{
sha_with_2_mb_file
}
refs/heads/my_branch_2"
)
end
.
to
raise_error
(
described_class
::
UnauthorizedError
,
/Your push to this repository would cause it to exceed the size limit/
)
end
end
context
'when object directory (quarantine) size does not exceed the limit'
do
it
'accepts the push'
do
expect
do
push_changes
(
"
#{
Gitlab
::
Git
::
BLANK_SHA
}
#{
sha_with_smallest_changes
}
refs/heads/my_branch_3"
)
end
.
not_to
raise_error
end
end
end
end
end
end
end
context
'when quarantine_push_size_check feature is disabled'
do
before
do
stub_feature_flags
(
quarantine_push_size_check:
false
)
end
it_behaves_like
'a push to repository using git-rev-list for checking against repository size limit'
end
end
context
'when GIT_OBJECT_DIRECTORY_RELATIVE env var is not set'
do
it_behaves_like
'a push to repository using git-rev-list for checking against repository size limit'
end
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