Blob Blame History Raw
From 4bff9d92a51bff2fabb6168f8ae69c8a8d17ba2a Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Sun, 17 Jun 2018 22:06:22 +0200
Subject: [PATCH] TESTS: Allow adding sshPublicKey for users
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Adds the objectclass and allows storing a list of sshPublicKey
attributes for users. Since there is no harm in adding the extra
objectclass, we can do it unconditionally.

Related to:
https://pagure.io/SSSD/sssd/issue/3747

Reviewed-by: Fabiano FidĂȘncio <fidencio@redhat.com>
(cherry picked from commit 56cda832e9f61c52e9cfde1f0864507de718ffbb)
---
 src/tests/intg/ldap_ent.py | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/tests/intg/ldap_ent.py b/src/tests/intg/ldap_ent.py
index 6b6d8f903cbcc277d892c3212ca382f4aaadc671..a4c987969d3dcefba2af69e095b220180e0fa54c 100644
--- a/src/tests/intg/ldap_ent.py
+++ b/src/tests/intg/ldap_ent.py
@@ -24,7 +24,8 @@ def user(base_dn, uid, uidNumber, gidNumber,
          homeDirectory=None,
          loginShell=None,
          cn=None,
-         sn=None):
+         sn=None,
+         sshPubKey=()):
     """
     Generate an RFC2307(bis) user add-modlist for passing to ldap.add*
     """
@@ -33,7 +34,8 @@ def user(base_dn, uid, uidNumber, gidNumber,
     user = (
         "uid=" + uid + ",ou=Users," + base_dn,
         [
-            ('objectClass', [b'top', b'inetOrgPerson', b'posixAccount']),
+            ('objectClass', [b'top', b'inetOrgPerson',
+                             b'posixAccount', b'ldapPublicKey']),
             ('cn', [uidNumber if cn is None else cn.encode('utf-8')]),
             ('sn', [b'User' if sn is None else sn.encode('utf-8')]),
             ('uidNumber', [uidNumber]),
@@ -51,6 +53,9 @@ def user(base_dn, uid, uidNumber, gidNumber,
     )
     if gecos is not None:
         user[1].append(('gecos', [gecos.encode('utf-8')]))
+    if len(sshPubKey) > 0:
+        pubkeys = [key.encode('utf-8') for key in sshPubKey]
+        user[1].append(('sshPublicKey', pubkeys))
     return user
 
 
@@ -118,7 +123,8 @@ class List(list):
                  homeDirectory=None,
                  loginShell=None,
                  cn=None,
-                 sn=None):
+                 sn=None,
+                 sshPubKey=()):
         """Add an RFC2307(bis) user add-modlist."""
         self.append(user(base_dn or self.base_dn,
                          uid, uidNumber, gidNumber,
@@ -127,7 +133,8 @@ class List(list):
                          homeDirectory=homeDirectory,
                          loginShell=loginShell,
                          cn=cn,
-                         sn=sn))
+                         sn=sn,
+                         sshPubKey=sshPubKey))
 
     def add_group(self, cn, gidNumber, member_uids=[],
                   base_dn=None):
-- 
2.17.1