From bfe2e6a96570102d3485200c476510b5b0d6f9ba Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Thu, 28 Nov 2019 11:44:27 +0100 Subject: [PATCH] Fix otptoken_sync plugin The plugin had two bugs: For one it did not work under Python 3 because urlencode() returns a string but HTTPSHandler expects bytes as data argument. The primary key field name is not available in client plugins. Just pass the token name and let server code convert the name to DN. Fixes: https://pagure.io/freeipa/issue/7804 Signed-off-by: Christian Heimes Reviewed-By: Alexander Bokovoy Reviewed-By: Rob Crittenden --- ipaclient/plugins/otptoken.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ipaclient/plugins/otptoken.py b/ipaclient/plugins/otptoken.py index 3f389c46be2feedf0bb7cb95bd451bf0e6fe6333..e2dcb04a66648276b3f5dd033d048ab6df611b42 100644 --- a/ipaclient/plugins/otptoken.py +++ b/ipaclient/plugins/otptoken.py @@ -27,7 +27,6 @@ from ipalib.messages import add_message, ResultFormattingError from ipalib.plugable import Registry from ipalib.frontend import Local from ipalib.util import create_https_connection -from ipapython.dn import DN from ipapython.version import API_VERSION import locale @@ -162,13 +161,13 @@ class otptoken_sync(Local): sync_uri = urllib.parse.urlunparse(segments) # Prepare the query. - query = {k: v for k, v in kwargs.items() - if k in {x.name for x in self.takes_options}} + options = {x.name for x in self.takes_options} + query = {k: v for k, v in kwargs.items() if k in options} if args and args[0] is not None: - obj = self.api.Object.otptoken - query['token'] = DN((obj.primary_key.name, args[0]), - obj.container_dn, self.api.env.basedn) + # sync_token converts token name to token DN + query['token'] = args[0] query = urllib.parse.urlencode(query) + query = query.encode('utf-8') # Sync the token. # pylint: disable=E1101 -- 2.37.3