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
79437672
Commit
79437672
authored
Jul 15, 2016
by
Patricio Cano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored the domain separator regex, plus syntax and grammar fixes.
parent
e15fa67c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
20 deletions
+19
-20
app/models/application_setting.rb
app/models/application_setting.rb
+10
-11
doc/administration/access_restrictions.md
doc/administration/access_restrictions.md
+1
-1
spec/models/application_setting_spec.rb
spec/models/application_setting_spec.rb
+5
-5
spec/models/user_spec.rb
spec/models/user_spec.rb
+3
-3
No files found.
app/models/application_setting.rb
View file @
79437672
...
...
@@ -4,6 +4,12 @@ class ApplicationSetting < ActiveRecord::Base
add_authentication_token_field
:health_check_access_token
CACHE_KEY
=
'application_setting.last'
DOMAIN_LIST_SEPARATOR
=
%r{
\s
*[,;]
\s
* # comma or semicolon, optionally surrounded by whitespace
| # or
\s
# any whitespace character
| # or
[
\r\n
] # any number of newline characters
}x
serialize
:restricted_visibility_levels
serialize
:import_sources
...
...
@@ -164,25 +170,18 @@ class ApplicationSetting < ActiveRecord::Base
self
.
domain_blacklist
.
join
(
"
\n
"
)
unless
self
.
domain_blacklist
.
nil?
end
def
splitter
/\s*[,;]\s* # comma or semicolon, optionally surrounded by whitespace
| # or
\s # any whitespace character
| # or
[\r\n] # any number of newline characters
/x
end
def
restricted_signup_domains_raw
=
(
values
)
self
.
restricted_signup_domains
=
[]
self
.
restricted_signup_domains
=
values
.
split
(
splitter
)
self
.
restricted_signup_domains
=
values
.
split
(
DOMAIN_LIST_SEPARATOR
)
self
.
restricted_signup_domains
.
reject!
{
|
d
|
d
.
empty?
}
self
.
restricted_signup_domains
end
def
domain_blacklist_raw
=
(
values
)
self
.
domain_blacklist
=
[]
self
.
domain_blacklist
=
values
.
split
(
splitter
)
self
.
domain_blacklist
=
values
.
split
(
DOMAIN_LIST_SEPARATOR
)
self
.
domain_blacklist
.
reject!
{
|
d
|
d
.
empty?
}
self
.
domain_blacklist
end
def
domain_blacklist_file
=
(
file
)
...
...
doc/administration/access_restrictions.md
View file @
79437672
...
...
@@ -39,7 +39,7 @@ not selected.
## Blacklist email domains
With this feature enabled, you can block email addresses of a
n
specific domain
With this feature enabled, you can block email addresses of a specific domain
from creating an account on your GitLab server. This is particularly useful to
prevent spam. Disposable email addresses are usually used by malicious users to
create dummy accounts and spam issues.
...
...
spec/models/application_setting_spec.rb
View file @
79437672
...
...
@@ -77,27 +77,27 @@ describe ApplicationSetting, models: true do
context
'blacklisted signup domains'
do
it
'set single domain'
do
setting
.
domain_blacklist_raw
=
'example.com'
expect
(
setting
.
domain_blacklist
).
to
eq
([
'example.com'
]
)
expect
(
setting
.
domain_blacklist
).
to
contain_exactly
(
'example.com'
)
end
it
'set multiple domains with spaces'
do
setting
.
domain_blacklist_raw
=
'example.com *.example.com'
expect
(
setting
.
domain_blacklist
).
to
eq
([
'example.com'
,
'*.example.com'
]
)
expect
(
setting
.
domain_blacklist
).
to
contain_exactly
(
'example.com'
,
'*.example.com'
)
end
it
'set multiple domains with newlines and a space'
do
setting
.
domain_blacklist_raw
=
"example.com
\n
*.example.com"
expect
(
setting
.
domain_blacklist
).
to
eq
([
'example.com'
,
'*.example.com'
]
)
expect
(
setting
.
domain_blacklist
).
to
contain_exactly
(
'example.com'
,
'*.example.com'
)
end
it
'set multiple domains with commas'
do
setting
.
domain_blacklist_raw
=
"example.com, *.example.com"
expect
(
setting
.
domain_blacklist
).
to
eq
([
'example.com'
,
'*.example.com'
]
)
expect
(
setting
.
domain_blacklist
).
to
contain_exactly
(
'example.com'
,
'*.example.com'
)
end
it
'set multiple domain with file'
do
setting
.
domain_blacklist_file
=
File
.
open
(
Rails
.
root
.
join
(
'spec/fixtures/'
,
'blacklist.txt'
))
expect
(
setting
.
domain_blacklist
).
to
eq
(
%w(example.com test.com foo.bar)
)
expect
(
setting
.
domain_blacklist
).
to
contain_exactly
(
'example.com'
,
'test.com'
,
'foo.bar'
)
end
end
end
spec/models/user_spec.rb
View file @
79437672
...
...
@@ -89,7 +89,7 @@ describe User, models: true do
end
describe
'email'
do
context
'when no signup domains white
listed'
do
context
'when no signup domains whitelisted'
do
before
do
allow_any_instance_of
(
ApplicationSetting
).
to
receive
(
:restricted_signup_domains
).
and_return
([])
end
...
...
@@ -100,7 +100,7 @@ describe User, models: true do
end
end
context
'when a signup domain is white
listed and subdomains are allowed'
do
context
'when a signup domain is whitelisted and subdomains are allowed'
do
before
do
allow_any_instance_of
(
ApplicationSetting
).
to
receive
(
:restricted_signup_domains
).
and_return
([
'example.com'
,
'*.example.com'
])
end
...
...
@@ -121,7 +121,7 @@ describe User, models: true do
end
end
context
'when a signup domain is white
listed and subdomains are not allowed'
do
context
'when a signup domain is whitelisted and subdomains are not allowed'
do
before
do
allow_any_instance_of
(
ApplicationSetting
).
to
receive
(
:restricted_signup_domains
).
and_return
([
'example.com'
])
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