a99c7c
From edbd8f692a28fc999b92e9032614d366511db323 Mon Sep 17 00:00:00 2001
a99c7c
From: Anuja More <amore@redhat.com>
a99c7c
Date: Mon, 6 Dec 2021 20:50:01 +0530
a99c7c
Subject: [PATCH] ipatests: webui: Tests for subordinate ids.
a99c7c
a99c7c
Added web-ui tests to verify where operations
a99c7c
using subordinate ids are working as expected.
a99c7c
a99c7c
Related : https://pagure.io/freeipa/issue/8361
a99c7c
a99c7c
Signed-off-by: Anuja More <amore@redhat.com>
a99c7c
Reviewed-By: Michal Polovka <mpolovka@redhat.com>
a99c7c
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
a99c7c
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
a99c7c
---
a99c7c
 ipatests/test_webui/test_subid.py | 141 ++++++++++++++++++++++++++++++
a99c7c
 ipatests/test_webui/ui_driver.py  |  28 ++++++
a99c7c
 2 files changed, 169 insertions(+)
a99c7c
 create mode 100644 ipatests/test_webui/test_subid.py
a99c7c
a99c7c
diff --git a/ipatests/test_webui/test_subid.py b/ipatests/test_webui/test_subid.py
a99c7c
new file mode 100644
a99c7c
index 0000000000000000000000000000000000000000..26decdba03955f28ab21a41ccffae2a9af7b09fe
a99c7c
--- /dev/null
a99c7c
+++ b/ipatests/test_webui/test_subid.py
a99c7c
@@ -0,0 +1,141 @@
a99c7c
+
a99c7c
+"""
a99c7c
+Tests for subordinateid.
a99c7c
+"""
a99c7c
+
a99c7c
+from ipatests.test_webui.ui_driver import UI_driver
a99c7c
+import ipatests.test_webui.data_config as config_data
a99c7c
+import ipatests.test_webui.data_user as user_data
a99c7c
+from ipatests.test_webui.ui_driver import screenshot
a99c7c
+import re
a99c7c
+
a99c7c
+
a99c7c
+class test_subid(UI_driver):
a99c7c
+
a99c7c
+    def add_user(self, pkey, name, surname):
a99c7c
+        self.add_record('user', {
a99c7c
+            'pkey': pkey,
a99c7c
+            'add': [
a99c7c
+                ('textbox', 'uid', pkey),
a99c7c
+                ('textbox', 'givenname', name),
a99c7c
+                ('textbox', 'sn', surname),
a99c7c
+            ]
a99c7c
+        })
a99c7c
+
a99c7c
+    def set_default_subid(self):
a99c7c
+        self.navigate_to_entity(config_data.ENTITY)
a99c7c
+        self.check_option('ipauserdefaultsubordinateid', 'checked')
a99c7c
+        self.facet_button_click('save')
a99c7c
+
a99c7c
+    def get_user_count(self, user_pkey):
a99c7c
+        self.navigate_to_entity('subid', facet='search')
a99c7c
+        self.apply_search_filter(user_pkey)
a99c7c
+        self.wait_for_request()
a99c7c
+        return self.get_rows()
a99c7c
+
a99c7c
+    @screenshot
a99c7c
+    def test_set_defaultsubid(self):
a99c7c
+        """
a99c7c
+        Test to verify that enable/disable is working for
a99c7c
+        adding subids to new users.
a99c7c
+        """
a99c7c
+        self.init_app()
a99c7c
+        self.add_record(user_data.ENTITY, user_data.DATA2)
a99c7c
+        self.navigate_to_entity(config_data.ENTITY)
a99c7c
+        # test subid can be enabled/disabled.
a99c7c
+        self.set_default_subid()
a99c7c
+        assert self.get_field_checked('ipauserdefaultsubordinateid')
a99c7c
+        self.set_default_subid()
a99c7c
+        assert not self.get_field_checked('ipauserdefaultsubordinateid')
a99c7c
+
a99c7c
+    @screenshot
a99c7c
+    def test_user_defaultsubid(self):
a99c7c
+        """
a99c7c
+        Test to verify that subid is generated for new user.
a99c7c
+        """
a99c7c
+        self.init_app()
a99c7c
+        user_pkey = "some-user"
a99c7c
+
a99c7c
+        self.set_default_subid()
a99c7c
+        assert self.get_field_checked('ipauserdefaultsubordinateid')
a99c7c
+
a99c7c
+        before_count = self.get_user_count(user_pkey)
a99c7c
+        assert len(before_count) == 0
a99c7c
+
a99c7c
+        self.add_user(user_pkey, 'Some', 'User')
a99c7c
+        after_count = self.get_user_count(user_pkey)
a99c7c
+        assert len(after_count) == 1
a99c7c
+
a99c7c
+    @screenshot
a99c7c
+    def test_user_subid_mod_desc(self):
a99c7c
+        """
a99c7c
+        Test to verify that auto-assigned subid description is modified.
a99c7c
+        """
a99c7c
+        self.init_app()
a99c7c
+        self.navigate_to_record("some-user")
a99c7c
+        self.switch_to_facet('memberof_subid')
a99c7c
+        rows = self.get_rows()
a99c7c
+        self.navigate_to_row_record(rows[-1])
a99c7c
+        self.fill_textbox("description", "some-user-subid-desc")
a99c7c
+        self.facet_button_click('save')
a99c7c
+
a99c7c
+    @screenshot
a99c7c
+    def test_admin_subid(self):
a99c7c
+        """
a99c7c
+        Test to verify that subid range is created with owner admin.
a99c7c
+        """
a99c7c
+        self.init_app()
a99c7c
+        self.navigate_to_entity('subid', facet='search')
a99c7c
+        self.facet_button_click('add')
a99c7c
+        self.select_combobox('ipaowner', 'admin')
a99c7c
+        self.dialog_button_click('add')
a99c7c
+        self.wait(0.3)
a99c7c
+        self.assert_no_error_dialog()
a99c7c
+
a99c7c
+    @screenshot
a99c7c
+    def test_admin_subid_negative(self):
a99c7c
+        """
a99c7c
+        Test to verify that readding the subid fails with error.
a99c7c
+        """
a99c7c
+        self.init_app()
a99c7c
+        self.navigate_to_entity('subid', facet='search')
a99c7c
+        self.facet_button_click('add')
a99c7c
+        self.select_combobox('ipaowner', 'admin')
a99c7c
+        self.dialog_button_click('add')
a99c7c
+        self.wait(0.3)
a99c7c
+        err_dialog = self.get_last_error_dialog(dialog_name='error_dialog')
a99c7c
+        text = self.get_text('.modal-body div p', err_dialog)
a99c7c
+        text = text.strip()
a99c7c
+        pattern = r'Subordinate id with with name .* already exists.'
a99c7c
+        assert re.search(pattern, text) is not None
a99c7c
+        self.close_all_dialogs()
a99c7c
+
a99c7c
+    @screenshot
a99c7c
+    def test_user_subid_add(self):
a99c7c
+        """
a99c7c
+        Test to verify that subid range is created for given user.
a99c7c
+        """
a99c7c
+        self.init_app()
a99c7c
+        self.navigate_to_entity('subid', facet='search')
a99c7c
+        before_count = self.get_rows()
a99c7c
+        self.facet_button_click('add')
a99c7c
+        self.select_combobox('ipaowner', user_data.PKEY2)
a99c7c
+        self.dialog_button_click('add')
a99c7c
+        self.wait(0.3)
a99c7c
+        self.assert_no_error_dialog()
a99c7c
+        after_count = self.get_rows()
a99c7c
+        assert len(before_count) < len(after_count)
a99c7c
+
a99c7c
+    @screenshot
a99c7c
+    def test_subid_del(self):
a99c7c
+        """
a99c7c
+        Test to remove subordinate id for given user.
a99c7c
+        """
a99c7c
+        self.init_app()
a99c7c
+        self.navigate_to_entity('subid', facet='search')
a99c7c
+        user_uid = self.get_record_pkey("some-user", "ipaowner",
a99c7c
+                                        table_name="ipauniqueid")
a99c7c
+        before_count = self.get_rows()
a99c7c
+        self.delete_record(user_uid, table_name="ipauniqueid")
a99c7c
+        after_count = self.get_rows()
a99c7c
+        assert len(before_count) > len(after_count)
a99c7c
diff --git a/ipatests/test_webui/ui_driver.py b/ipatests/test_webui/ui_driver.py
a99c7c
index 46fd512ae67bee65be55ae0d4dedec53cc29de97..77fd74e49593183a37fe735bedf2e0d6b9257ac7 100644
a99c7c
--- a/ipatests/test_webui/ui_driver.py
a99c7c
+++ b/ipatests/test_webui/ui_driver.py
a99c7c
@@ -1151,6 +1151,34 @@ class UI_driver:
a99c7c
                 return row
