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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
d945300b
Commit
d945300b
authored
Nov 14, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check permissions before stopping CI environments
parent
ec0daedb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
23 deletions
+50
-23
app/services/ci/stop_environment_service.rb
app/services/ci/stop_environment_service.rb
+1
-0
spec/services/ci/stop_environment_service_spec.rb
spec/services/ci/stop_environment_service_spec.rb
+49
-23
No files found.
app/services/ci/stop_environment_service.rb
View file @
d945300b
...
@@ -10,6 +10,7 @@ module Ci
...
@@ -10,6 +10,7 @@ module Ci
environments
.
each
do
|
environment
|
environments
.
each
do
|
environment
|
next
unless
environment
.
stoppable?
next
unless
environment
.
stoppable?
next
unless
can?
(
current_user
,
:create_deployment
,
project
)
environment
.
stop!
(
current_user
)
environment
.
stop!
(
current_user
)
end
end
...
...
spec/services/ci/stop_environment_service_spec.rb
View file @
d945300b
require
'spec_helper'
require
'spec_helper'
describe
Ci
::
StopEnvironmentService
,
services:
true
do
describe
Ci
::
StopEnvironmentService
,
services:
true
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
,
:private
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
)
}
...
@@ -12,25 +12,24 @@ describe Ci::StopEnvironmentService, services: true do
...
@@ -12,25 +12,24 @@ describe Ci::StopEnvironmentService, services: true do
create
(
:environment
,
:with_review_app
,
project:
project
)
create
(
:environment
,
:with_review_app
,
project:
project
)
end
end
it
'stops environment'
do
context
'when user has permission to stop environment'
do
expect_any_instance_of
(
Environment
).
to
receive
(
:stop!
)
before
do
project
.
team
<<
[
user
,
:developer
]
end
service
.
execute
(
'master'
)
it
'stops environment'
do
expect_environment_stopped_on
(
'master'
)
end
end
context
'when specified branch does not exist'
do
context
'when specified branch does not exist'
do
it
'does not stop environment'
do
it
'does not stop environment'
do
expect_any_instance_of
(
Environment
).
not_to
receive
(
:stop!
)
expect_environment_not_stopped_on
(
'non/existent/branch'
)
service
.
execute
(
'non/existent/branch'
)
end
end
end
end
context
'when no branch not specified'
do
context
'when no branch not specified'
do
it
'does not stop environment'
do
it
'does not stop environment'
do
expect_any_instance_of
(
Environment
).
not_to
receive
(
:stop!
)
expect_environment_not_stopped_on
(
nil
)
service
.
execute
(
nil
)
end
end
end
end
...
@@ -41,9 +40,18 @@ describe Ci::StopEnvironmentService, services: true do
...
@@ -41,9 +40,18 @@ describe Ci::StopEnvironmentService, services: true do
end
end
it
'does not stop environment'
do
it
'does not stop environment'
do
expect_any_instance_of
(
Environment
).
not_to
receive
(
:stop!
)
expect_environment_not_stopped_on
(
'master'
)
end
end
end
context
'when user does not have permission to stop environment'
do
before
do
project
.
team
<<
[
user
,
:guest
]
end
service
.
execute
(
'master'
)
it
'does not stop environment'
do
expect_environment_not_stopped_on
(
'master'
)
end
end
end
end
end
end
...
@@ -53,10 +61,14 @@ describe Ci::StopEnvironmentService, services: true do
...
@@ -53,10 +61,14 @@ describe Ci::StopEnvironmentService, services: true do
create
(
:environment
,
project:
project
)
create
(
:environment
,
project:
project
)
end
end
it
'does not stop environment'
do
context
'when user has permission to stop environments'
do
expect_any_instance_of
(
Environment
).
not_to
receive
(
:stop!
)
before
do
project
.
team
<<
[
user
,
:master
]
end
service
.
execute
(
'master'
)
it
'does not stop environment'
do
expect_environment_not_stopped_on
(
'master'
)
end
end
end
end
end
...
@@ -67,4 +79,18 @@ describe Ci::StopEnvironmentService, services: true do
...
@@ -67,4 +79,18 @@ describe Ci::StopEnvironmentService, services: true do
end
end
end
end
end
end
def
expect_environment_stopped_on
(
branch
)
expect_any_instance_of
(
Environment
)
.
to
receive
(
:stop!
)
service
.
execute
(
branch
)
end
def
expect_environment_not_stopped_on
(
branch
)
expect_any_instance_of
(
Environment
)
.
not_to
receive
(
:stop!
)
service
.
execute
(
branch
)
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