debian-mirror-gitlab/spec/controllers/admin/application_settings_controller_spec.rb

174 lines
5.5 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
describe Admin::ApplicationSettingsController do
include StubENV
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
let(:admin) { create(:admin) }
let(:user) { create(:user)}
before do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
end
describe 'GET #usage_data with no access' do
before do
2020-03-09 13:42:32 +05:30
allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(false)
2017-08-17 22:00:37 +05:30
sign_in(user)
end
it 'returns 404' do
get :usage_data, format: :html
expect(response.status).to eq(404)
end
end
describe 'GET #usage_data' do
before do
2020-03-09 13:42:32 +05:30
allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(false)
2017-08-17 22:00:37 +05:30
sign_in(admin)
end
it 'returns HTML data' do
get :usage_data, format: :html
expect(response.body).to start_with('<span')
expect(response.status).to eq(200)
end
it 'returns JSON data' do
get :usage_data, format: :json
2019-09-30 21:07:59 +05:30
body = json_response
2017-08-17 22:00:37 +05:30
expect(body["version"]).to eq(Gitlab::VERSION)
expect(body).to include('counts')
expect(response.status).to eq(200)
end
end
describe 'PUT #update' do
before do
sign_in(admin)
end
2018-03-17 18:26:18 +05:30
it 'updates the password_authentication_enabled_for_git setting' do
2019-02-15 15:39:39 +05:30
put :update, params: { application_setting: { password_authentication_enabled_for_git: "0" } }
2018-03-17 18:26:18 +05:30
2020-03-09 13:42:32 +05:30
expect(response).to redirect_to(general_admin_application_settings_path)
2018-03-17 18:26:18 +05:30
expect(ApplicationSetting.current.password_authentication_enabled_for_git).to eq(false)
end
2017-08-17 22:00:37 +05:30
it 'updates the default_project_visibility for string value' do
2019-02-15 15:39:39 +05:30
put :update, params: { application_setting: { default_project_visibility: "20" } }
2017-08-17 22:00:37 +05:30
2020-03-09 13:42:32 +05:30
expect(response).to redirect_to(general_admin_application_settings_path)
2017-08-17 22:00:37 +05:30
expect(ApplicationSetting.current.default_project_visibility).to eq(Gitlab::VisibilityLevel::PUBLIC)
end
it 'update the restricted levels for string values' do
2019-02-15 15:39:39 +05:30
put :update, params: { application_setting: { restricted_visibility_levels: %w[10 20] } }
2017-08-17 22:00:37 +05:30
2020-03-09 13:42:32 +05:30
expect(response).to redirect_to(general_admin_application_settings_path)
2017-08-17 22:00:37 +05:30
expect(ApplicationSetting.current.restricted_visibility_levels).to eq([10, 20])
end
2018-05-09 12:01:36 +05:30
it 'updates the restricted_visibility_levels when empty array is passed' do
2019-02-15 15:39:39 +05:30
put :update, params: { application_setting: { restricted_visibility_levels: [""] } }
2017-08-17 22:00:37 +05:30
2020-03-09 13:42:32 +05:30
expect(response).to redirect_to(general_admin_application_settings_path)
2017-08-17 22:00:37 +05:30
expect(ApplicationSetting.current.restricted_visibility_levels).to be_empty
end
2018-11-20 20:47:30 +05:30
it 'updates the receive_max_input_size setting' do
2019-02-15 15:39:39 +05:30
put :update, params: { application_setting: { receive_max_input_size: "1024" } }
2018-11-20 20:47:30 +05:30
2020-03-09 13:42:32 +05:30
expect(response).to redirect_to(general_admin_application_settings_path)
2018-11-20 20:47:30 +05:30
expect(ApplicationSetting.current.receive_max_input_size).to eq(1024)
end
2019-07-07 11:18:12 +05:30
it 'updates the default_project_creation for string value' do
put :update, params: { application_setting: { default_project_creation: ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS } }
2020-03-09 13:42:32 +05:30
expect(response).to redirect_to(general_admin_application_settings_path)
2019-07-07 11:18:12 +05:30
expect(ApplicationSetting.current.default_project_creation).to eq(::Gitlab::Access::MAINTAINER_PROJECT_ACCESS)
end
2020-01-01 13:55:28 +05:30
it 'updates minimum_password_length setting' do
put :update, params: { application_setting: { minimum_password_length: 10 } }
2020-03-09 13:42:32 +05:30
expect(response).to redirect_to(general_admin_application_settings_path)
2020-01-01 13:55:28 +05:30
expect(ApplicationSetting.current.minimum_password_length).to eq(10)
end
2019-07-07 11:18:12 +05:30
context 'external policy classification settings' do
let(:settings) do
{
external_authorization_service_enabled: true,
external_authorization_service_url: 'https://custom.service/',
external_authorization_service_default_label: 'default',
external_authorization_service_timeout: 3,
external_auth_client_cert: File.read('spec/fixtures/passphrase_x509_certificate.crt'),
external_auth_client_key: File.read('spec/fixtures/passphrase_x509_certificate_pk.key'),
external_auth_client_key_pass: "5iveL!fe"
}
end
it 'updates settings when the feature is available' do
put :update, params: { application_setting: settings }
settings.each do |attribute, value|
expect(ApplicationSetting.current.public_send(attribute)).to eq(value)
end
end
end
2019-09-30 21:07:59 +05:30
describe 'verify panel actions' do
2019-12-21 20:55:43 +05:30
Admin::ApplicationSettingsController::VALID_SETTING_PANELS.each do |valid_action|
2019-09-30 21:07:59 +05:30
it_behaves_like 'renders correct panels' do
let(:action) { valid_action }
end
end
end
2017-08-17 22:00:37 +05:30
end
2018-12-05 23:21:45 +05:30
describe 'PUT #reset_registration_token' do
before do
sign_in(admin)
end
subject { put :reset_registration_token }
it 'resets runner registration token' do
expect { subject }.to change { ApplicationSetting.current.runners_registration_token }
end
it 'redirects the user to admin runners page' do
subject
expect(response).to redirect_to(admin_runners_path)
end
end
2019-12-21 20:55:43 +05:30
describe 'GET #lets_encrypt_terms_of_service' do
include LetsEncryptHelpers
before do
sign_in(admin)
stub_lets_encrypt_client
end
subject { get :lets_encrypt_terms_of_service }
it 'redirects the user to the terms of service page' do
subject
expect(response).to redirect_to("https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf")
end
end
2017-08-17 22:00:37 +05:30
end