2019-10-28 20:06:10 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-26 03:37:02 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe API::Environments do
|
2021-04-23 08:09:52 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:non_member) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, :private, :repository, namespace: user.namespace) }
|
|
|
|
let_it_be_with_reload(:environment) { create(:environment, project: project) }
|
2016-07-26 03:37:02 -04:00
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2016-07-26 03:37:02 -04:00
|
|
|
end
|
|
|
|
|
2021-05-03 08:09:49 -04:00
|
|
|
describe 'GET /projects/:id/environments', :aggregate_failures do
|
2016-07-26 03:37:02 -04:00
|
|
|
context 'as member of the project' do
|
2016-07-29 06:14:36 -04:00
|
|
|
it 'returns project environments' do
|
2016-07-26 03:37:02 -04:00
|
|
|
get api("/projects/#{project.id}/environments", user)
|
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-01-24 15:49:10 -05:00
|
|
|
expect(response).to include_pagination_headers
|
2016-07-26 03:37:02 -04:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.size).to eq(1)
|
|
|
|
expect(json_response.first['name']).to eq(environment.name)
|
|
|
|
expect(json_response.first['external_url']).to eq(environment.external_url)
|
2021-04-30 08:12:30 -04:00
|
|
|
expect(json_response.first['project']).to match_schema('public_api/v4/project')
|
2021-04-23 08:09:52 -04:00
|
|
|
expect(json_response.first['enable_advanced_logs_querying']).to eq(false)
|
|
|
|
expect(json_response.first).not_to have_key('last_deployment')
|
2021-05-03 08:09:49 -04:00
|
|
|
expect(json_response.first).not_to have_key('gitlab_managed_apps_logs_path')
|
2021-04-23 08:09:52 -04:00
|
|
|
end
|
|
|
|
|
2021-05-03 08:09:49 -04:00
|
|
|
context 'when the user can read pod logs' do
|
|
|
|
context 'with successful deployment on cluster' do
|
|
|
|
let_it_be(:deployment) { create(:deployment, :on_cluster, :success, environment: environment, project: project) }
|
|
|
|
|
|
|
|
it 'returns environment with enable_advanced_logs_querying and logs_api_path' do
|
|
|
|
get api("/projects/#{project.id}/environments", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.size).to eq(1)
|
|
|
|
expect(json_response.first['gitlab_managed_apps_logs_path']).to eq(
|
|
|
|
"/#{project.full_path}/-/logs/k8s.json?cluster_id=#{deployment.cluster_id}"
|
|
|
|
)
|
2021-04-23 08:09:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-03 08:09:49 -04:00
|
|
|
context 'when elastic stack is available' do
|
|
|
|
before do
|
|
|
|
allow_next_found_instance_of(Environment) do |env|
|
|
|
|
allow(env).to receive(:elastic_stack_available?).and_return(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns environment with enable_advanced_logs_querying and logs_api_path' do
|
2021-04-23 08:09:52 -04:00
|
|
|
get api("/projects/#{project.id}/environments", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.size).to eq(1)
|
|
|
|
expect(json_response.first['enable_advanced_logs_querying']).to eq(true)
|
2021-05-03 08:09:49 -04:00
|
|
|
expect(json_response.first['logs_api_path']).to eq(
|
|
|
|
"/#{project.full_path}/-/logs/elasticsearch.json?environment_name=#{environment.name}"
|
|
|
|
)
|
2021-04-23 08:09:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-03 08:09:49 -04:00
|
|
|
context 'when elastic stack is not available' do
|
2021-04-23 08:09:52 -04:00
|
|
|
before do
|
2021-05-03 08:09:49 -04:00
|
|
|
allow_next_found_instance_of(Environment) do |env|
|
|
|
|
allow(env).to receive(:elastic_stack_available?).and_return(false)
|
2021-04-23 08:09:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-03 08:09:49 -04:00
|
|
|
it 'returns environment with enable_advanced_logs_querying logs_api_path' do
|
2021-04-23 08:09:52 -04:00
|
|
|
get api("/projects/#{project.id}/environments", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.size).to eq(1)
|
2021-05-03 08:09:49 -04:00
|
|
|
expect(json_response.first['enable_advanced_logs_querying']).to eq(false)
|
|
|
|
expect(json_response.first['logs_api_path']).to eq(
|
|
|
|
"/#{project.full_path}/-/logs/k8s.json?environment_name=#{environment.name}"
|
|
|
|
)
|
2021-04-23 08:09:52 -04:00
|
|
|
end
|
|
|
|
end
|
2016-07-26 03:37:02 -04:00
|
|
|
end
|
2019-06-24 08:18:40 -04:00
|
|
|
|
2021-05-03 08:09:49 -04:00
|
|
|
context 'when the user cannot read pod logs' do
|
|
|
|
before do
|
|
|
|
allow_next_found_instance_of(User) do |user|
|
|
|
|
allow(user).to receive(:can?).and_call_original
|
|
|
|
allow(user).to receive(:can?).with(:read_pod_logs, project).and_return(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not contain enable_advanced_logs_querying' do
|
|
|
|
get api("/projects/#{project.id}/environments", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.size).to eq(1)
|
|
|
|
expect(json_response.first).not_to have_key('enable_advanced_logs_querying')
|
|
|
|
expect(json_response.first).not_to have_key('logs_api_path')
|
|
|
|
expect(json_response.first).not_to have_key('gitlab_managed_apps_logs_path')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-24 08:18:40 -04:00
|
|
|
context 'when filtering' do
|
2021-04-23 08:09:52 -04:00
|
|
|
let_it_be(:environment2) { create(:environment, project: project) }
|
2019-06-24 08:18:40 -04:00
|
|
|
|
|
|
|
it 'returns environment by name' do
|
|
|
|
get api("/projects/#{project.id}/environments?name=#{environment.name}", user)
|
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-06-24 08:18:40 -04:00
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.size).to eq(1)
|
|
|
|
expect(json_response.first['name']).to eq(environment.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns no environment by non-existent name' do
|
|
|
|
get api("/projects/#{project.id}/environments?name=test", user)
|
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-06-24 08:18:40 -04:00
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.size).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns environments by name_like' do
|
|
|
|
get api("/projects/#{project.id}/environments?search=envir", user)
|
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-06-24 08:18:40 -04:00
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.size).to eq(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns no environment by non-existent name_like' do
|
|
|
|
get api("/projects/#{project.id}/environments?search=test", user)
|
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-06-24 08:18:40 -04:00
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.size).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
2016-07-26 03:37:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'as non member' do
|
2016-07-29 06:14:36 -04:00
|
|
|
it 'returns a 404 status code' do
|
2016-07-26 03:37:02 -04:00
|
|
|
get api("/projects/#{project.id}/environments", non_member)
|
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-07-26 03:37:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-26 08:19:37 -04:00
|
|
|
describe 'POST /projects/:id/environments' do
|
2016-07-26 03:37:02 -04:00
|
|
|
context 'as a member' do
|
|
|
|
it 'creates a environment with valid params' do
|
2018-12-17 17:52:17 -05:00
|
|
|
post api("/projects/#{project.id}/environments", user), params: { name: "mepmep" }
|
2016-07-26 03:37:02 -04:00
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2016-07-26 03:37:02 -04:00
|
|
|
expect(json_response['name']).to eq('mepmep')
|
2016-12-07 20:09:18 -05:00
|
|
|
expect(json_response['slug']).to eq('mepmep')
|
2016-07-26 03:37:02 -04:00
|
|
|
expect(json_response['external']).to be nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'requires name to be passed' do
|
2018-12-17 17:52:17 -05:00
|
|
|
post api("/projects/#{project.id}/environments", user), params: { external_url: 'test.gitlab.com' }
|
2016-07-26 03:37:02 -04:00
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2016-07-26 03:37:02 -04:00
|
|
|
end
|
|
|
|
|
2016-07-29 06:14:36 -04:00
|
|
|
it 'returns a 400 if environment already exists' do
|
2018-12-17 17:52:17 -05:00
|
|
|
post api("/projects/#{project.id}/environments", user), params: { name: environment.name }
|
2016-07-26 03:37:02 -04:00
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2016-07-26 03:37:02 -04:00
|
|
|
end
|
2016-12-07 20:09:18 -05:00
|
|
|
|
|
|
|
it 'returns a 400 if slug is specified' do
|
2018-12-17 17:52:17 -05:00
|
|
|
post api("/projects/#{project.id}/environments", user), params: { name: "foo", slug: "foo" }
|
2016-12-07 20:09:18 -05:00
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2016-12-07 20:09:18 -05:00
|
|
|
expect(json_response["error"]).to eq("slug is automatically generated and cannot be changed")
|
|
|
|
end
|
2016-07-26 03:37:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'a non member' do
|
|
|
|
it 'rejects the request' do
|
2018-12-17 17:52:17 -05:00
|
|
|
post api("/projects/#{project.id}/environments", non_member), params: { name: 'gitlab.com' }
|
2016-07-26 03:37:02 -04:00
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-08-01 02:42:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 400 when the required params are missing' do
|
2020-04-01 11:07:45 -04:00
|
|
|
post api("/projects/#{non_existing_record_id}/environments", non_member), params: { external_url: 'http://env.git.com' }
|
2016-07-26 03:37:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-29 06:14:36 -04:00
|
|
|
describe 'PUT /projects/:id/environments/:environment_id' do
|
|
|
|
it 'returns a 200 if name and external_url are changed' do
|
|
|
|
url = 'https://mepmep.whatever.ninja'
|
|
|
|
put api("/projects/#{project.id}/environments/#{environment.id}", user),
|
2018-12-17 17:52:17 -05:00
|
|
|
params: { name: 'Mepmep', external_url: url }
|
2016-07-26 03:37:02 -04:00
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-07-29 06:14:36 -04:00
|
|
|
expect(json_response['name']).to eq('Mepmep')
|
|
|
|
expect(json_response['external_url']).to eq(url)
|
2016-07-26 03:37:02 -04:00
|
|
|
end
|
|
|
|
|
2016-12-07 20:09:18 -05:00
|
|
|
it "won't allow slug to be changed" do
|
|
|
|
slug = environment.slug
|
|
|
|
api_url = api("/projects/#{project.id}/environments/#{environment.id}", user)
|
2018-12-17 17:52:17 -05:00
|
|
|
put api_url, params: { slug: slug + "-foo" }
|
2016-12-07 20:09:18 -05:00
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2016-12-07 20:09:18 -05:00
|
|
|
expect(json_response["error"]).to eq("slug is automatically generated and cannot be changed")
|
|
|
|
end
|
|
|
|
|
2016-07-29 06:14:36 -04:00
|
|
|
it "won't update the external_url if only the name is passed" do
|
|
|
|
url = environment.external_url
|
2016-07-26 03:37:02 -04:00
|
|
|
put api("/projects/#{project.id}/environments/#{environment.id}", user),
|
2018-12-17 17:52:17 -05:00
|
|
|
params: { name: 'Mepmep' }
|
2016-07-26 03:37:02 -04:00
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-07-26 03:37:02 -04:00
|
|
|
expect(json_response['name']).to eq('Mepmep')
|
2016-07-29 06:14:36 -04:00
|
|
|
expect(json_response['external_url']).to eq(url)
|
2016-07-26 03:37:02 -04:00
|
|
|
end
|
|
|
|
|
2016-07-29 06:14:36 -04:00
|
|
|
it 'returns a 404 if the environment does not exist' do
|
2020-04-01 11:07:45 -04:00
|
|
|
put api("/projects/#{project.id}/environments/#{non_existing_record_id}", user)
|
2016-07-26 03:37:02 -04:00
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-07-26 03:37:02 -04:00
|
|
|
end
|
|
|
|
end
|
2016-07-29 06:14:36 -04:00
|
|
|
|
|
|
|
describe 'DELETE /projects/:id/environments/:environment_id' do
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'as a maintainer' do
|
2020-03-25 05:08:11 -04:00
|
|
|
it "rejects the requests in environment isn't stopped" do
|
|
|
|
delete api("/projects/#{project.id}/environments/#{environment.id}", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 200 for stopped environment' do
|
|
|
|
environment.stop
|
|
|
|
|
2016-07-29 06:14:36 -04:00
|
|
|
delete api("/projects/#{project.id}/environments/#{environment.id}", user)
|
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:no_content)
|
2016-07-29 06:14:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 404 for non existing id' do
|
2020-04-01 11:07:45 -04:00
|
|
|
delete api("/projects/#{project.id}/environments/#{non_existing_record_id}", user)
|
2016-07-29 06:14:36 -04:00
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-07-29 06:14:36 -04:00
|
|
|
expect(json_response['message']).to eq('404 Not found')
|
|
|
|
end
|
2017-08-24 12:03:39 -04:00
|
|
|
|
|
|
|
it_behaves_like '412 response' do
|
2020-03-25 05:08:11 -04:00
|
|
|
before do
|
|
|
|
environment.stop
|
|
|
|
end
|
|
|
|
|
2017-08-24 12:03:39 -04:00
|
|
|
let(:request) { api("/projects/#{project.id}/environments/#{environment.id}", user) }
|
|
|
|
end
|
2016-07-29 06:14:36 -04:00
|
|
|
end
|
2016-08-01 02:42:09 -04:00
|
|
|
|
|
|
|
context 'a non member' do
|
|
|
|
it 'rejects the request' do
|
|
|
|
delete api("/projects/#{project.id}/environments/#{environment.id}", non_member)
|
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-08-01 02:42:09 -04:00
|
|
|
end
|
|
|
|
end
|
2016-07-29 06:14:36 -04:00
|
|
|
end
|
2017-02-28 08:55:21 -05:00
|
|
|
|
|
|
|
describe 'POST /projects/:id/environments/:environment_id/stop' do
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'as a maintainer' do
|
2017-02-28 08:55:21 -05:00
|
|
|
context 'with a stoppable environment' do
|
|
|
|
before do
|
2021-04-05 14:09:15 -04:00
|
|
|
environment.update!(state: :available)
|
2017-02-28 08:55:21 -05:00
|
|
|
|
|
|
|
post api("/projects/#{project.id}/environments/#{environment.id}/stop", user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 200' do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-02-28 08:55:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'actually stops the environment' do
|
|
|
|
expect(environment.reload).to be_stopped
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 404 for non existing id' do
|
2020-04-01 11:07:45 -04:00
|
|
|
post api("/projects/#{project.id}/environments/#{non_existing_record_id}/stop", user)
|
2017-02-28 08:55:21 -05:00
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2017-02-28 08:55:21 -05:00
|
|
|
expect(json_response['message']).to eq('404 Not found')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'a non member' do
|
|
|
|
it 'rejects the request' do
|
|
|
|
post api("/projects/#{project.id}/environments/#{environment.id}/stop", non_member)
|
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2017-02-28 08:55:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-04-09 05:16:57 -04:00
|
|
|
|
|
|
|
describe 'GET /projects/:id/environments/:environment_id' do
|
|
|
|
context 'as member of the project' do
|
|
|
|
it 'returns project environments' do
|
|
|
|
create(:deployment, :success, project: project, environment: environment)
|
|
|
|
|
|
|
|
get api("/projects/#{project.id}/environments/#{environment.id}", user)
|
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-04-09 05:16:57 -04:00
|
|
|
expect(response).to match_response_schema('public_api/v4/environment')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as non member' do
|
|
|
|
it 'returns a 404 status code' do
|
|
|
|
get api("/projects/#{project.id}/environments/#{environment.id}", non_member)
|
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2019-04-09 05:16:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-03-11 22:08:56 -05:00
|
|
|
|
|
|
|
describe "DELETE /projects/:id/environments/review_apps" do
|
|
|
|
shared_examples "delete stopped review environments" do
|
|
|
|
around do |example|
|
|
|
|
freeze_time { example.run }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "deletes the old stopped review apps" do
|
|
|
|
old_stopped_review_env = create(:environment, :with_review_app, :stopped, created_at: 31.days.ago, project: project)
|
|
|
|
new_stopped_review_env = create(:environment, :with_review_app, :stopped, project: project)
|
|
|
|
old_active_review_env = create(:environment, :with_review_app, :available, created_at: 31.days.ago, project: project)
|
|
|
|
old_stopped_other_env = create(:environment, :stopped, created_at: 31.days.ago, project: project)
|
|
|
|
new_stopped_other_env = create(:environment, :stopped, project: project)
|
|
|
|
old_active_other_env = create(:environment, :available, created_at: 31.days.ago, project: project)
|
|
|
|
|
|
|
|
delete api("/projects/#{project.id}/environments/review_apps", current_user), params: { dry_run: false }
|
|
|
|
project.environments.reload
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response["scheduled_entries"].size).to eq(1)
|
|
|
|
expect(json_response["scheduled_entries"].first["id"]).to eq(old_stopped_review_env.id)
|
|
|
|
expect(json_response["unprocessable_entries"].size).to eq(0)
|
|
|
|
|
|
|
|
expect(old_stopped_review_env.reload.auto_delete_at).to eq(1.week.from_now)
|
|
|
|
expect(new_stopped_review_env.reload.auto_delete_at).to be_nil
|
|
|
|
expect(old_active_review_env.reload.auto_delete_at).to be_nil
|
|
|
|
expect(old_stopped_other_env.reload.auto_delete_at).to be_nil
|
|
|
|
expect(new_stopped_other_env.reload.auto_delete_at).to be_nil
|
|
|
|
expect(old_active_other_env.reload.auto_delete_at).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "as a maintainer" do
|
|
|
|
it_behaves_like "delete stopped review environments" do
|
|
|
|
let(:current_user) { user }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "as a developer" do
|
|
|
|
let(:developer) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(developer)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like "delete stopped review environments" do
|
|
|
|
let(:current_user) { developer }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "as a reporter" do
|
|
|
|
let(:reporter) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_reporter(reporter)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "rejects the request" do
|
|
|
|
delete api("/projects/#{project.id}/environments/review_apps", reporter)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "as a non member" do
|
|
|
|
it "rejects the request" do
|
|
|
|
delete api("/projects/#{project.id}/environments/review_apps", non_member)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-07-26 03:37:02 -04:00
|
|
|
end
|