Add test, reduce complexity

This commit is contained in:
Robert Schilling 2019-08-22 19:05:43 +02:00
parent 30f302d2be
commit cc18c332e0
2 changed files with 11 additions and 2 deletions

View File

@ -7,8 +7,7 @@ module ApplicationSettings
attr_reader :params, :application_setting
def execute
disable_ext_auth = params[:external_authorization_service_enabled].present? && !Gitlab::Utils.to_boolean(params[:external_authorization_service_enabled])
validate_classification_label(application_setting, :external_authorization_service_default_label) unless disable_ext_auth
validate_classification_label(application_setting, :external_authorization_service_default_label) unless bypass_external_auth?
if application_setting.errors.any?
return false
@ -60,5 +59,9 @@ module ApplicationSettings
Group.find_by_full_path(group_full_path)&.id if group_full_path.present?
end
def bypass_external_auth?
params.key?(:external_authorization_service_enabled) && !Gitlab::Utils.to_boolean(params[:external_authorization_service_enabled])
end
end
end

View File

@ -201,6 +201,12 @@ describe ApplicationSettings::UpdateService do
enable_external_authorization_service_check
end
it 'does not validate labels if external authorization gets disabled' do
expect_any_instance_of(described_class).not_to receive(:validate_classification_label)
described_class.new(application_settings, admin, { external_authorization_service_enabled: false }).execute
end
it 'does not save the settings with an error if the service denies access' do
expect(::Gitlab::ExternalAuthorization)
.to receive(:access_allowed?).with(admin, 'new-label') { false }