URL: https://github.com/freeipa/freeipa/pull/904
Author: Tiboris
 Title: #904: Add test: test_xmlrpc/test_whoami_plugin.py
Action: opened

PR body:
"""
New file contains tests for `whoami` command with 
user, host, and service principal's tgt.

Test will be failing until #900 PR is merged.

Resolves: https://pagure.io/freeipa/issue/6745
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/904/head:pr904
git checkout pr904
From f4c734955f4c23dfd4cccd44f600582a41751f15 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tibor=20Dudl=C3=A1k?= <tdud...@redhat.com>
Date: Thu, 8 Jun 2017 15:36:44 +0200
Subject: [PATCH] Add test: test_xmlrpc/test_whoami_plugin.py

Resolves: https://pagure.io/freeipa/issue/6745
---
 ipatests/test_xmlrpc/test_whoami_plugin.py | 126 +++++++++++++++++++++++++++++
 1 file changed, 126 insertions(+)
 create mode 100644 ipatests/test_xmlrpc/test_whoami_plugin.py

diff --git a/ipatests/test_xmlrpc/test_whoami_plugin.py b/ipatests/test_xmlrpc/test_whoami_plugin.py
new file mode 100644
index 0000000000..d137be95b4
--- /dev/null
+++ b/ipatests/test_xmlrpc/test_whoami_plugin.py
@@ -0,0 +1,126 @@
+# Authors:
+#   Tibor Dudlak <tdud...@redhat.com>
+#
+# Copyright (C) 2017  Red Hat
+# see file 'COPYING' for use and warranty information
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+"""
+Test the `ipaserver/plugins/whoami.py` module.
+"""
+
+import pytest
+
+from ipalib import api
+from ipatests.util import (unlock_principal_password,
+                           get_entity_keytab,
+                           change_principal,
+                           assert_deepequal,
+                           host_keytab)
+from ipatests.test_xmlrpc.xmlrpc_test import XMLRPC_test
+from ipatests.test_xmlrpc.tracker.user_plugin import UserTracker
+from ipatests.test_xmlrpc.tracker.host_plugin import HostTracker
+from ipatests.test_xmlrpc.tracker.service_plugin import ServiceTracker
+
+
+@pytest.fixture(scope='function')
+def krb_user(request):
+    tracker = UserTracker(u'krb_user', u'krb', u'test_user')
+
+    return tracker.make_fixture(request)
+
+
+@pytest.fixture
+def krb_host(request):
+    tracker = HostTracker(u'krb-host')
+
+    return tracker.make_fixture(request)
+
+
+@pytest.fixture(scope='function')
+def krb_service(request, krb_host):
+    krb_host.ensure_exists()
+
+    tracker = ServiceTracker(name=u'SERVICE', host_fqdn=krb_host.name)
+
+    return tracker.make_fixture(request)
+
+
+@pytest.mark.tier1
+class test_whoami(XMLRPC_test):
+    """
+    Test the 'whoami' plugin.
+    """
+    domain = api.env.domain
+    realm = api.env.realm
+    oldpw, newpw = u"Secret1234", u"Secret123"
+
+    def test_whoami_users(self, krb_user):
+        """
+        Testing whoami with user's tgt
+        """
+        krb_user.ensure_exists()
+
+        pwdmod = krb_user.make_update_command({'userpassword': self.oldpw})
+        pwdmod()
+
+        unlock_principal_password(krb_user.name, self.oldpw, self.newpw)
+
+        with change_principal(krb_user.name, self.newpw):
+            try:
+                result = api.Command.whoami()
+                expected = {u'object': u'user',
+                            u'command': u'user_show/1',
+                            u'arguments': (u'krb_user',)}
+                assert_deepequal(expected, result)
+            except Exception as exc:
+                raise Exception(exc)
+
+    def test_whoami_hosts(self, krb_host):
+        """
+        Testing host
+        """
+        krb_host.ensure_exists()
+        with host_keytab(krb_host.name) as keytab_filename:
+            with change_principal(krb_host.attrs['krbcanonicalname'][0],
+                                  keytab=keytab_filename):
+                try:
+                    result = api.Command.whoami()
+                    expected = {u'object': u'host',
+                                u'command': u'host_show/1',
+                                u'arguments': (u'krb-host.{domain}'.format(
+                                    domain=self.domain),)}
+                    assert_deepequal(expected, result)
+                except Exception as exc:
+                    raise Exception(exc)
+
+    def test_whoami_kerberos_services(self, krb_host, krb_service):
+        """
+        Testing kerberos service
+        """
+        krb_service.ensure_exists()
+        with get_entity_keytab(krb_service.name, '-r') as keytab_filename:
+            with change_principal(krb_service.attrs['krbcanonicalname'][0],
+                                  keytab=keytab_filename):
+                try:
+                    result = api.Command.whoami()
+                    expected = {u'object': u'service',
+                                u'command': u'service_show/1',
+                                u'arguments':
+                                (u'SERVICE/krb-host.{domain}@{realm}'.format(
+                                    domain=self.domain,
+                                    realm=self.realm),)}
+                    assert_deepequal(expected, result)
+                except Exception as exc:
+                    raise Exception(exc)
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to