2021-04-17 20:07:23 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe API::Admin::PlanLimits, 'PlanLimits', feature_category: :shared do
|
2021-04-17 20:07:23 +05:30
|
|
|
let_it_be(:admin) { create(:admin) }
|
|
|
|
let_it_be(:plan) { create(:plan, name: 'default') }
|
2023-05-27 22:25:52 +05:30
|
|
|
let_it_be(:path) { '/application/plan_limits' }
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
describe 'GET /application/plan_limits' do
|
2023-05-27 22:25:52 +05:30
|
|
|
it_behaves_like 'GET request permissions for admin mode'
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
context 'as an admin user' do
|
|
|
|
context 'no params' do
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'returns plan limits', :aggregate_failures do
|
|
|
|
get api(path, admin, admin_mode: true)
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
expect(json_response).to be_an Hash
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(json_response['ci_pipeline_size']).to eq(Plan.default.actual_limits.ci_pipeline_size)
|
|
|
|
expect(json_response['ci_active_jobs']).to eq(Plan.default.actual_limits.ci_active_jobs)
|
|
|
|
expect(json_response['ci_project_subscriptions']).to eq(Plan.default.actual_limits.ci_project_subscriptions)
|
|
|
|
expect(json_response['ci_pipeline_schedules']).to eq(Plan.default.actual_limits.ci_pipeline_schedules)
|
|
|
|
expect(json_response['ci_needs_size_limit']).to eq(Plan.default.actual_limits.ci_needs_size_limit)
|
|
|
|
expect(json_response['ci_registered_group_runners']).to eq(Plan.default.actual_limits.ci_registered_group_runners)
|
|
|
|
expect(json_response['ci_registered_project_runners']).to eq(Plan.default.actual_limits.ci_registered_project_runners)
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(json_response['conan_max_file_size']).to eq(Plan.default.actual_limits.conan_max_file_size)
|
|
|
|
expect(json_response['generic_packages_max_file_size']).to eq(Plan.default.actual_limits.generic_packages_max_file_size)
|
2022-01-26 12:08:38 +05:30
|
|
|
expect(json_response['helm_max_file_size']).to eq(Plan.default.actual_limits.helm_max_file_size)
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(json_response['maven_max_file_size']).to eq(Plan.default.actual_limits.maven_max_file_size)
|
|
|
|
expect(json_response['npm_max_file_size']).to eq(Plan.default.actual_limits.npm_max_file_size)
|
|
|
|
expect(json_response['nuget_max_file_size']).to eq(Plan.default.actual_limits.nuget_max_file_size)
|
|
|
|
expect(json_response['pypi_max_file_size']).to eq(Plan.default.actual_limits.pypi_max_file_size)
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(json_response['terraform_module_max_file_size']).to eq(Plan.default.actual_limits.terraform_module_max_file_size)
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(json_response['storage_size_limit']).to eq(Plan.default.actual_limits.storage_size_limit)
|
2023-03-04 22:38:38 +05:30
|
|
|
expect(json_response['pipeline_hierarchy_size']).to eq(Plan.default.actual_limits.pipeline_hierarchy_size)
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'correct plan name in params' do
|
|
|
|
before do
|
|
|
|
@params = { plan_name: 'default' }
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'returns plan limits', :aggregate_failures do
|
|
|
|
get api(path, admin, admin_mode: true), params: @params
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response).to be_an Hash
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(json_response['ci_pipeline_size']).to eq(Plan.default.actual_limits.ci_pipeline_size)
|
|
|
|
expect(json_response['ci_active_jobs']).to eq(Plan.default.actual_limits.ci_active_jobs)
|
|
|
|
expect(json_response['ci_project_subscriptions']).to eq(Plan.default.actual_limits.ci_project_subscriptions)
|
|
|
|
expect(json_response['ci_pipeline_schedules']).to eq(Plan.default.actual_limits.ci_pipeline_schedules)
|
|
|
|
expect(json_response['ci_needs_size_limit']).to eq(Plan.default.actual_limits.ci_needs_size_limit)
|
|
|
|
expect(json_response['ci_registered_group_runners']).to eq(Plan.default.actual_limits.ci_registered_group_runners)
|
|
|
|
expect(json_response['ci_registered_project_runners']).to eq(Plan.default.actual_limits.ci_registered_project_runners)
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(json_response['conan_max_file_size']).to eq(Plan.default.actual_limits.conan_max_file_size)
|
|
|
|
expect(json_response['generic_packages_max_file_size']).to eq(Plan.default.actual_limits.generic_packages_max_file_size)
|
2022-01-26 12:08:38 +05:30
|
|
|
expect(json_response['helm_max_file_size']).to eq(Plan.default.actual_limits.helm_max_file_size)
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(json_response['maven_max_file_size']).to eq(Plan.default.actual_limits.maven_max_file_size)
|
|
|
|
expect(json_response['npm_max_file_size']).to eq(Plan.default.actual_limits.npm_max_file_size)
|
|
|
|
expect(json_response['nuget_max_file_size']).to eq(Plan.default.actual_limits.nuget_max_file_size)
|
|
|
|
expect(json_response['pypi_max_file_size']).to eq(Plan.default.actual_limits.pypi_max_file_size)
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(json_response['terraform_module_max_file_size']).to eq(Plan.default.actual_limits.terraform_module_max_file_size)
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(json_response['storage_size_limit']).to eq(Plan.default.actual_limits.storage_size_limit)
|
2023-03-04 22:38:38 +05:30
|
|
|
expect(json_response['pipeline_hierarchy_size']).to eq(Plan.default.actual_limits.pipeline_hierarchy_size)
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'invalid plan name in params' do
|
|
|
|
before do
|
|
|
|
@params = { plan_name: 'my-plan' }
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'returns validation error', :aggregate_failures do
|
|
|
|
get api(path, admin, admin_mode: true), params: @params
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
expect(json_response['error']).to eq('plan_name does not have a valid value')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT /application/plan_limits' do
|
2023-05-27 22:25:52 +05:30
|
|
|
it_behaves_like 'PUT request permissions for admin mode' do
|
|
|
|
let(:params) { { 'plan_name': 'default' } }
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'as an admin user' do
|
|
|
|
context 'correct params' do
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'updates multiple plan limits', :aggregate_failures do
|
|
|
|
put api(path, admin, admin_mode: true), params: {
|
2021-04-17 20:07:23 +05:30
|
|
|
'plan_name': 'default',
|
2022-07-16 23:28:13 +05:30
|
|
|
'ci_pipeline_size': 101,
|
|
|
|
'ci_active_jobs': 102,
|
|
|
|
'ci_project_subscriptions': 104,
|
|
|
|
'ci_pipeline_schedules': 105,
|
|
|
|
'ci_needs_size_limit': 106,
|
|
|
|
'ci_registered_group_runners': 107,
|
|
|
|
'ci_registered_project_runners': 108,
|
2021-04-17 20:07:23 +05:30
|
|
|
'conan_max_file_size': 10,
|
|
|
|
'generic_packages_max_file_size': 20,
|
2022-01-26 12:08:38 +05:30
|
|
|
'helm_max_file_size': 25,
|
2021-04-17 20:07:23 +05:30
|
|
|
'maven_max_file_size': 30,
|
|
|
|
'npm_max_file_size': 40,
|
|
|
|
'nuget_max_file_size': 50,
|
2021-09-30 23:02:18 +05:30
|
|
|
'pypi_max_file_size': 60,
|
2022-07-16 23:28:13 +05:30
|
|
|
'terraform_module_max_file_size': 70,
|
2023-03-04 22:38:38 +05:30
|
|
|
'storage_size_limit': 80,
|
|
|
|
'pipeline_hierarchy_size': 250
|
2021-04-17 20:07:23 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
expect(json_response).to be_an Hash
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(json_response['ci_pipeline_size']).to eq(101)
|
|
|
|
expect(json_response['ci_active_jobs']).to eq(102)
|
|
|
|
expect(json_response['ci_project_subscriptions']).to eq(104)
|
|
|
|
expect(json_response['ci_pipeline_schedules']).to eq(105)
|
|
|
|
expect(json_response['ci_needs_size_limit']).to eq(106)
|
|
|
|
expect(json_response['ci_registered_group_runners']).to eq(107)
|
|
|
|
expect(json_response['ci_registered_project_runners']).to eq(108)
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(json_response['conan_max_file_size']).to eq(10)
|
|
|
|
expect(json_response['generic_packages_max_file_size']).to eq(20)
|
2022-01-26 12:08:38 +05:30
|
|
|
expect(json_response['helm_max_file_size']).to eq(25)
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(json_response['maven_max_file_size']).to eq(30)
|
|
|
|
expect(json_response['npm_max_file_size']).to eq(40)
|
|
|
|
expect(json_response['nuget_max_file_size']).to eq(50)
|
|
|
|
expect(json_response['pypi_max_file_size']).to eq(60)
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(json_response['terraform_module_max_file_size']).to eq(70)
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(json_response['storage_size_limit']).to eq(80)
|
2023-03-04 22:38:38 +05:30
|
|
|
expect(json_response['pipeline_hierarchy_size']).to eq(250)
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'updates single plan limits', :aggregate_failures do
|
|
|
|
put api(path, admin, admin_mode: true), params: {
|
2021-04-17 20:07:23 +05:30
|
|
|
'plan_name': 'default',
|
|
|
|
'maven_max_file_size': 100
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response).to be_an Hash
|
|
|
|
expect(json_response['maven_max_file_size']).to eq(100)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'empty params' do
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'fails to update plan limits', :aggregate_failures do
|
|
|
|
put api(path, admin, admin_mode: true), params: {}
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
expect(json_response['error']).to match('plan_name is missing')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'params with wrong type' do
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'fails to update plan limits', :aggregate_failures do
|
|
|
|
put api(path, admin, admin_mode: true), params: {
|
2021-04-17 20:07:23 +05:30
|
|
|
'plan_name': 'default',
|
2022-07-16 23:28:13 +05:30
|
|
|
'ci_pipeline_size': 'z',
|
|
|
|
'ci_active_jobs': 'y',
|
|
|
|
'ci_project_subscriptions': 'w',
|
|
|
|
'ci_pipeline_schedules': 'v',
|
|
|
|
'ci_needs_size_limit': 'u',
|
|
|
|
'ci_registered_group_runners': 't',
|
|
|
|
'ci_registered_project_runners': 's',
|
2021-04-17 20:07:23 +05:30
|
|
|
'conan_max_file_size': 'a',
|
|
|
|
'generic_packages_max_file_size': 'b',
|
2022-01-26 12:08:38 +05:30
|
|
|
'helm_max_file_size': 'h',
|
2021-04-17 20:07:23 +05:30
|
|
|
'maven_max_file_size': 'c',
|
|
|
|
'npm_max_file_size': 'd',
|
|
|
|
'nuget_max_file_size': 'e',
|
2021-09-30 23:02:18 +05:30
|
|
|
'pypi_max_file_size': 'f',
|
2022-07-16 23:28:13 +05:30
|
|
|
'terraform_module_max_file_size': 'g',
|
2023-03-04 22:38:38 +05:30
|
|
|
'storage_size_limit': 'j',
|
|
|
|
'pipeline_hierarchy_size': 'r'
|
2021-04-17 20:07:23 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
expect(json_response['error']).to include(
|
2022-07-16 23:28:13 +05:30
|
|
|
'ci_pipeline_size is invalid',
|
|
|
|
'ci_active_jobs is invalid',
|
|
|
|
'ci_project_subscriptions is invalid',
|
|
|
|
'ci_pipeline_schedules is invalid',
|
|
|
|
'ci_needs_size_limit is invalid',
|
|
|
|
'ci_registered_group_runners is invalid',
|
|
|
|
'ci_registered_project_runners is invalid',
|
2021-04-17 20:07:23 +05:30
|
|
|
'conan_max_file_size is invalid',
|
|
|
|
'generic_packages_max_file_size is invalid',
|
2022-01-26 12:08:38 +05:30
|
|
|
'helm_max_file_size is invalid',
|
2021-04-17 20:07:23 +05:30
|
|
|
'maven_max_file_size is invalid',
|
|
|
|
'npm_max_file_size is invalid',
|
|
|
|
'nuget_max_file_size is invalid',
|
2021-09-30 23:02:18 +05:30
|
|
|
'pypi_max_file_size is invalid',
|
2022-07-16 23:28:13 +05:30
|
|
|
'terraform_module_max_file_size is invalid',
|
2023-03-04 22:38:38 +05:30
|
|
|
'storage_size_limit is invalid',
|
|
|
|
'pipeline_hierarchy_size is invalid'
|
2021-04-17 20:07:23 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'missing plan_name in params' do
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'fails to update plan limits', :aggregate_failures do
|
|
|
|
put api(path, admin, admin_mode: true), params: { 'conan_max_file_size': 0 }
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
expect(json_response['error']).to match('plan_name is missing')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'additional undeclared params' do
|
|
|
|
before do
|
|
|
|
Plan.default.actual_limits.update!({ 'golang_max_file_size': 1000 })
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'updates only declared plan limits', :aggregate_failures do
|
|
|
|
put api(path, admin, admin_mode: true), params: {
|
2021-04-17 20:07:23 +05:30
|
|
|
'plan_name': 'default',
|
|
|
|
'pypi_max_file_size': 200,
|
|
|
|
'golang_max_file_size': 999
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response).to be_an Hash
|
|
|
|
expect(json_response['pypi_max_file_size']).to eq(200)
|
|
|
|
expect(json_response['golang_max_file_size']).to be_nil
|
|
|
|
expect(Plan.default.actual_limits.golang_max_file_size).to eq(1000)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|