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
f8476338
Commit
f8476338
authored
Feb 05, 2020
by
João Cunha
Committed by
Grzegorz Bizon
Feb 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enforce Gitlab::Utils::DeepSize `max_size` and `max_depth` defaults
parent
63fe208c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
13 deletions
+29
-13
lib/gitlab/utils/deep_size.rb
lib/gitlab/utils/deep_size.rb
+2
-2
spec/lib/gitlab/utils/deep_size_spec.rb
spec/lib/gitlab/utils/deep_size_spec.rb
+27
-11
No files found.
lib/gitlab/utils/deep_size.rb
View file @
f8476338
...
...
@@ -13,8 +13,8 @@ module Gitlab
def
initialize
(
root
,
max_size:
DEFAULT_MAX_SIZE
,
max_depth:
DEFAULT_MAX_DEPTH
)
@root
=
root
@max_size
=
max_size
@max_depth
=
max_depth
@max_size
=
max_size
||
DEFAULT_MAX_SIZE
@max_depth
=
max_depth
||
DEFAULT_MAX_DEPTH
@size
=
0
@depth
=
0
...
...
spec/lib/gitlab/utils/deep_size_spec.rb
View file @
f8476338
...
...
@@ -17,29 +17,45 @@ describe Gitlab::Utils::DeepSize do
let
(
:max_size
)
{
1
.
kilobyte
}
let
(
:max_depth
)
{
10
}
let
(
:deep_size
)
{
described_class
.
new
(
data
,
max_size:
max_size
,
max_depth:
max_depth
)
}
describe
'#evaluate'
do
context
'when data within size and depth limits'
do
it
'returns true'
do
expect
(
deep_size
).
to
be_valid
subject
(
:deep_size
)
{
described_class
.
new
(
data
,
max_size:
max_size
,
max_depth:
max_depth
)
}
it
{
expect
(
described_class
::
DEFAULT_MAX_SIZE
).
to
eq
(
1
.
megabyte
)
}
it
{
expect
(
described_class
::
DEFAULT_MAX_DEPTH
).
to
eq
(
100
)
}
describe
'#initialize'
do
context
'when max_size is nil'
do
let
(
:max_size
)
{
nil
}
it
'sets max_size to DEFAULT_MAX_SIZE'
do
expect
(
subject
.
instance_variable_get
(
:@max_size
)).
to
eq
(
described_class
::
DEFAULT_MAX_SIZE
)
end
end
context
'when max_depth is nil'
do
let
(
:max_depth
)
{
nil
}
it
'sets max_depth to DEFAULT_MAX_DEPTH'
do
expect
(
subject
.
instance_variable_get
(
:@max_depth
)).
to
eq
(
described_class
::
DEFAULT_MAX_DEPTH
)
end
end
end
describe
'#valid?'
do
context
'when data within size and depth limits'
do
it
{
is_expected
.
to
be_valid
}
end
context
'when data not within size limit'
do
let
(
:max_size
)
{
200
.
bytes
}
it
'returns false'
do
expect
(
deep_size
).
not_to
be_valid
end
it
{
is_expected
.
not_to
be_valid
}
end
context
'when data not within depth limit'
do
let
(
:max_depth
)
{
2
}
it
'returns false'
do
expect
(
deep_size
).
not_to
be_valid
end
it
{
is_expected
.
not_to
be_valid
}
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