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
4afb42c6
Commit
4afb42c6
authored
Mar 16, 2021
by
Małgorzata Ksionek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for new groups controller behaviour
parent
de135860
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
4 deletions
+48
-4
app/controllers/groups_controller.rb
app/controllers/groups_controller.rb
+8
-4
config/feature_flags/ops/recaptcha_on_group_creation.yml
config/feature_flags/ops/recaptcha_on_group_creation.yml
+8
-0
spec/controllers/groups_controller_spec.rb
spec/controllers/groups_controller_spec.rb
+32
-0
No files found.
app/controllers/groups_controller.rb
View file @
4afb42c6
...
...
@@ -16,7 +16,7 @@ class GroupsController < Groups::ApplicationController
prepend_before_action
(
only:
[
:show
,
:issues
])
{
authenticate_sessionless_user!
(
:rss
)
}
prepend_before_action
(
only:
[
:issues_calendar
])
{
authenticate_sessionless_user!
(
:ics
)
}
prepend_before_action
:ensure_export_enabled
,
only:
[
:export
,
:download_export
]
prepend_before_action
:check_captcha
,
only: :create
prepend_before_action
:check_captcha
,
only: :create
,
if:
->
{
recaptcha_on_group_creation_enabled?
}
before_action
:authenticate_user!
,
only:
[
:new
,
:create
]
before_action
:group
,
except:
[
:index
,
:new
,
:create
]
...
...
@@ -24,7 +24,7 @@ class GroupsController < Groups::ApplicationController
# Authorize
before_action
:authorize_admin_group!
,
only:
[
:edit
,
:update
,
:destroy
,
:projects
,
:transfer
,
:export
,
:download_export
]
before_action
:authorize_create_group!
,
only:
[
:new
]
before_action
:load_recaptcha
,
only:
[
:new
]
before_action
:load_recaptcha
,
only:
[
:new
]
,
if:
->
{
recaptcha_on_group_creation_enabled?
}
before_action
:group_projects
,
only:
[
:projects
,
:activity
,
:issues
,
:merge_requests
]
before_action
:event_filter
,
only:
[
:activity
]
...
...
@@ -327,8 +327,8 @@ class GroupsController < Groups::ApplicationController
end
def
check_captcha
return
unless
captcha_enabled?
&&
load_recaptcha
return
if
group_params
[
:parent_id
].
present?
# Only require for top-level groups
return
unless
captcha_enabled?
&&
load_recaptcha
return
if
verify_recaptcha
...
...
@@ -363,7 +363,11 @@ class GroupsController < Groups::ApplicationController
end
def
captcha_required?
!
params
[
:parent_id
]
recaptcha_on_group_creation_enabled?
&&
!
params
[
:parent_id
]
end
def
recaptcha_on_group_creation_enabled?
Feature
.
enabled?
(
:recaptcha_on_group_creation
,
type: :ops
)
end
end
...
...
config/feature_flags/ops/recaptcha_on_group_creation.yml
0 → 100644
View file @
4afb42c6
---
name
:
recaptcha_on_group_creation
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56707
rollout_issue_url
:
milestone
:
'
13.10'
type
:
ops
group
:
group::access
default_enabled
:
false
spec/controllers/groups_controller_spec.rb
View file @
4afb42c6
...
...
@@ -312,6 +312,38 @@ RSpec.describe GroupsController, factory_default: :keep do
end
end
end
context
'when creating a group with captcha protection'
do
before
do
sign_in
(
user
)
stub_application_setting
(
recaptcha_enabled:
true
)
end
after
do
# Avoid test ordering issue and ensure `verify_recaptcha` returns true
unless
Recaptcha
.
configuration
.
skip_verify_env
.
include?
(
'test'
)
Recaptcha
.
configuration
.
skip_verify_env
<<
'test'
end
end
it
'displays an error when the reCAPTCHA is not solved'
do
allow_any_instance_of
(
described_class
).
to
receive
(
:verify_recaptcha
).
and_return
(
false
)
post
:create
,
params:
{
group:
{
name:
'new_group'
,
path:
"new_group"
}
}
expect
(
response
).
to
render_template
(
:new
)
expect
(
flash
[
:alert
]).
to
eq
(
_
(
'There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.'
))
end
it
'allows creating a group when the reCAPTCHA is solved'
do
expect
do
post
:create
,
params:
{
group:
{
name:
'new_group'
,
path:
"new_group"
}
}
end
.
to
change
{
Group
.
count
}.
by
(
1
)
expect
(
response
).
to
have_gitlab_http_status
(
:found
)
end
end
end
describe
'GET #index'
do
...
...
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