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
8655855d
Commit
8655855d
authored
May 19, 2020
by
Imre Farkas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Limit scope of admin mode in Groups::PushRulesController specs
parent
4d2882b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
82 deletions
+87
-82
ee/spec/controllers/groups/push_rules_controller_spec.rb
ee/spec/controllers/groups/push_rules_controller_spec.rb
+87
-82
No files found.
ee/spec/controllers/groups/push_rules_controller_spec.rb
View file @
8655855d
...
...
@@ -74,135 +74,140 @@ describe Groups::PushRulesController do
patch
:update
,
params:
{
group_id:
group
,
push_rule:
{
prevent_secrets:
true
}
}
end
context
'when user is at least a maintainer'
do
before
do
sign_in
(
user
)
end
context
'push rules unlicensed'
do
before
do
sign_in
(
user
)
stub_licensed_features
(
push_rules:
false
)
group
.
add_maintainer
(
user
)
end
context
'push rules unlicensed'
do
before
do
stub_licensed_features
(
push_rules:
false
)
end
it
'returns 404 status'
do
do_update
it
'returns 404 status'
do
do_update
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
context
'push rules licensed'
,
:enable_admin_mode
do
before
do
stub_licensed_features
(
push_rules:
true
)
end
context
'push rules licensed'
do
before
do
stub_licensed_features
(
push_rules:
true
)
end
it
'updates the push rule'
do
do_update
shared_examples
'updateable setting'
do
|
rule_attr
,
new_value
|
it
'updates the setting'
do
patch
:update
,
params:
{
group_id:
group
,
push_rule:
{
rule_attr
=>
new_value
}
}
expect
(
response
).
to
have_gitlab_http_status
(
:found
)
expect
(
group
.
reload
.
push_rule
.
prevent_secrets
).
to
be_truthy
expect
(
group
.
reload
.
push_rule
.
public_send
(
rule_attr
)).
to
eq
(
new_value
)
end
end
shared_examples
'updateable setting'
do
|
rule_attr
,
new_value
|
it
'updates the setting'
do
shared_examples
'not updateable setting'
do
|
rule_attr
,
new_value
|
it
'does not update the setting'
do
expect
do
patch
:update
,
params:
{
group_id:
group
,
push_rule:
{
rule_attr
=>
new_value
}
}
end
.
not_to
change
{
group
.
reload
.
push_rule
.
public_send
(
rule_attr
)
}
end
end
expect
(
group
.
reload
.
push_rule
.
public_send
(
rule_attr
)).
to
eq
(
new_value
)
shared_examples
'an updatable setting with global default'
do
|
rule_attr
|
context
"when
#{
rule_attr
}
not specified on global level"
do
before
do
stub_licensed_features
(
rule_attr
=>
true
)
end
it_behaves_like
'updateable setting'
,
rule_attr
,
true
end
shared_examples
'not updateable setting'
do
|
rule_attr
,
new_value
|
it
'does not update the setting'
do
expect
do
patch
:update
,
params:
{
group_id:
group
,
push_rule:
{
rule_attr
=>
new_value
}
}
end
.
not_to
change
{
group
.
reload
.
push_rule
.
public_send
(
rule_attr
)
}
context
"when global setting
#{
rule_attr
}
is enabled"
do
before
do
stub_licensed_features
(
rule_attr
=>
true
)
create
(
:push_rule_sample
,
rule_attr
=>
true
)
end
end
shared_examples
'an updatable setting with global default'
do
|
rule_attr
|
context
"when
#{
rule_attr
}
not specified on global level"
do
before
do
stub_licensed_features
(
rule_attr
=>
true
)
end
it_behaves_like
'updateable setting'
,
rule_attr
,
true
end
end
it_behaves_like
'updateable setting'
,
rule_attr
,
true
shared_examples
'a not updatable setting with global default'
do
|
rule_attr
|
context
"when
#{
rule_attr
}
is disabled"
do
before
do
stub_licensed_features
(
rule_attr
=>
false
)
end
context
"when global setting
#{
rule_attr
}
is enabled"
do
before
do
stub_licensed_features
(
rule_attr
=>
true
)
create
(
:push_rule_sample
,
rule_attr
=>
true
)
end
it_behaves_like
'not updateable setting'
,
rule_attr
,
true
end
it_behaves_like
'updateable setting'
,
rule_attr
,
true
context
"when global setting
#{
rule_attr
}
is enabled"
do
before
do
stub_licensed_features
(
rule_attr
=>
true
)
create
(
:push_rule_sample
,
rule_attr
=>
true
)
end
it_behaves_like
'not updateable setting'
,
rule_attr
,
true
end
end
shared_examples
'a not updatable setting with global default'
do
|
rule_attr
|
context
"when
#{
rule_attr
}
is disabled"
do
before
do
stub_licensed_features
(
rule_attr
=>
false
)
end
PushRule
::
SETTINGS_WITH_GLOBAL_DEFAULT
.
each
do
|
rule_attr
|
context
"Updating
#{
rule_attr
}
rule"
do
let
(
:push_rule_for_group
)
{
create
(
:push_rule
,
rule_attr
=>
false
)
}
it_behaves_like
'not updateable setting'
,
rule_attr
,
true
before
do
group
.
update!
(
push_rule_id:
push_rule_for_group
.
id
)
end
context
"when global setting
#{
rule_attr
}
is enabled"
do
before
do
stub_licensed_features
(
rule_attr
=>
true
)
create
(
:push_rule_sample
,
rule_attr
=>
true
)
context
'as an admin'
do
let
(
:user
)
{
create
(
:admin
)
}
context
'when admin mode enabled'
,
:enable_admin_mode
do
it_behaves_like
'an updatable setting with global default'
,
rule_attr
,
updates:
true
end
it_behaves_like
'not updateable setting'
,
rule_attr
,
true
context
'when admin mode disabled'
do
it_behaves_like
'a not updatable setting with global default'
,
rule_attr
,
updates:
true
end
end
end
PushRule
::
SETTINGS_WITH_GLOBAL_DEFAULT
.
each
do
|
rule_attr
|
context
"Updating
#{
rule_attr
}
rule"
do
let
(
:push_rule_for_group
)
{
create
(
:push_rule
,
rule_attr
=>
false
)
}
context
'as a maintainer user'
do
before
do
group
.
update!
(
push_rule_id:
push_rule_for_group
.
id
)
group
.
add_maintainer
(
user
)
end
context
'as an admin
'
do
let
(
:user
)
{
create
(
:admin
)
}
it
'updates the push rule
'
do
do_update
it_behaves_like
'an updatable setting with global default'
,
rule_attr
,
updates:
true
expect
(
response
).
to
have_gitlab_http_status
(
:found
)
expect
(
group
.
reload
.
push_rule
.
prevent_secrets
).
to
be_truthy
end
context
'as a maintainer user'
do
context
"when global setting
#{
rule_attr
}
is disabled"
do
before
do
group
.
add_maintainer
(
user
)
stub_licensed_features
(
rule_attr
=>
false
)
create
(
:push_rule_sample
,
rule_attr
=>
true
)
end
context
"when global setting
#{
rule_attr
}
is disabled"
do
before
do
stub_licensed_features
(
rule_attr
=>
false
)
create
(
:push_rule_sample
,
rule_attr
=>
true
)
end
it_behaves_like
'updateable setting'
,
rule_attr
,
true
end
context
"when global setting
#{
rule_attr
}
is enabled"
do
before
do
stub_licensed_features
(
rule_attr
=>
true
)
create
(
:push_rule_sample
,
rule_attr
=>
true
)
end
it_behaves_like
'not updateable setting'
,
rule_attr
,
true
end
it_behaves_like
'updateable setting'
,
rule_attr
,
true
end
context
'as a developer user'
do
context
"when global setting
#{
rule_attr
}
is enabled"
do
before
do
group
.
add_developer
(
user
)
stub_licensed_features
(
rule_attr
=>
true
)
create
(
:push_rule_sample
,
rule_attr
=>
true
)
end
it_behaves_like
'a not updatable setting with global default'
,
rule_attr
it_behaves_like
'not updateable setting'
,
rule_attr
,
true
end
end
context
'as a developer user'
do
before
do
group
.
add_developer
(
user
)
end
it_behaves_like
'a not updatable setting with global default'
,
rule_attr
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