URL: https://github.com/freeipa/freeipa/pull/736 Author: felipevolpone Title: #736: Fixing the cert-request command comparing whole email address case-sensitively. Action: opened
PR body: """ Now, the cert-request command compares the domain part of the email case-insensitively. Fixes: [https://pagure.io/freeipa/issue/5919](https://pagure.io/freeipa/issue/5919) """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/736/head:pr736 git checkout pr736
From 6210297824b61c20e3ca70dff3c48ffd47aee29e Mon Sep 17 00:00:00 2001 From: felipe barreto <fbarreto@localhost.localdomain> Date: Wed, 26 Apr 2017 11:08:35 -0300 Subject: [PATCH] Fixing the cert-request comparing whole email address case-sensitively. Now, the cert-request command compares the domain part of the email case-insensitively. https://pagure.io/freeipa/issue/5919 --- ipaserver/plugins/cert.py | 20 +++++++++++++++++++- ipatests/test_xmlrpc/test_cert_plugin.py | 25 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/ipaserver/plugins/cert.py b/ipaserver/plugins/cert.py index 9f90107..a0b2b83 100644 --- a/ipaserver/plugins/cert.py +++ b/ipaserver/plugins/cert.py @@ -705,7 +705,8 @@ def execute(self, csr, all=False, raw=False, chain=False, **kw): # fail if any email addr from DN does not appear in ldap entry email_addrs = csr_obj.subject.get_attributes_for_oid( cryptography.x509.oid.NameOID.EMAIL_ADDRESS) - if len(set(email_addrs) - set(principal_obj.get('mail', []))) > 0: + if not _emails_are_valid(email_addrs, + principal_obj.get('mail', [])): raise errors.ValidationError( name='csr', error=_( @@ -860,6 +861,23 @@ def execute(self, csr, all=False, raw=False, chain=False, **kw): ) +def _emails_are_valid(cert_emails, principal_emails): + """ + Checks if any email addr from DN does not appear in ldap entry, + comparing the domain part case-insensitively. + """ + + def lower_domain(email): + return email.split('@')[0] + '@' + email.split('@')[1].lower() + + principal_emails_lower = [lower_domain(email) for email in principal_emails] + + email_addrs = [attr.value for attr in cert_emails] + cert_emails_lower = [lower_domain(email) for email in email_addrs] + + return not any(set(cert_emails_lower) - set(principal_emails_lower)) + + def principal_to_principal_type(principal): if principal.is_user: return USER diff --git a/ipatests/test_xmlrpc/test_cert_plugin.py b/ipatests/test_xmlrpc/test_cert_plugin.py index 0b8277b..cd8ee7b 100644 --- a/ipatests/test_xmlrpc/test_cert_plugin.py +++ b/ipatests/test_xmlrpc/test_cert_plugin.py @@ -253,6 +253,31 @@ def test_00010_cleanup(self): res = api.Command['service_find'](self.service_princ) assert res['count'] == 0 + def test_00011_email_are_valid(self): + from ipaserver.plugins.cert import _emails_are_valid + from collections import namedtuple + NameAttribute = namedtuple('NameAttribute', 'value') + + cert = [NameAttribute(u'a...@email.com')] + result = _emails_are_valid(cert, [u'a...@email.com']) + assert True == result, result + + cert = [NameAttribute(u'a...@email.com')] + result = _emails_are_valid(cert, [u'a...@email.com', u'anot...@email.com']) + assert True == result, result + + cert = [NameAttribute(u'a...@email.com'), NameAttribute('anot...@email.com')] + result = _emails_are_valid(cert, [u'a...@email.com']) + assert False == result, result + + result = _emails_are_valid([], [u'a...@email.com']) + assert True == result, result + + cert = [NameAttribute(u'a...@email.com')] + result = _emails_are_valid(cert, []) + assert False == result, result + + @pytest.mark.tier1 class test_cert_find(XMLRPC_test):
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code