2016-07-26 03:35:47 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::EnvironmentsController do
|
2017-05-22 02:24:08 -04:00
|
|
|
set(:user) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
set(:project) { create(:project) }
|
2017-02-03 08:28:44 -05:00
|
|
|
|
2017-05-22 02:24:08 -04:00
|
|
|
set(:environment) do
|
2017-02-04 04:38:16 -05:00
|
|
|
create(:environment, name: 'production', project: project)
|
2017-02-03 08:28:44 -05:00
|
|
|
end
|
2016-07-26 03:35:47 -04:00
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2016-07-26 03:35:47 -04:00
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
2016-11-07 04:03:19 -05:00
|
|
|
describe 'GET index' do
|
2017-05-22 02:24:08 -04:00
|
|
|
context 'when a request for the HTML is made' do
|
2016-11-07 04:03:19 -05:00
|
|
|
it 'responds with status code 200' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :index, params: environment_params
|
2016-11-07 04:03:19 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-11-07 04:03:19 -05:00
|
|
|
end
|
2018-05-22 09:12:47 -04:00
|
|
|
|
|
|
|
it 'expires etag cache to force reload environments list' do
|
|
|
|
expect_any_instance_of(Gitlab::EtagCaching::Store)
|
|
|
|
.to receive(:touch).with(project_environments_path(project, format: :json))
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :index, params: environment_params
|
2018-05-22 09:12:47 -04:00
|
|
|
end
|
2016-11-07 04:03:19 -05:00
|
|
|
end
|
|
|
|
|
2017-02-03 08:28:44 -05:00
|
|
|
context 'when requesting JSON response for folders' do
|
|
|
|
before do
|
2017-02-04 04:38:16 -05:00
|
|
|
create(:environment, project: project,
|
|
|
|
name: 'staging/review-1',
|
|
|
|
state: :available)
|
|
|
|
|
|
|
|
create(:environment, project: project,
|
|
|
|
name: 'staging/review-2',
|
|
|
|
state: :available)
|
|
|
|
|
|
|
|
create(:environment, project: project,
|
|
|
|
name: 'staging/review-3',
|
|
|
|
state: :stopped)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:environments) { json_response['environments'] }
|
|
|
|
|
2019-01-16 15:05:19 -05:00
|
|
|
context 'with default parameters' do
|
|
|
|
before do
|
|
|
|
get :index, params: environment_params(format: :json)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds with a flat payload describing available environments' do
|
|
|
|
expect(environments.count).to eq 3
|
2019-02-26 14:13:09 -05:00
|
|
|
expect(environments.first).to include('name' => 'production', 'name_without_type' => 'production')
|
|
|
|
expect(environments.second).to include('name' => 'staging/review-1', 'name_without_type' => 'review-1')
|
|
|
|
expect(environments.third).to include('name' => 'staging/review-2', 'name_without_type' => 'review-2')
|
2019-01-16 15:05:19 -05:00
|
|
|
expect(json_response['available_count']).to eq 3
|
|
|
|
expect(json_response['stopped_count']).to eq 1
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the polling interval header' do
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response.headers['Poll-Interval']).to eq("3000")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a folder-based nested structure is requested' do
|
|
|
|
before do
|
|
|
|
get :index, params: environment_params(format: :json, nested: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds with a payload containing the latest environment for each folder' do
|
|
|
|
expect(environments.count).to eq 2
|
|
|
|
expect(environments.first['name']).to eq 'production'
|
|
|
|
expect(environments.second['name']).to eq 'staging'
|
|
|
|
expect(environments.second['size']).to eq 2
|
|
|
|
expect(environments.second['latest']['name']).to eq 'staging/review-2'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-04 04:38:16 -05:00
|
|
|
context 'when requesting available environments scope' do
|
|
|
|
before do
|
2019-01-16 15:05:19 -05:00
|
|
|
get :index, params: environment_params(format: :json, nested: true, scope: :available)
|
2017-02-04 04:38:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds with a payload describing available environments' do
|
|
|
|
expect(environments.count).to eq 2
|
|
|
|
expect(environments.first['name']).to eq 'production'
|
|
|
|
expect(environments.second['name']).to eq 'staging'
|
|
|
|
expect(environments.second['size']).to eq 2
|
|
|
|
expect(environments.second['latest']['name']).to eq 'staging/review-2'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains values describing environment scopes sizes' do
|
|
|
|
expect(json_response['available_count']).to eq 3
|
|
|
|
expect(json_response['stopped_count']).to eq 1
|
|
|
|
end
|
2017-02-03 08:28:44 -05:00
|
|
|
end
|
|
|
|
|
2017-02-04 04:38:16 -05:00
|
|
|
context 'when requesting stopped environments scope' do
|
|
|
|
before do
|
2019-01-16 15:05:19 -05:00
|
|
|
get :index, params: environment_params(format: :json, nested: true, scope: :stopped)
|
2017-02-04 04:38:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds with a payload describing stopped environments' do
|
|
|
|
expect(environments.count).to eq 1
|
|
|
|
expect(environments.first['name']).to eq 'staging'
|
|
|
|
expect(environments.first['size']).to eq 1
|
|
|
|
expect(environments.first['latest']['name']).to eq 'staging/review-3'
|
|
|
|
end
|
2016-11-07 04:03:19 -05:00
|
|
|
|
2017-02-04 04:38:16 -05:00
|
|
|
it 'contains values describing environment scopes sizes' do
|
|
|
|
expect(json_response['available_count']).to eq 3
|
|
|
|
expect(json_response['stopped_count']).to eq 1
|
|
|
|
end
|
2016-11-07 04:03:19 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-27 05:53:43 -04:00
|
|
|
describe 'GET folder' do
|
|
|
|
before do
|
|
|
|
create(:environment, project: project,
|
|
|
|
name: 'staging-1.0/review',
|
|
|
|
state: :available)
|
2017-05-17 07:36:19 -04:00
|
|
|
create(:environment, project: project,
|
2017-05-18 07:36:00 -04:00
|
|
|
name: 'staging-1.0/zzz',
|
2017-05-17 07:36:19 -04:00
|
|
|
state: :available)
|
2017-03-27 05:53:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when using default format' do
|
|
|
|
it 'responds with HTML' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :folder, params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
id: 'staging-1.0'
|
|
|
|
}
|
2017-03-27 05:53:43 -04:00
|
|
|
|
|
|
|
expect(response).to be_ok
|
|
|
|
expect(response).to render_template 'folder'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when using JSON format' do
|
2017-05-22 02:24:08 -04:00
|
|
|
it 'sorts the subfolders lexicographically' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :folder, params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
id: 'staging-1.0'
|
|
|
|
},
|
2017-03-27 05:53:43 -04:00
|
|
|
format: :json
|
|
|
|
|
|
|
|
expect(response).to be_ok
|
|
|
|
expect(response).not_to render_template 'folder'
|
|
|
|
expect(json_response['environments'][0])
|
2019-02-26 14:13:09 -05:00
|
|
|
.to include('name' => 'staging-1.0/review', 'name_without_type' => 'review')
|
2017-05-18 07:36:00 -04:00
|
|
|
expect(json_response['environments'][1])
|
2019-02-26 14:13:09 -05:00
|
|
|
.to include('name' => 'staging-1.0/zzz', 'name_without_type' => 'zzz')
|
2017-03-27 05:53:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-26 03:35:47 -04:00
|
|
|
describe 'GET show' do
|
|
|
|
context 'with valid id' do
|
|
|
|
it 'responds with a status code 200' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: environment_params
|
2016-07-26 03:35:47 -04:00
|
|
|
|
|
|
|
expect(response).to be_ok
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid id' do
|
|
|
|
it 'responds with a status code 404' do
|
2016-07-26 08:19:37 -04:00
|
|
|
params = environment_params
|
|
|
|
params[:id] = 12345
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: params
|
2016-07-26 03:35:47 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-07-26 03:35:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET edit' do
|
|
|
|
it 'responds with a status code 200' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :edit, params: environment_params
|
2016-07-26 03:35:47 -04:00
|
|
|
|
|
|
|
expect(response).to be_ok
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PATCH #update' do
|
|
|
|
it 'responds with a 302' do
|
2016-07-26 08:19:37 -04:00
|
|
|
patch_params = environment_params.merge(environment: { external_url: 'https://git.gitlab.com' })
|
2018-12-17 17:52:17 -05:00
|
|
|
patch :update, params: patch_params
|
2016-07-26 03:35:47 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(302)
|
2016-07-26 03:35:47 -04:00
|
|
|
end
|
|
|
|
end
|
2016-07-26 08:19:37 -04:00
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
describe 'PATCH #stop' do
|
|
|
|
context 'when env not available' do
|
|
|
|
it 'returns 404' do
|
|
|
|
allow_any_instance_of(Environment).to receive(:available?) { false }
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
patch :stop, params: environment_params(format: :json)
|
2017-05-09 00:15:34 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when stop action' do
|
|
|
|
it 'returns action url' do
|
|
|
|
action = create(:ci_build, :manual)
|
|
|
|
|
|
|
|
allow_any_instance_of(Environment)
|
|
|
|
.to receive_messages(available?: true, stop_with_action!: action)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
patch :stop, params: environment_params(format: :json)
|
2017-05-09 00:15:34 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-05-09 00:15:34 -04:00
|
|
|
expect(json_response).to eq(
|
|
|
|
{ 'redirect_url' =>
|
2017-06-29 13:06:35 -04:00
|
|
|
project_job_url(project, action) })
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no stop action' do
|
|
|
|
it 'returns env url' do
|
|
|
|
allow_any_instance_of(Environment)
|
|
|
|
.to receive_messages(available?: true, stop_with_action!: nil)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
patch :stop, params: environment_params(format: :json)
|
2017-05-09 00:15:34 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-05-09 00:15:34 -04:00
|
|
|
expect(json_response).to eq(
|
|
|
|
{ 'redirect_url' =>
|
2017-06-29 13:06:35 -04:00
|
|
|
project_environment_url(project, environment) })
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-22 14:55:56 -05:00
|
|
|
describe 'GET #terminal' do
|
|
|
|
context 'with valid id' do
|
|
|
|
it 'responds with a status code 200' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :terminal, params: environment_params
|
2016-11-22 14:55:56 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-11-22 14:55:56 -05:00
|
|
|
end
|
|
|
|
|
2018-10-30 06:53:01 -04:00
|
|
|
it 'loads the terminals for the environment' do
|
2018-11-28 11:00:11 -05:00
|
|
|
# In EE we have to stub EE::Environment since it overwrites the
|
|
|
|
# "terminals" method.
|
|
|
|
expect_any_instance_of(defined?(EE) ? EE::Environment : Environment)
|
|
|
|
.to receive(:terminals)
|
2016-11-22 14:55:56 -05:00
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :terminal, params: environment_params
|
2016-11-22 14:55:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid id' do
|
|
|
|
it 'responds with a status code 404' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :terminal, params: environment_params(id: 666)
|
2016-11-22 14:55:56 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-11-22 14:55:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #terminal_websocket_authorize' do
|
|
|
|
context 'with valid workhorse signature' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::Workhorse).to receive(:verify_api_request!).and_return(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and valid id' do
|
|
|
|
it 'returns the first terminal for the environment' do
|
2018-11-28 11:00:11 -05:00
|
|
|
# In EE we have to stub EE::Environment since it overwrites the
|
|
|
|
# "terminals" method.
|
|
|
|
expect_any_instance_of(defined?(EE) ? EE::Environment : Environment)
|
2017-06-21 09:48:12 -04:00
|
|
|
.to receive(:terminals)
|
|
|
|
.and_return([:fake_terminal])
|
|
|
|
|
|
|
|
expect(Gitlab::Workhorse)
|
|
|
|
.to receive(:terminal_websocket)
|
|
|
|
.with(:fake_terminal)
|
|
|
|
.and_return(workhorse: :response)
|
2016-11-22 14:55:56 -05:00
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :terminal_websocket_authorize, params: environment_params
|
2016-11-22 14:55:56 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-11-22 14:55:56 -05:00
|
|
|
expect(response.headers["Content-Type"]).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE)
|
|
|
|
expect(response.body).to eq('{"workhorse":"response"}')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and invalid id' do
|
|
|
|
it 'returns 404' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :terminal_websocket_authorize, params: environment_params(id: 666)
|
2016-12-14 19:59:04 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-11-22 14:55:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid workhorse signature' do
|
|
|
|
it 'aborts with an exception' do
|
|
|
|
allow(Gitlab::Workhorse).to receive(:verify_api_request!).and_raise(JWT::DecodeError)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
expect { get :terminal_websocket_authorize, params: environment_params }.to raise_error(JWT::DecodeError)
|
2016-11-22 14:55:56 -05:00
|
|
|
# controller tests don't set the response status correctly. It's enough
|
|
|
|
# to check that the action raised an exception
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-28 05:54:02 -04:00
|
|
|
describe 'GET #metrics_redirect' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
it 'redirects to environment if it exists' do
|
|
|
|
environment = create(:environment, name: 'production', project: project)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :metrics_redirect, params: { namespace_id: project.namespace, project_id: project }
|
2018-06-28 05:54:02 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to(environment_metrics_path(environment))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to empty page if no environment exists' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :metrics_redirect, params: { namespace_id: project.namespace, project_id: project }
|
2018-06-28 05:54:02 -04:00
|
|
|
|
2018-06-29 04:02:32 -04:00
|
|
|
expect(response).to be_ok
|
|
|
|
expect(response).to render_template 'empty'
|
2018-06-28 05:54:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-07 11:57:42 -05:00
|
|
|
describe 'GET #metrics' do
|
|
|
|
before do
|
|
|
|
allow(controller).to receive(:environment).and_return(environment)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when environment has no metrics' do
|
|
|
|
before do
|
|
|
|
expect(environment).to receive(:metrics).and_return(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a metrics page' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :metrics, params: environment_params
|
2017-03-07 11:57:42 -05:00
|
|
|
|
|
|
|
expect(response).to be_ok
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when requesting metrics as JSON' do
|
|
|
|
it 'returns a metrics JSON document' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :metrics, params: environment_params(format: :json)
|
2017-03-07 11:57:42 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(204)
|
2017-03-07 11:57:42 -05:00
|
|
|
expect(json_response).to eq({})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when environment has some metrics' do
|
|
|
|
before do
|
|
|
|
expect(environment).to receive(:metrics).and_return({
|
|
|
|
success: true,
|
|
|
|
metrics: {},
|
|
|
|
last_update: 42
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a metrics JSON document' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :metrics, params: environment_params(format: :json)
|
2017-03-07 11:57:42 -05:00
|
|
|
|
|
|
|
expect(response).to be_ok
|
|
|
|
expect(json_response['success']).to be(true)
|
|
|
|
expect(json_response['metrics']).to eq({})
|
|
|
|
expect(json_response['last_update']).to eq(42)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-05 12:38:09 -04:00
|
|
|
describe 'GET #additional_metrics' do
|
|
|
|
before do
|
|
|
|
allow(controller).to receive(:environment).and_return(environment)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when environment has no metrics' do
|
|
|
|
before do
|
|
|
|
expect(environment).to receive(:additional_metrics).and_return(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when requesting metrics as JSON' do
|
|
|
|
it 'returns a metrics JSON document' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :additional_metrics, params: environment_params(format: :json)
|
2017-06-05 12:38:09 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(204)
|
2017-06-05 12:38:09 -04:00
|
|
|
expect(json_response).to eq({})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when environment has some metrics' do
|
|
|
|
before do
|
2017-06-16 10:53:02 -04:00
|
|
|
expect(environment)
|
|
|
|
.to receive(:additional_metrics)
|
|
|
|
.and_return({
|
|
|
|
success: true,
|
|
|
|
data: {},
|
|
|
|
last_update: 42
|
|
|
|
})
|
2017-06-05 12:38:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a metrics JSON document' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :additional_metrics, params: environment_params(format: :json)
|
2017-06-05 12:38:09 -04:00
|
|
|
|
|
|
|
expect(response).to be_ok
|
|
|
|
expect(json_response['success']).to be(true)
|
|
|
|
expect(json_response['data']).to eq({})
|
|
|
|
expect(json_response['last_update']).to eq(42)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-05 02:14:30 -05:00
|
|
|
describe 'GET #search' do
|
|
|
|
before do
|
|
|
|
create(:environment, name: 'staging', project: project)
|
|
|
|
create(:environment, name: 'review/patch-1', project: project)
|
|
|
|
create(:environment, name: 'review/patch-2', project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:query) { 'pro' }
|
|
|
|
|
|
|
|
it 'responds with status code 200' do
|
|
|
|
get :search, params: environment_params(format: :json, query: query)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns matched results' do
|
|
|
|
get :search, params: environment_params(format: :json, query: query)
|
|
|
|
|
|
|
|
expect(json_response).to contain_exactly('production')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when query is review' do
|
|
|
|
let(:query) { 'review' }
|
|
|
|
|
|
|
|
it 'returns matched results' do
|
|
|
|
get :search, params: environment_params(format: :json, query: query)
|
|
|
|
|
|
|
|
expect(json_response).to contain_exactly('review/patch-1', 'review/patch-2')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when query is empty' do
|
|
|
|
let(:query) { '' }
|
|
|
|
|
|
|
|
it 'returns matched results' do
|
|
|
|
get :search, params: environment_params(format: :json, query: query)
|
|
|
|
|
|
|
|
expect(json_response)
|
|
|
|
.to contain_exactly('production', 'staging', 'review/patch-1', 'review/patch-2')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when query is review/patch-3' do
|
|
|
|
let(:query) { 'review/patch-3' }
|
|
|
|
|
|
|
|
it 'responds with status code 204' do
|
|
|
|
get :search, params: environment_params(format: :json, query: query)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:no_content)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when query is partially matched in the middle of environment name' do
|
|
|
|
let(:query) { 'patch' }
|
|
|
|
|
|
|
|
it 'responds with status code 204' do
|
|
|
|
get :search, params: environment_params(format: :json, query: query)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:no_content)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when query contains a wildcard character' do
|
|
|
|
let(:query) { 'review%' }
|
|
|
|
|
|
|
|
it 'prevents wildcard injection' do
|
|
|
|
get :search, params: environment_params(format: :json, query: query)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:no_content)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-07 04:03:19 -05:00
|
|
|
def environment_params(opts = {})
|
|
|
|
opts.reverse_merge(namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
id: environment.id)
|
2016-07-26 08:19:37 -04:00
|
|
|
end
|
2016-07-26 03:35:47 -04:00
|
|
|
end
|