URL: https://github.com/freeipa/freeipa/pull/1994
Author: mrizwan93
 Title: #1994: [Backport][ipa-4-6]Extended UI test for selfservice permission
Action: opened

PR body:
"""
Follwoing scenario added:
 - test_add_all_attr
 - test_add_and_add_another
 - test_add_and_edit
 - test_add_and_cancel
 - test_add_permission_undo
 - test_add_permission_reset
 - test_permission_negative
 - test_del_multiple_permission
 - test_permission_using_enter_key
 - test_reset_sshkey_permsission

Signed-off-by: Mohammad Rizwan Yusuf <myu...@redhat.com>
Reviewed-By: Petr Vobornik <pvobo...@redhat.com>
(cherry picked from commit 3927b0e7b1a6de1734d2e3b4e283dcc7d3f0a406)
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/1994/head:pr1994
git checkout pr1994
From 5debbd3bc06fdefa46f63f89a669f60fdef23224 Mon Sep 17 00:00:00 2001
From: Mohammad Rizwan Yusuf <myu...@redhat.com>
Date: Thu, 17 May 2018 14:21:15 +0530
Subject: [PATCH] Extended UI test for selfservice permission.

Follwoing scenario added:
 - test_add_all_attr
 - test_add_and_add_another
 - test_add_and_edit
 - test_add_and_cancel
 - test_add_permission_undo
 - test_add_permission_reset
 - test_permission_negative
 - test_del_multiple_permission
 - test_permission_using_enter_key
 - test_reset_sshkey_permsission

Signed-off-by: Mohammad Rizwan Yusuf <myu...@redhat.com>
Reviewed-By: Petr Vobornik <pvobo...@redhat.com>
(cherry picked from commit 3927b0e7b1a6de1734d2e3b4e283dcc7d3f0a406)
---
 ipatests/test_webui/data_selfservice.py | 134 ++++++++++++++++
 ipatests/test_webui/test_selfservice.py | 266 ++++++++++++++++++++++++++++++--
 2 files changed, 386 insertions(+), 14 deletions(-)
 create mode 100644 ipatests/test_webui/data_selfservice.py

diff --git a/ipatests/test_webui/data_selfservice.py b/ipatests/test_webui/data_selfservice.py
new file mode 100644
index 0000000000..73bbf1b9e8
--- /dev/null
+++ b/ipatests/test_webui/data_selfservice.py
@@ -0,0 +1,134 @@
+#
+# Copyright (C) 2018  FreeIPA Contributors see COPYING for license
+#
+
+ENTITY = 'selfservice'
+PKEY = 'itest-selfservice-rule'
+DATA = {
+    'pkey': PKEY,
+    'add': [
+        ('textbox', 'aciname', PKEY),
+        ('checkbox', 'attrs', 'audio'),
+        ('checkbox', 'attrs', 'businesscategory'),
+    ],
+    'mod': [
+        ('checkbox', 'attrs', 'businesscategory'),
+    ],
+}
+
+PKEY1 = 'itest-selfservice-rule1'
+DATA1 = {
+    'pkey': PKEY1,
+    'add': [
+        ('textbox', 'aciname', PKEY1),
+        ('checkbox', 'attrs', 'businesscategory'),
+    ],
+    'mod': [
+        ('checkbox', 'attrs', 'businesscategory'),
+        ('checkbox', 'attrs', 'departmentnumber'),
+        ('checkbox', 'attrs', 'destinationindicator'),
+    ],
+}
+
+DATA2 = [
+    ('checkbox', 'attrs', 'businesscategory'),
+    ('checkbox', 'attrs', 'departmentnumber'),
+    ('checkbox', 'attrs', 'destinationindicator'),
+]
+
+DATA_ALL = {
+    'pkey': PKEY,
+    'add': [
+        ('textbox', 'aciname', PKEY),
+        ('checkbox', 'attrs', 'audio'),
+        ('checkbox', 'attrs', 'businesscategory'),
+        ('checkbox', 'attrs', 'carlicense'),
+        ('checkbox', 'attrs', 'cn'),
+        ('checkbox', 'attrs', 'departmentnumber'),
+        ('checkbox', 'attrs', 'description'),
+        ('checkbox', 'attrs', 'destinationindicator'),
+        ('checkbox', 'attrs', 'displayname'),
+        ('checkbox', 'attrs', 'employeenumber'),
+        ('checkbox', 'attrs', 'employeetype'),
+        ('checkbox', 'attrs', 'facsimiletelephonenumber'),
+        ('checkbox', 'attrs', 'gecos'),
+        ('checkbox', 'attrs', 'gidnumber'),
+        ('checkbox', 'attrs', 'givenname'),
+        ('checkbox', 'attrs', 'homedirectory'),
+        ('checkbox', 'attrs', 'homephone'),
+        ('checkbox', 'attrs', 'homepostaladdress'),
+        ('checkbox', 'attrs', 'inetuserhttpurl'),
+        ('checkbox', 'attrs', 'inetuserstatus'),
+        ('checkbox', 'attrs', 'initials'),
+        ('checkbox', 'attrs', 'internationalisdnnumber'),
+        ('checkbox', 'attrs', 'ipacertmapdata'),
+        ('checkbox', 'attrs', 'ipakrbauthzdata'),
+        ('checkbox', 'attrs', 'ipasshpubkey'),
+        ('checkbox', 'attrs', 'ipatokenradiusconfiglink'),
+        ('checkbox', 'attrs', 'ipatokenradiususername'),
+        ('checkbox', 'attrs', 'ipauniqueid'),
+        ('checkbox', 'attrs', 'ipauserauthtype'),
+        ('checkbox', 'attrs', 'jpegphoto'),
+        ('checkbox', 'attrs', 'krballowedtodelegateto'),
+        ('checkbox', 'attrs', 'krbcanonicalname'),
+        ('checkbox', 'attrs', 'krbextradata'),
+        ('checkbox', 'attrs', 'krblastadminunlock'),
+        ('checkbox', 'attrs', 'krblastfailedauth'),
+        ('checkbox', 'attrs', 'krblastpwdchange'),
+        ('checkbox', 'attrs', 'krblastsuccessfulauth'),
+        ('checkbox', 'attrs', 'krbloginfailedcount'),
+        ('checkbox', 'attrs', 'krbmaxrenewableage'),
+        ('checkbox', 'attrs', 'krbmaxticketlife'),
+        ('checkbox', 'attrs', 'krbpasswordexpiration'),
+        ('checkbox', 'attrs', 'krbprincipalaliases'),
+        ('checkbox', 'attrs', 'krbprincipalauthind'),
+        ('checkbox', 'attrs', 'krbprincipalexpiration'),
+        ('checkbox', 'attrs', 'krbprincipalkey'),
+        ('checkbox', 'attrs', 'krbprincipalname'),
+        ('checkbox', 'attrs', 'krbprincipaltype'),
+        ('checkbox', 'attrs', 'krbpwdhistory'),
+        ('checkbox', 'attrs', 'krbpwdpolicyreference'),
+        ('checkbox', 'attrs', 'krbticketflags'),
+        ('checkbox', 'attrs', 'krbticketpolicyreference'),
+        ('checkbox', 'attrs', 'krbupenabled'),
+        ('checkbox', 'attrs', 'l'),
+        ('checkbox', 'attrs', 'labeleduri'),
+        ('checkbox', 'attrs', 'loginshell'),
+        ('checkbox', 'attrs', 'mail'),
+        ('checkbox', 'attrs', 'manager'),
+        ('checkbox', 'attrs', 'memberof'),
+        ('checkbox', 'attrs', 'mepmanagedentry'),
+        ('checkbox', 'attrs', 'mobile'),
+        ('checkbox', 'attrs', 'o'),
+        ('checkbox', 'attrs', 'objectclass'),
+        ('checkbox', 'attrs', 'ou'),
+        ('checkbox', 'attrs', 'pager'),
+        ('checkbox', 'attrs', 'photo'),
+        ('checkbox', 'attrs', 'physicaldeliveryofficename'),
+        ('checkbox', 'attrs', 'postaladdress'),
+        ('checkbox', 'attrs', 'postalcode'),
+        ('checkbox', 'attrs', 'postofficebox'),
+        ('checkbox', 'attrs', 'preferreddeliverymethod'),
+        ('checkbox', 'attrs', 'preferredlanguage'),
+        ('checkbox', 'attrs', 'registeredaddress'),
+        ('checkbox', 'attrs', 'roomnumber'),
+        ('checkbox', 'attrs', 'secretary'),
+        ('checkbox', 'attrs', 'seealso'),
+        ('checkbox', 'attrs', 'sn'),
+        ('checkbox', 'attrs', 'st'),
+        ('checkbox', 'attrs', 'street'),
+        ('checkbox', 'attrs', 'telephonenumber'),
+        ('checkbox', 'attrs', 'teletexterminalidentifier'),
+        ('checkbox', 'attrs', 'telexnumber'),
+        ('checkbox', 'attrs', 'title'),
+        ('checkbox', 'attrs', 'uid'),
+        ('checkbox', 'attrs', 'uidnumber'),
+        ('checkbox', 'attrs', 'usercertificate'),
+        ('checkbox', 'attrs', 'userclass'),
+        ('checkbox', 'attrs', 'userpassword'),
+        ('checkbox', 'attrs', 'userpkcs12'),
+        ('checkbox', 'attrs', 'usersmimecertificate'),
+        ('checkbox', 'attrs', 'x121address'),
+        ('checkbox', 'attrs', 'x500uniqueidentifier'),
+    ],
+}
diff --git a/ipatests/test_webui/test_selfservice.py b/ipatests/test_webui/test_selfservice.py
index e7c031b333..de7455aeda 100644
--- a/ipatests/test_webui/test_selfservice.py
+++ b/ipatests/test_webui/test_selfservice.py
@@ -23,21 +23,32 @@
 
 from ipatests.test_webui.ui_driver import UI_driver
 from ipatests.test_webui.ui_driver import screenshot
+import ipatests.test_webui.data_selfservice as data_selfservice
+import ipatests.test_webui.data_user as user
 import pytest
 
-ENTITY = 'selfservice'
-PKEY = 'itest-selfservice-rule'
-DATA = {
-    'pkey': PKEY,
-    'add': [
-        ('textbox', 'aciname', PKEY),
-        ('checkbox', 'attrs', 'audio'),
-        ('checkbox', 'attrs', 'businesscategory'),
-    ],
-    'mod': [
-        ('checkbox', 'attrs', 'businesscategory'),
-    ],
-}
+try:
+    from selenium.webdriver.common.by import By
+    from selenium.webdriver.common.keys import Keys
+    from selenium.webdriver.common.action_chains import ActionChains
+except ImportError:
+    pass
+
+ENTRY_EXIST = 'This entry already exists'
+FIELD_REQ = 'Required field'
+INV_NAME = ("invalid 'name': Leading and trailing spaces are "
+            "not allowed")
+ERR_INCLUDE = 'May only contain letters, numbers, -, _, and space'
+SERVICE_ADDED = 'Self Service Permission successfully added'
+
+
+def reset_passwd(self, login, pwd):
+            self.navigate_to_entity(user.ENTITY)
+            self.navigate_to_record(login)
+            self.action_list_action('reset_password', False)
+            self.fill_password('password', pwd)
+            self.fill_password('password2', pwd)
+            self.dialog_button_click('confirm')
 
 
 @pytest.mark.tier1
@@ -49,4 +60,231 @@ def test_crud(self):
         Basic CRUD: selfservice entity
         """
         self.init_app()
