From 7e4bcabb38991c155b4e6194777e4fcb642b0600 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 d176adddff8d2590d64ba4059018606ff1eb8d48..a096603552ffb0d0621a7d0f79d907d862e3888f 100644 --- a/ipaserver/plugins/service.py +++ b/ipaserver/plugins/service.py @@ -282,8 +282,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 3d50dfec4532f2e0590e5a05ca9db7d731cbd31e..7c8132cf8ccad3c9feebb58705320285a603fb77 100644 --- a/ipatests/test_xmlrpc/test_service_plugin.py +++ b/ipatests/test_xmlrpc/test_service_plugin.py @@ -791,6 +791,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, @@ -805,6 +817,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, -- 2.25.4