a99c7c
         return None
a99c7c
 
a99c7c
+    def get_row_by_column_value(self, key, column_name, parent=None,
a99c7c
+                                table_name=None):
a99c7c
+        """
a99c7c
+        Get the first matched row element of a search table with given key
a99c7c
+        matched against selected column. None if not found
a99c7c
+        """
a99c7c
+        rows = self.get_rows(parent, table_name)
a99c7c
+        s = "td div[name='%s']" % column_name
a99c7c
+        for row in rows:
a99c7c
+            has = self.find(s, By.CSS_SELECTOR, row)
a99c7c
+            if has.text == key:
a99c7c
+                return row
a99c7c
+        return None
a99c7c
+
a99c7c
+    def get_record_pkey(self, key, column, parent=None, table_name=None):
a99c7c
+        """
a99c7c
+        Get record pkey if value of column is known
a99c7c
+        """
a99c7c
+        row = self.get_row_by_column_value(key,
a99c7c
+                                           column_name=column,
a99c7c
+                                           parent=parent,
a99c7c
+                                           table_name=table_name)
a99c7c
+        val = None
a99c7c
+        if row:
a99c7c
+            el = self.find("td input", By.CSS_SELECTOR, row)
a99c7c
+            val = el.get_attribute("value")
a99c7c
+        return val
a99c7c
+
a99c7c
     def navigate_to_row_record(self, row, pkey_column=None):
a99c7c
         """
a99c7c
         Navigate to record by clicking on a link.
a99c7c
-- 
a99c7c
2.34.1
a99c7c