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
6f14e36d
Commit
6f14e36d
authored
Dec 16, 2021
by
Vladlena Shumilo
Committed by
Kerri Miller
Dec 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent sync for ghosted user namespaces
parent
921fd6ab
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
5 deletions
+103
-5
ee/app/models/ee/namespace.rb
ee/app/models/ee/namespace.rb
+1
-0
ee/app/models/ee/user.rb
ee/app/models/ee/user.rb
+6
-0
ee/spec/models/ee/namespace_spec.rb
ee/spec/models/ee/namespace_spec.rb
+44
-5
ee/spec/models/ee/user_spec.rb
ee/spec/models/ee/user_spec.rb
+52
-0
No files found.
ee/app/models/ee/namespace.rb
View file @
6f14e36d
...
...
@@ -485,6 +485,7 @@ module EE
def
sync_name_with_customers_dot
return
unless
::
Gitlab
.
com?
return
if
user_namespace?
&&
owner
.
privatized_by_abuse_automation?
::
Namespaces
::
SyncNamespaceNameWorker
.
perform_async
(
id
)
end
...
...
ee/app/models/ee/user.rb
View file @
6f14e36d
...
...
@@ -436,6 +436,12 @@ module EE
credit_card_validated_at
.
present?
end
def
privatized_by_abuse_automation?
# Prevent abuse automation names are expected to be in the format: ghost-:id-:id. Ex: ghost-123-4567
# More context: https://gitlab.com/gitlab-org/customers-gitlab-com/-/issues/3871 for more context on the
private_profile?
&&
name
.
match?
(
/\Aghost-\d+-\d+\z/
)
end
protected
override
:password_required?
...
...
ee/spec/models/ee/namespace_spec.rb
View file @
6f14e36d
...
...
@@ -359,11 +359,14 @@ RSpec.describe Namespace do
describe
'after_commit :sync_name_with_customers_dot'
do
let
(
:namespace
)
{
create
(
:group
)
}
let
(
:privatized_by_abuse_automation
)
{
false
}
subject
(
:update_namespace
)
{
namespace
.
update!
(
attributes
)
}
before
do
allow
(
Gitlab
).
to
receive
(
:com?
).
and_return
(
true
)
allow
(
namespace
.
owner
).
to
receive
(
:privatized_by_abuse_automation?
)
.
and_return
(
privatized_by_abuse_automation
)
end
shared_examples
'no sync'
do
...
...
@@ -374,6 +377,15 @@ RSpec.describe Namespace do
end
end
shared_examples
'sync'
do
it
'triggers a name sync with CustomersDot'
do
expect
(
::
Namespaces
::
SyncNamespaceNameWorker
).
to
receive
(
:perform_async
)
.
with
(
namespace
.
id
).
once
update_namespace
end
end
context
'when the name is not updated'
do
let
(
:attributes
)
{
{
path:
'Foo'
}
}
...
...
@@ -394,14 +406,41 @@ RSpec.describe Namespace do
context
'when project namespace'
do
let
(
:namespace
)
{
create
(
:project_namespace
)
}
include_examples
'no sync'
context
'when the owner is privatized by abuse automation'
do
let
(
:privatized_by_abuse_automation
)
{
true
}
include_examples
'no sync'
end
context
'when the owner is not privatized by abuse automation'
do
include_examples
'no sync'
end
end
it
'triggers a name sync with CustomersDot
'
do
expect
(
::
Namespaces
::
SyncNamespaceNameWorker
).
to
receive
(
:perform_async
)
.
with
(
namespace
.
id
).
once
context
'when group namespace
'
do
context
'when the owner is privatized by abuse automation'
do
let
(
:privatized_by_abuse_automation
)
{
true
}
update_namespace
include_examples
'sync'
end
context
'when the owner is not privatized by abuse automation'
do
include_examples
'sync'
end
end
context
'when user namespace'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
context
'when the owner is privatized by abuse automation'
do
let
(
:privatized_by_abuse_automation
)
{
true
}
include_examples
'no sync'
end
context
'when the owner is not privatized by abuse automation'
do
include_examples
'sync'
end
end
end
end
...
...
ee/spec/models/ee/user_spec.rb
View file @
6f14e36d
...
...
@@ -2015,6 +2015,58 @@ RSpec.describe User do
end
end
describe
"#privatized_by_abuse_automation?"
do
let
(
:user
)
{
build
(
:user
,
private_profile:
true
,
name:
'ghost-123-456'
)
}
subject
(
:spam_check
)
{
user
.
privatized_by_abuse_automation?
}
context
'when the user has a non private profile'
do
it
'returns false'
do
user
.
private_profile
=
false
expect
(
spam_check
).
to
eq
false
end
end
context
'when the user name is not ghost-:id-:id like'
do
it
'returns false'
do
user
.
name
=
'spam-is-not-cool'
expect
(
spam_check
).
to
eq
false
end
end
context
'when the user name matches ghost-:id-:id'
do
context
'with extra chars at the beginning'
do
it
'returns false'
do
user
.
name
=
'ABCghost-123-456'
expect
(
spam_check
).
to
eq
false
end
end
context
'with extra chars at the end'
do
it
'returns false'
do
user
.
name
=
'ghost-123-456XYZ'
expect
(
spam_check
).
to
eq
false
end
end
context
'with extra chars at the beginning and the end'
do
it
'returns false'
do
user
.
name
=
'ABCghost-123-456XYZ'
expect
(
spam_check
).
to
eq
false
end
end
end
context
'when the user has a private profile and the format is ghost-:id-:id'
do
it
{
is_expected
.
to
eq
true
}
end
end
describe
'#activate_based_on_user_cap?'
do
using
RSpec
::
Parameterized
::
TableSyntax
...
...
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