9991ea
From b574423a54dbff7dbca89c6cee49f0304f2393e1 Mon Sep 17 00:00:00 2001
9991ea
From: Rob Crittenden <rcritten@redhat.com>
9991ea
Date: Tue, 14 Jan 2014 14:23:47 -0500
9991ea
Subject: [PATCH 19/25] Change the way we determine if the host has a password
9991ea
 set.
9991ea
9991ea
When creating a host with a password we don't set a Kerberos
9991ea
principal or add the Kerberos objectclasses. Those get added when the
9991ea
host is enrolled. If one passed in --password= (so no password) then
9991ea
we incorrectly thought the user was in fact setting a password, so the
9991ea
principal and objectclasses weren't updated.
9991ea
9991ea
https://fedorahosted.org/freeipa/ticket/4102
9991ea
---
9991ea
 ipalib/plugins/host.py                   |  2 +-
9991ea
 ipatests/test_xmlrpc/test_host_plugin.py | 27 +++++++++++++++++++++++++++
9991ea
 2 files changed, 28 insertions(+), 1 deletion(-)
9991ea
9991ea
diff --git a/ipalib/plugins/host.py b/ipalib/plugins/host.py
9991ea
index 7aa94aa95ba9be17c308546d5d2fe247f27a07b3..9d45e270ff8221e4b9380684cb56112db4af4f52 100644
9991ea
--- a/ipalib/plugins/host.py
9991ea
+++ b/ipalib/plugins/host.py
9991ea
@@ -425,7 +425,7 @@ def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
9991ea
             entry_attrs['l'] = entry_attrs['locality']
9991ea
         entry_attrs['cn'] = keys[-1]
9991ea
         entry_attrs['serverhostname'] = keys[-1].split('.', 1)[0]
9991ea
-        if 'userpassword' not in entry_attrs and not options.get('random', False):
9991ea
+        if not entry_attrs.get('userpassword', False) and not options.get('random', False):
9991ea
             entry_attrs['krbprincipalname'] = 'host/%s@%s' % (
9991ea
                 keys[-1], self.api.env.realm
9991ea
             )
9991ea
diff --git a/ipatests/test_xmlrpc/test_host_plugin.py b/ipatests/test_xmlrpc/test_host_plugin.py
9991ea
index a23a34112f5c041a8325d5090580b535d93c7a72..7b64398fadd236b9b06723ef561cb19d61bca6d5 100644
9991ea
--- a/ipatests/test_xmlrpc/test_host_plugin.py
9991ea
+++ b/ipatests/test_xmlrpc/test_host_plugin.py
9991ea
@@ -863,6 +863,33 @@ class test_host(Declarative):
9991ea
             ),
9991ea
         ),
9991ea
 
9991ea
+
9991ea
+        dict(
9991ea
+            desc='Create a host with a NULL password',
9991ea
+            command=('host_add', [fqdn3],
9991ea
+                dict(
9991ea
+                    description=u'Test host 3',
9991ea
+                    force=True,
9991ea
+                    userpassword=None,
9991ea
+                ),
9991ea
+            ),
9991ea
+            expected=dict(
9991ea
+                value=fqdn3,
9991ea
+                summary=u'Added host "%s"' % fqdn3,
9991ea
+                result=dict(
9991ea
+                    dn=dn3,
9991ea
+                    fqdn=[fqdn3],
9991ea
+                    description=[u'Test host 3'],
9991ea
+                    krbprincipalname=[u'host/%s@%s' % (fqdn3, api.env.realm)],
9991ea
+                    objectclass=objectclasses.host,
9991ea
+                    ipauniqueid=[fuzzy_uuid],
9991ea
+                    managedby_host=[u'%s' % fqdn3],
9991ea
+                    has_keytab=False,
9991ea
+                    has_password=False,
9991ea
+                ),
9991ea
+            ),
9991ea
+        ),
9991ea
+
9991ea
     ]
9991ea
 
9991ea
 class test_host_false_pwd_change(XMLRPC_test):
9991ea
-- 
9991ea
1.8.4.2
9991ea