-        self.basic_crud(ENTITY, DATA)
+        self.basic_crud(data_selfservice.ENTITY, data_selfservice.DATA)
+
+    @screenshot
+    def test_add_all_attr(self):
+        """
+        Add self service with all attribute
+        """
+        self.init_app()
+        self.add_record(data_selfservice.ENTITY, data_selfservice.DATA_ALL,
+                        delete=True)
+
+    @screenshot
+    def test_add_scenarios(self):
+        """
+        Test various add scenarios
+        """
+
+        # Add self service with Add and Add Another button
+        self.init_app()
+        records = [data_selfservice.DATA, data_selfservice.DATA1]
+        self.add_record(data_selfservice.ENTITY, records)
+
+        # check if record is added
+        for record in records:
+            self.assert_record(record['pkey'])
+
+        # cleanup
+        self.navigate_to_entity(data_selfservice.ENTITY)
+        self.select_multiple_records(records)
+        self.facet_button_click('remove')
+        self.dialog_button_click('ok')
+        for record in records:
+            self.assert_record(record['pkey'], negative=True)
+
+        # Add self service with Add and edit button
+        self.add_record(data_selfservice.ENTITY,
+                        data_selfservice.DATA1,
+                        dialog_btn='add_and_edit')
+
+        # cleanup
+        self.navigate_to_entity(data_selfservice.ENTITY)
+        self.delete(data_selfservice.ENTITY, [data_selfservice.DATA1])
+
+        # Add self service with Add and cancel button
+        self.add_record(data_selfservice.ENTITY, data_selfservice.DATA1,
+                        dialog_btn='cancel')
+
+    @screenshot
+    def test_undo_reset(self):
+        """
+        Test undo and reset operation
+        """
+        # Add self service permission and perform undo
+        self.init_app()
+        self.add_record(data_selfservice.ENTITY, data_selfservice.DATA1)
+        self.navigate_to_record(data_selfservice.PKEY1)
+        self.fill_fields(data_selfservice.DATA2)
+        self.click_undo_button('attrs')
+        self.wait_for_request()
+        # if undo succeed, 'save' button remains disabled
+        self.assert_facet_button_enabled('save', enabled=False)
+
+        # Add self service permission and perform reset
+        self.add_record(data_selfservice.ENTITY, data_selfservice.DATA1)
+        self.navigate_to_record(data_selfservice.PKEY1)
+        self.fill_fields(data_selfservice.DATA2)
+        self.facet_button_click('revert')
+        # if revert succeed, 'save' button remains disabled
+        self.assert_facet_button_enabled('save', enabled=False)
+
+    @screenshot
+    def test_permission_negative(self):
+        """
+        Negative test cases for self service permission
+        """
+        self.init_app()
+
+        # try to add duplicate entry
+        self.add_record(data_selfservice.ENTITY, data_selfservice.DATA1)
+        self.add_record(data_selfservice.ENTITY, data_selfservice.DATA1,
+                        negative=True, pre_delete=False)
+        self.assert_last_error_dialog(ENTRY_EXIST)
+        self.close_all_dialogs()
+        self.delete(data_selfservice.ENTITY, [data_selfservice.DATA1])
+        self.close_notifications()
+
+        # try to add permission without name and attribute
+        self.navigate_to_entity(data_selfservice.ENTITY)
+        self.wait_for_request()
+        self.facet_button_click('add')
+        self.dialog_button_click('add')
+        self.assert_field_validation(FIELD_REQ, field='aciname')
+        self.dialog_button_click('cancel')
+
+        # try to add permission without name but having attribute
+        self.navigate_to_entity(data_selfservice.ENTITY)
+        self.wait_for_request()
+        self.facet_button_click('add')
+        self.check_option('attrs', 'displayname')
+        self.dialog_button_click('add')
+        self.assert_field_validation(FIELD_REQ, field='aciname')
+        self.dialog_button_click('cancel')
+
+        # try to add permission without having attribute.
+        self.navigate_to_entity(data_selfservice.ENTITY)
+        self.wait_for_request()
+        self.facet_button_click('add')
+        self.fill_textbox('aciname', data_selfservice.DATA1['pkey'])
+        self.dialog_button_click('add')
+        self.assert_field_validation(FIELD_REQ, field='attrs')
+        self.dialog_button_click('cancel')
+
+        # try to add aciname with leading space.
+        self.navigate_to_entity(data_selfservice.ENTITY)
+        self.wait_for_request()
+        self.facet_button_click('add')
+        self.fill_textbox('aciname',
+                          ' {}'.format(data_selfservice.DATA1['pkey']))
+        self.check_option('attrs', 'audio')
+        self.dialog_button_click('add')
+        self.assert_last_error_dialog(INV_NAME)
+        self.close_all_dialogs()
+
+        # try to add aciname with trailing space
+        self.navigate_to_entity(data_selfservice.ENTITY)
+        self.wait_for_request()
+        self.facet_button_click('add')
+        self.fill_textbox('aciname',
+                          '{} '.format(data_selfservice.DATA1['pkey']))
+        self.check_option('attrs', 'audio')
+        self.dialog_button_click('add')
+        self.assert_last_error_dialog(INV_NAME)
+        self.dialog_button_click('cancel')
+        self.dialog_button_click('cancel')
+
+        # try to add aciname with special char
+        self.navigate_to_entity(data_selfservice.ENTITY)
+        self.wait_for_request()
+        self.facet_button_click('add')
+        self.fill_textbox('aciname', '#%^')
+        self.dialog_button_click('add')
+        self.assert_field_validation(ERR_INCLUDE, field='aciname')
+        self.dialog_button_click('cancel')
+
+        # try to modify pesmission by removing all attributes
+        self.add_record(data_selfservice.ENTITY, data_selfservice.DATA1)
+        self.navigate_to_record(data_selfservice.DATA1['pkey'])
+        self.check_option('attrs', 'businesscategory')
+        self.facet_button_click('save')
+        self.assert_field_validation(FIELD_REQ, field='attrs')
+
+    @screenshot
+    def test_del_multiple_permission(self):
+        """
+        Try to delete multiple self service permission
+        """
+        self.init_app()
+        self.add_record(data_selfservice.ENTITY, data_selfservice.DATA1)
+        self.add_record(data_selfservice.ENTITY, data_selfservice.DATA)
+        self.delete(data_selfservice.ENTITY,
+                    [data_selfservice.DATA1,
+                     data_selfservice.DATA])
+        # check if record deleted
+        for key in [data_selfservice.DATA1['pkey'],
+                    data_selfservice.DATA['pkey']]:
+            self.assert_record(key, negative=True)
+
+    @screenshot
+    def test_permission_using_enter_key(self):
+        """
+        Try to add/delete persmission using enter key
+        """
+        # try to add using enter key
+        self.init_app()
+        self.add_record(data_selfservice.ENTITY,
+                        data_selfservice.DATA1,
+                        dialog_btn=None)
+        actions = ActionChains(self.driver)
+        actions.send_keys(Keys.ENTER).perform()
+        self.wait()
+        self.assert_notification(assert_text=SERVICE_ADDED)
+        self.assert_record(data_selfservice.DATA1['pkey'])
+        self.close_notifications()
+
+        # try to delete using enter key
+        self.navigate_to_entity(data_selfservice.ENTITY)
+        self.select_record(data_selfservice.DATA1['pkey'])
+        self.facet_button_click('remove')
+        actions = ActionChains(self.driver)
+        actions.send_keys(Keys.ENTER).perform()
+        self.wait()
+        self.assert_notification(assert_text='1 item(s) deleted')
+        self.close_notifications()
+
+    @screenshot
+    def test_reset_sshkey_permsission(self):
+        """
+        Try to delete sshkey after altering sshkey permission
+        """
+        pwd = self.config.get('ipa_password')
+
+        self.init_app()
+        self.add_record(user.ENTITY, user.DATA, navigate=False)
+        reset_passwd(self, user.PKEY, pwd)
+        self.logout()
+        self.login(user.PKEY, password=pwd, new_password=pwd)
+        self.add_sshkey_to_record(user.SSH_RSA, user.PKEY, navigate=True)
+        self.assert_num_ssh_keys(1)
+        self.close_notifications()
+        self.logout()
+
+        self.init_app()
+        self.navigate_to_entity(data_selfservice.ENTITY)
+        self.navigate_to_record('Users can manage their own SSH public keys')
+        # to pass the validator, check some option from the options
+        self.check_option('attrs', 'carlicense')
+        # uncheck the ipasshpubkey checkbox.
+        self.check_option('attrs', 'ipasshpubkey')
+        self.facet_button_click('save')
+        self.close_notifications()
+        self.logout()
+
+        # check if delete button is visible for ssh key.
+        self.login(user.PKEY, password=pwd)
+        s = "div[name='ipasshpubkey'].multivalued-widget"
+        facet = self.get_facet()
+        btn = self.find(s, By.CSS_SELECTOR, facet, strict=True)
+        assert btn.is_displayed is not True
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/freeipa-devel@lists.fedorahosted.org/message/ESBKSZTU2NIJFLTVGJKQCXHSANKZWMK4/

Reply via email to