From fefd1153d5e7bed9627a3b89de8d6a86f7a0bdfb Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Mon, 4 May 2020 16:13:22 +0200 Subject: [PATCH] Make check_required_principal() case-insensitive service-del deletes services by DN and LDAP DNs are compared case-insensitive. Make check_required_principal() compare the service name case insensitive. Fixes: https://pagure.io/freeipa/issue/8308 Signed-off-by: Christian Heimes Reviewed-By: Alexander Bokovoy --- ipaserver/plugins/service.py | 4 ++-- ipatests/test_xmlrpc/test_service_plugin.py | 23 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ipaserver/plugins/service.py b/ipaserver/plugins/service.py index 6caf0fb17..de80fab5d 100644 --- a/ipaserver/plugins/service.py +++ b/ipaserver/plugins/service.py @@ -287,8 +287,8 @@ def check_required_principal(ldap, principal): try: host_is_master(ldap, principal.hostname) except errors.ValidationError: - service_types = ['HTTP', 'ldap', 'DNS', 'dogtagldap'] - if principal.service_name in service_types: + service_types = {'http', 'ldap', 'dns', 'dogtagldap'} + if principal.service_name.lower() in service_types: raise errors.ValidationError(name='principal', error=_('This principal is required by the IPA master')) def update_krbticketflags(ldap, entry_attrs, attrs_list, options, existing): diff --git a/ipatests/test_xmlrpc/test_service_plugin.py b/ipatests/test_xmlrpc/test_service_plugin.py index 878868009..affac4fc9 100644 --- a/ipatests/test_xmlrpc/test_service_plugin.py +++ b/ipatests/test_xmlrpc/test_service_plugin.py @@ -814,6 +814,18 @@ class test_service(Declarative): expected=errors.ValidationError(name='principal', error='This principal is required by the IPA master'), ), + # DN is case insensitive, see https://pagure.io/freeipa/issue/8308 + dict( + desc=( + 'Delete the current host (master?) %s HTTP service, should ' + 'be caught' + ) % api.env.host, + command=('service_del', ['http/%s' % api.env.host], {}), + expected=errors.ValidationError( + name='principal', + error='This principal is required by the IPA master' + ), + ), dict( desc='Delete the current host (master?) %s ldap service, should be caught' % api.env.host, @@ -828,6 +840,17 @@ class test_service(Declarative): expected=errors.ValidationError(name='principal', error='This principal is required by the IPA master'), ), + dict( + desc=( + 'Disable the current host (master?) %s HTTP service, should ' + 'be caught' + ) % api.env.host, + command=('service_disable', ['http/%s' % api.env.host], {}), + expected=errors.ValidationError( + name='principal', + error='This principal is required by the IPA master' + ), + ), dict( desc='Disable the current host (master?) %s ldap service, should be caught' % api.env.host,