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
6d0e752c
Commit
6d0e752c
authored
Aug 04, 2020
by
Uday Aggarwal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added min value for max_content validation
parent
d1a6d7e8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
10 additions
and
48 deletions
+10
-48
app/helpers/application_settings_helper.rb
app/helpers/application_settings_helper.rb
+1
-2
app/models/application_setting.rb
app/models/application_setting.rb
+1
-2
app/models/application_setting_implementation.rb
app/models/application_setting_implementation.rb
+1
-2
app/models/wiki_page.rb
app/models/wiki_page.rb
+5
-13
spec/models/application_setting_spec.rb
spec/models/application_setting_spec.rb
+1
-2
spec/models/wiki_page_spec.rb
spec/models/wiki_page_spec.rb
+1
-27
No files found.
app/helpers/application_settings_helper.rb
View file @
6d0e752c
...
...
@@ -328,8 +328,7 @@ module ApplicationSettingsHelper
:group_import_limit
,
:group_export_limit
,
:group_download_export_limit
,
:wiki_page_max_content_bytes
,
:wiki_page_min_content_bytes
:wiki_page_max_content_bytes
]
end
...
...
app/models/application_setting.rb
View file @
6d0e752c
...
...
@@ -272,8 +272,7 @@ class ApplicationSetting < ApplicationRecord
numericality:
{
greater_than_or_equal_to:
0
}
validates
:snippet_size_limit
,
numericality:
{
only_integer:
true
,
greater_than:
0
}
validates
:wiki_page_max_content_bytes
,
numericality:
{
only_integer:
true
,
greater_than:
0
}
validates
:wiki_page_min_content_bytes
,
numericality:
{
only_integer:
true
,
greater_than:
0
}
validates
:wiki_page_max_content_bytes
,
numericality:
{
only_integer:
true
,
greater_than_or_equal_to:
1
.
kilobytes
}
validates
:email_restrictions
,
untrusted_regexp:
true
...
...
app/models/application_setting_implementation.rb
View file @
6d0e752c
...
...
@@ -165,8 +165,7 @@ module ApplicationSettingImplementation
user_default_external:
false
,
user_default_internal_regex:
nil
,
user_show_add_ssh_key_message:
true
,
wiki_page_max_content_bytes:
50
.
megabytes
,
wiki_page_min_content_bytes:
1
.
kilobytes
wiki_page_max_content_bytes:
50
.
megabytes
}
end
...
...
app/models/wiki_page.rb
View file @
6d0e752c
...
...
@@ -408,19 +408,11 @@ class WikiPage
def
validate_content_size_limit
current_value
=
raw_content
.
to_s
.
bytesize
max_size
=
Gitlab
::
CurrentSettings
.
wiki_page_max_content_bytes
min_size
=
Gitlab
::
CurrentSettings
.
wiki_page_min_content_bytes
return
if
current_value
<=
max_size
&&
current_value
>=
min_size
return
if
current_value
<=
max_size
if
current_value
>
max_size
errors
.
add
(
:content
,
_
(
'is too long (%{current_value}). The maximum size is %{max_size}.'
)
%
{
current_value:
ActiveSupport
::
NumberHelper
.
number_to_human_size
(
current_value
),
max_size:
ActiveSupport
::
NumberHelper
.
number_to_human_size
(
max_size
)
})
else
errors
.
add
(
:content
,
_
(
'is too short (%{current_value}). The minimum size is %{min_size}.'
)
%
{
current_value:
ActiveSupport
::
NumberHelper
.
number_to_human_size
(
current_value
),
min_size:
ActiveSupport
::
NumberHelper
.
number_to_human_size
(
min_size
)
})
end
errors
.
add
(
:content
,
_
(
'is too long (%{current_value}). The maximum size is %{max_size}.'
)
%
{
current_value:
ActiveSupport
::
NumberHelper
.
number_to_human_size
(
current_value
),
max_size:
ActiveSupport
::
NumberHelper
.
number_to_human_size
(
max_size
)
})
end
end
spec/models/application_setting_spec.rb
View file @
6d0e752c
...
...
@@ -72,8 +72,7 @@ RSpec.describe ApplicationSetting do
it
{
is_expected
.
not_to
allow_value
(
nil
).
for
(
:push_event_activities_limit
)
}
it
{
is_expected
.
to
validate_numericality_of
(
:snippet_size_limit
).
only_integer
.
is_greater_than
(
0
)
}
it
{
is_expected
.
to
validate_numericality_of
(
:wiki_page_max_content_bytes
).
only_integer
.
is_greater_than
(
0
)
}
it
{
is_expected
.
to
validate_numericality_of
(
:wiki_page_min_content_bytes
).
only_integer
.
is_greater_than
(
0
)
}
it
{
is_expected
.
to
validate_numericality_of
(
:wiki_page_max_content_bytes
).
only_integer
.
is_greater_than_or_equal_to
(
1024
)
}
it
{
is_expected
.
to
validate_presence_of
(
:max_artifacts_size
)
}
it
{
is_expected
.
to
validate_numericality_of
(
:max_artifacts_size
).
only_integer
.
is_greater_than
(
0
)
}
it
{
is_expected
.
to
validate_presence_of
(
:max_pages_size
)
}
...
...
spec/models/wiki_page_spec.rb
View file @
6d0e752c
...
...
@@ -275,7 +275,6 @@ RSpec.describe WikiPage do
context
'with a new page'
do
before
do
stub_application_setting
(
wiki_page_max_content_bytes:
10
)
stub_application_setting
(
wiki_page_min_content_bytes:
2
)
end
it
'accepts content below the limit'
do
...
...
@@ -284,12 +283,6 @@ RSpec.describe WikiPage do
expect
(
subject
).
to
be_valid
end
it
'accepts content above the limit'
do
subject
.
attributes
[
:content
]
=
'a'
*
2
expect
(
subject
).
to
be_valid
end
it
'rejects content exceeding the limit'
do
subject
.
attributes
[
:content
]
=
'a'
*
11
...
...
@@ -299,15 +292,6 @@ RSpec.describe WikiPage do
)
end
it
'rejects content below the limit'
do
subject
.
attributes
[
:content
]
=
'a'
expect
(
subject
).
not_to
be_valid
expect
(
subject
.
errors
.
messages
).
to
eq
(
content:
[
'is too short (1 Bytes). The minimum size is 2 Bytes.'
]
)
end
it
'counts content size in bytes rather than characters'
do
subject
.
attributes
[
:content
]
=
'💩💩💩'
...
...
@@ -324,14 +308,13 @@ RSpec.describe WikiPage do
before
do
subject
stub_application_setting
(
wiki_page_max_content_bytes:
11
)
stub_application_setting
(
wiki_page_min_content_bytes:
2
)
end
it
'accepts content when it has not changed'
do
expect
(
subject
).
to
be_valid
end
it
'rejects content when it has changed
and exceeds the limit
'
do
it
'rejects content when it has changed'
do
subject
.
attributes
[
:content
]
=
'a'
*
12
expect
(
subject
).
not_to
be_valid
...
...
@@ -339,15 +322,6 @@ RSpec.describe WikiPage do
content:
[
'is too long (12 Bytes). The maximum size is 11 Bytes.'
]
)
end
it
'rejects content when it has changed and is below the limit'
do
subject
.
attributes
[
:content
]
=
'a'
*
1
expect
(
subject
).
not_to
be_valid
expect
(
subject
.
errors
.
messages
).
to
eq
(
content:
[
'is too short (1 Bytes). The minimum size is 2 Bytes.'
]
)
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