URL: https://github.com/freeipa/freeipa/pull/2324
Author: serg-cymbaluk
 Title: #2324: Fix webui tests
Action: opened

PR body:
"""
This pull request includes fixes for different issues which I have found while 
running Web UI tests manually.
There were also two regressions for version 4.6, so both of them have been 
merged: https://github.com/freeipa/freeipa/pull/2313, 
https://github.com/freeipa/freeipa/pull/2315
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/2324/head:pr2324
git checkout pr2324
From 8db8159d42623d4cfaf2fab3a8a7ced683488950 Mon Sep 17 00:00:00 2001
From: Serhii Tsymbaliuk <stsym...@redhat.com>
Date: Wed, 22 Aug 2018 08:54:09 +0200
Subject: [PATCH 1/7] Fix hardcoded CSR in test_webui/test_cert.py

---
 ipatests/test_webui/crypto_utils.py | 23 +++++++++++++++++++++++
 ipatests/test_webui/test_cert.py    | 21 +++------------------
 2 files changed, 26 insertions(+), 18 deletions(-)
 create mode 100644 ipatests/test_webui/crypto_utils.py

diff --git a/ipatests/test_webui/crypto_utils.py b/ipatests/test_webui/crypto_utils.py
new file mode 100644
index 0000000000..3be325211d
--- /dev/null
+++ b/ipatests/test_webui/crypto_utils.py
@@ -0,0 +1,23 @@
+#
+# Copyright (C) 2018  FreeIPA Contributors see COPYING for license
+#
+
+from cryptography import x509
+from cryptography.hazmat.backends import default_backend
+from cryptography.hazmat.primitives import serialization, hashes
+from cryptography.hazmat.primitives.asymmetric import rsa
+from cryptography.x509.oid import NameOID
+
+
+def generate_csr(hostname):
+    key = rsa.generate_private_key(
+        public_exponent=65537,
+        key_size=2048,
+        backend=default_backend()
+    )
+    csr = x509.CertificateSigningRequestBuilder()
+    csr = csr.subject_name(x509.Name([
+        x509.NameAttribute(NameOID.COMMON_NAME, u'{}'.format(hostname))
+    ]))
+    csr = csr.sign(key, hashes.SHA256(), default_backend())
+    return csr.public_bytes(serialization.Encoding.PEM)
diff --git a/ipatests/test_webui/test_cert.py b/ipatests/test_webui/test_cert.py
index 1cb8108f3a..c5e05bcab1 100644
--- a/ipatests/test_webui/test_cert.py
+++ b/ipatests/test_webui/test_cert.py
@@ -21,6 +21,7 @@
 Cert tests
 """
 
+from ipatests.test_webui.crypto_utils import generate_csr
 from ipatests.test_webui.ui_driver import UI_driver
 from ipatests.test_webui.ui_driver import screenshot
 from datetime import date, timedelta
@@ -28,23 +29,6 @@
 
 ENTITY = 'cert'
 
-CERT_CSR = ("""-----BEGIN NEW CERTIFICATE REQUEST-----
-MIICcjCCAVoCAQAwLTERMA8GA1UEChMISVBBLlRFU1QxGDAWBgNVBAMTD21hc3Rl
-ci5pcGEudGVzdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK9xZ/OT
-PC9vlwP78ACCYTOGy8C+Ho4OUF4p4PYPkns4Zdov6N/f0MlUcxY7cpAlKlAZT53b
-OphSKamc7nlNgUAzV1S6JTm1YXiTzG6mAOWWK/i3O25rNfiz0D+srlqS0ADsGPwG
-4vxuWJYwUEKcV4YgCYCJj78dD+yxoz5anVrNosN4tVGg6jfaPI9uu1T+FhsNM/AC
-EN7pa50bgeV7iBZs/pdZEXEsk18NO4W55yPAKQp5JFCL6eeBJcHTU/IuEb/YPCSr
-e873Iwzw4ZqW8dHbE10Za3VzdKPDUbtJp93rvU6imRavvifIAa3GgBuLYbpEXXcG
-B6MLHdWOApwPBoMCAwEAAaAAMA0GCSqGSIb3DQEBCwUAA4IBAQClXDGZoGUSetZP
-lwx//vSN6P6y30dpiHDQiY4hCLYplpoB7V6wXXVMyuKpJjRMQ2mSdyuFge14Lvwr
-y1pE8Vg0+D99PW09tGTp54egPCKeyXptJ/1xi/Quo70OfSSI01vSczMDGTa4OfAB
-VPzE2xey1qL0a0UHqwBaSqnt6D0Xmid79YP0XkVEqZeHZvprtXzeA4dNc1GrZrjb
-7bazcPXbd7PXQaEFvmhqbDMFvu3xMBm5HJd4WkYKvBFDw4NHfT6jw/yRZXkWwJ/F
-EI0h2e9yxrSKgOEpWmeCdETZhMCljx5C2rLNqLAWJIJQ293UuVRCg4Rn6fdIefhF
-yKHlBerZ
------END NEW CERTIFICATE REQUEST-----""")
-
 ERR_SPACE = "invalid '{}': Leading and trailing spaces are not allowed"
 ERR_MUST_INTEGER = "invalid '{}': must be an integer"
 LEAST_SERIAL = "invalid '{}': must be at least 0"
@@ -180,7 +164,8 @@ def test_search_revocation_reason(self):
 
         # add a new cert
         hostname = self.config.get('ipa_server')
-        record = add_cert(self, 'HTTP/{}'.format(hostname), CERT_CSR)
+        csr = generate_csr(hostname)
+        record = add_cert(self, 'HTTP/{}'.format(hostname), csr)
 
         # revoke added cert
         revoke_cert(self, record, '1')

From 5ddad9b78b3be3aebeeb6dbc5a5dbed430c885aa Mon Sep 17 00:00:00 2001
From: Serhii Tsymbaliuk <stsym...@redhat.com>
Date: Wed, 22 Aug 2018 09:25:09 +0200
Subject: [PATCH 2/7] Use random IPs and domains in test_webui/test_host.py

---
 ipatests/test_webui/test_host.py | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/ipatests/test_webui/test_host.py b/ipatests/test_webui/test_host.py
index 8f12b71654..facc68cc25 100644
--- a/ipatests/test_webui/test_host.py
+++ b/ipatests/test_webui/test_host.py
@@ -21,6 +21,9 @@
 Host tests
 """
 
+import uuid
+from random import randint
+
 from ipatests.test_webui.ui_driver import UI_driver
 from ipatests.test_webui.ui_driver import screenshot
 import ipatests.test_webui.data_hostgroup as hostgroup
@@ -52,7 +55,7 @@ def setup(self, *args, **kwargs):
         self.prep_data4()
 
     def prep_data(self):
-        host = 'itest'
+        host = self.rand_host()
         domain = self.config.get('ipa_domain')
         ip = self.get_ip()
         self.data = self.get_data(host, domain, ip)
@@ -60,21 +63,21 @@ def prep_data(self):
         return self.data
 
     def prep_data2(self):
-        host = 'itest2'
+        host = self.rand_host()
         domain = self.config.get('ipa_domain')
         self.data2 = self.get_data(host, domain)
         self.pkey2 = self.data2['pkey']
         return self.data2
 
     def prep_data3(self):
-        host = 'itest3'
+        host = self.rand_host()
         domain = self.config.get('ipa_domain')
         self.data3 = self.get_data(host, domain)
         self.pkey3 = self.data3['pkey']
         return self.data3
 
     def prep_data4(self):
-        host = 'itest4'
+        host = self.rand_host()
         domain = self.config.get('ipa_domain')
         self.data4 = self.get_data(host, domain)
         self.pkey4 = self.data4['pkey']
@@ -117,10 +120,19 @@ def get_ip(self):
         ip = self.config.get('ipa_ip')
         if not ip:
             self.skip('FreeIPA Server IP address not configured')
-        ip = ip.split('.')
-        last = int(ip.pop())
-        ip.append(str(last + 1))
-        return '.'.join(ip)
+
+        while True:
+            new_ip = '10.{}.{}.{}'.format(
+                randint(0, 255),
+                randint(0, 255),
+                randint(1, 254)
+            )
+            if new_ip != ip: break
+        return new_ip
+
+    @staticmethod
+    def rand_host():
+        return 'host-{}'.format(uuid.uuid4().hex[:8])
 
     def load_file(self, path):
         """

From d0d54358c89eb1447cce0ada9472aea39e7913ab Mon Sep 17 00:00:00 2001
From: Serhii Tsymbaliuk <stsym...@redhat.com>
Date: Wed, 22 Aug 2018 11:24:35 +0200
Subject: [PATCH 3/7] Increase request timeout for WebUI tests

---
 ipatests/test_webui/ui_driver.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ipatests/test_webui/ui_driver.py b/ipatests/test_webui/ui_driver.py
index 76db402c60..5aa300a121 100644
--- a/ipatests/test_webui/ui_driver.py
+++ b/ipatests/test_webui/ui_driver.py
@@ -123,7 +123,7 @@ def setup_class(cls):
             raise unittest.SkipTest('Selenium not installed')
 
     def setup(self, driver=None, config=None):
-        self.request_timeout = 30
+        self.request_timeout = 60
         self.driver = driver
         self.config = config
         if not config:

From 14c31997168eff9353dbdd94bea48b0a7461773b Mon Sep 17 00:00:00 2001
From: Serhii Tsymbaliuk <stsym...@redhat.com>
Date: Thu, 23 Aug 2018 16:09:35 +0200
Subject: [PATCH 4/7] Fix test_realmdomains::test_add_single_labeled_domain
 (Web UI test)

---
 ipatests/test_webui/test_realmdomains.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ipatests/test_webui/test_realmdomains.py b/ipatests/test_webui/test_realmdomains.py
index 08aba2df5d..87912fe71e 100644
--- a/ipatests/test_webui/test_realmdomains.py
+++ b/ipatests/test_webui/test_realmdomains.py
@@ -127,15 +127,15 @@ def test_read(self):
     @screenshot
     def test_add_single_labeled_domain(self):
         """
-        Add domain with special_character
+        Add single label domain
         """
         self.init_app()
         self.navigate_to_entity(ENTITY)
 
-        domain_with_special_char = u'´╗┐ipa@123#'
+        single_label_domain = u'single-label-domain'
 
         # add with force - skipping DNS check
-        self._add_associateddomain([domain_with_special_char], force=True)
+        self._add_associateddomain([single_label_domain], force=True)
         dialog = self.get_last_error_dialog()
         assert ("invalid 'domain': single label domains are not supported"
                 in dialog.text)

From 2b2e8eb1ce7521b5b1a3bff08a98946bad55d1ed Mon Sep 17 00:00:00 2001
From: Serhii Tsymbaliuk <stsym...@redhat.com>
Date: Mon, 27 Aug 2018 12:58:01 +0200
Subject: [PATCH 5/7] Use random realmdomains in
 test_webui/test_realmdomains.py

---
 ipatests/test_webui/test_realmdomains.py | 98 ++++++++++++++----------
 1 file changed, 57 insertions(+), 41 deletions(-)

diff --git a/ipatests/test_webui/test_realmdomains.py b/ipatests/test_webui/test_realmdomains.py
index 87912fe71e..2107e2cb44 100644
--- a/ipatests/test_webui/test_realmdomains.py
+++ b/ipatests/test_webui/test_realmdomains.py
@@ -25,11 +25,13 @@
 Force udpate means Force Update in WebUI.
 """
 
+import uuid
+
 from ipatests.test_webui.ui_driver import UI_driver
 from ipatests.test_webui.ui_driver import screenshot
 from ipatests.test_webui.data_dns import (
     ZONE_ENTITY, FORWARD_ZONE_ENTITY, ZONE_DATA, FORWARD_ZONE_DATA,
-    ZONE_PKEY, FORWARD_ZONE_PKEY, ZONE_DEFAULT_FACET
+    ZONE_DEFAULT_FACET
 )
 import pytest
 
@@ -61,7 +63,7 @@ def prepare_dns_zone(self, realmdomain):
 
         # add DNS domain
         self.navigate_to_entity(ZONE_ENTITY)
-        self.add_record(ZONE_ENTITY, ZONE_DATA)
+        self.add_record(ZONE_ENTITY, self.copy_zone_data(realmdomain))
 
         realm = self.config.get('ipa_realm')
 
@@ -72,7 +74,7 @@ def prepare_dns_zone(self, realmdomain):
 
         # re-add _TXT kerberos.$domain "$REALM"
         self.navigate_to_entity(ZONE_ENTITY)
-        self.navigate_to_record(ZONE_PKEY)
+        self.navigate_to_record(realmdomain + '.')
 
         DNS_RECORD_ADD_DATA = {
             'pkey': '_kerberos',
@@ -96,6 +98,19 @@ def _add_associateddomain(self, values, force=False):
         self.wait_for_request()
         self.close_notifications()
 
+    @staticmethod
+    def copy_zone_data(realmdomain, zone_data=ZONE_DATA):
+        data = zone_data.copy()
+        data['pkey'] = realmdomain
+        for i, (widget, name, _) in enumerate(data['add']):
+            if name == 'idnsname':
+                data['add'][i] = (widget, name, realmdomain)
+        return data
+
+    @staticmethod
+    def rand_realmdomain():
+        return 'zone-{}.itest'.format(uuid.uuid4().hex[:8])
+
     @screenshot
     def test_read(self):
         """
@@ -112,7 +127,7 @@ def test_read(self):
         self.del_realm_domain('itest.bar', 'force')
         self.wait_for_request()
 
-        realmdomain = ZONE_PKEY.strip('.')
+        realmdomain = self.rand_realmdomain()
         self.prepare_dns_zone(realmdomain)
 
         # add Realm Domain and Check DNS
@@ -122,7 +137,7 @@ def test_read(self):
         # cleanup
         self.del_realm_domain(realmdomain, 'ok')
         self.navigate_to_entity(ZONE_ENTITY)
-        self.delete_record(ZONE_PKEY)
+        self.delete_record(realmdomain + '.')
 
     @screenshot
     def test_add_single_labeled_domain(self):
@@ -201,7 +216,7 @@ def test_add_domain_and_update(self):
         self.init_app()
         self.navigate_to_entity(ENTITY)
 
-        realmdomain = ZONE_PKEY.strip('.')
+        realmdomain = self.rand_realmdomain()
         self.prepare_dns_zone(realmdomain)
 
         # add Realm Domain and Check DNS
@@ -215,7 +230,7 @@ def test_add_domain_and_update(self):
         # cleanup
         self.del_realm_domain(realmdomain, 'ok')
         self.navigate_to_entity(ZONE_ENTITY)
-        self.delete_record(ZONE_PKEY)
+        self.delete_record(realmdomain + '.')
 
     @screenshot
     def test_add_domain_and_refresh(self):
@@ -260,7 +275,7 @@ def test_add_duplicate_domain(self):
         """
         self.init_app()
 
-        realmdomain = ZONE_PKEY.strip('.')
+        realmdomain = self.rand_realmdomain()
         self.prepare_dns_zone(realmdomain)
 
         self.navigate_to_entity(ENTITY)
@@ -275,7 +290,7 @@ def test_add_duplicate_domain(self):
         # cleanup
         self.del_realm_domain(realmdomain, 'force')
         self.navigate_to_entity(ZONE_ENTITY)
-        self.delete_record(ZONE_PKEY)
+        self.delete_record(realmdomain + '.')
 
     @screenshot
     def test_add_empty_domain(self):
@@ -331,7 +346,7 @@ def test_del_domain_undo(self):
         """
         self.init_app()
 
-        realmdomain = ZONE_PKEY.strip('.')
+        realmdomain = self.rand_realmdomain()
         self.prepare_dns_zone(realmdomain)
 
         # add
@@ -354,7 +369,7 @@ def test_del_domain_undo(self):
         # cleanup
         self.del_realm_domain(realmdomain, 'ok')
         self.navigate_to_entity(ZONE_ENTITY)
-        self.delete_record(ZONE_PKEY)
+        self.delete_record(realmdomain + '.')
 
     @screenshot
     def test_del_domain_undo_all(self):
@@ -363,7 +378,7 @@ def test_del_domain_undo_all(self):
         """
         self.init_app()
 
-        realmdomain = ZONE_PKEY.strip('.')
+        realmdomain = self.rand_realmdomain()
         self.prepare_dns_zone(realmdomain)
 
         # add
@@ -386,7 +401,7 @@ def test_del_domain_undo_all(self):
         # cleanup
         self.del_realm_domain(realmdomain, 'ok')
         self.navigate_to_entity(ZONE_ENTITY)
-        self.delete_record(ZONE_PKEY)
+        self.delete_record(realmdomain + '.')
 
     @screenshot
     def test_del_domain_revert(self):
@@ -395,7 +410,7 @@ def test_del_domain_revert(self):
         """
         self.init_app()
 
-        realmdomain = ZONE_PKEY.strip('.')
+        realmdomain = self.rand_realmdomain()
         self.prepare_dns_zone(realmdomain)
 
         # add
@@ -414,7 +429,7 @@ def test_del_domain_revert(self):
         # cleanup
         self.del_realm_domain(realmdomain, 'ok')
         self.navigate_to_entity(ZONE_ENTITY)
-        self.delete_record(ZONE_PKEY)
+        self.delete_record(realmdomain + '.')
 
     @screenshot
     def test_del_domain_and_refresh(self):
@@ -423,7 +438,7 @@ def test_del_domain_and_refresh(self):
         """
         self.init_app()
 
-        realmdomain = ZONE_PKEY.strip('.')
+        realmdomain = self.rand_realmdomain()
         self.prepare_dns_zone(realmdomain)
 
         # add
@@ -443,7 +458,7 @@ def test_del_domain_and_refresh(self):
         # cleanup
         self.del_realm_domain(realmdomain, 'ok')
         self.navigate_to_entity(ZONE_ENTITY)
-        self.delete_record(ZONE_PKEY)
+        self.delete_record(realmdomain + '.')
 
     @screenshot
     def test_del_domain_and_update(self):
@@ -452,7 +467,7 @@ def test_del_domain_and_update(self):
         """
         self.init_app()
 
-        realmdomain = ZONE_PKEY.strip('.')
+        realmdomain = self.rand_realmdomain()
         self.prepare_dns_zone(realmdomain)
 
         # add
@@ -474,7 +489,7 @@ def test_del_domain_and_update(self):
 
         # cleanup
         self.navigate_to_entity(ZONE_ENTITY)
-        self.delete_record(ZONE_PKEY)
+        self.delete_record(realmdomain + '.')
 
     @screenshot
     def test_del_domain_with_force_update(self):
@@ -483,7 +498,7 @@ def test_del_domain_with_force_update(self):
         """
         self.init_app()
 
-        realmdomain = ZONE_PKEY.strip('.')
+        realmdomain = self.rand_realmdomain()
         self.prepare_dns_zone(realmdomain)
 
         # add
@@ -505,7 +520,7 @@ def test_del_domain_with_force_update(self):
 
         # cleanup
         self.navigate_to_entity(ZONE_ENTITY)
-        self.delete_record(ZONE_PKEY)
+        self.delete_record(realmdomain + '.')
 
     @screenshot
     def test_add_non_dns_configured_domain_negative(self):
@@ -517,7 +532,7 @@ def test_add_non_dns_configured_domain_negative(self):
         """
         self.init_app()
 
-        realmdomain = ZONE_PKEY.strip('.')
+        realmdomain = self.rand_realmdomain()
 
         self.navigate_to_entity(ENTITY)
         self._add_associateddomain([realmdomain])
@@ -538,7 +553,7 @@ def test_add_non_dns_configured_domain_positive(self):
         """
         self.init_app()
 
-        realmdomain = ZONE_PKEY.strip('.')
+        realmdomain = self.rand_realmdomain()
 
         self.navigate_to_entity(ENTITY)
         self._add_associateddomain([realmdomain], force=True)
@@ -549,7 +564,7 @@ def test_add_non_dns_configured_domain_positive(self):
         # cleanup
         self.del_realm_domain(realmdomain, 'ok')
         self.navigate_to_entity(ZONE_ENTITY)
-        self.delete_record(ZONE_PKEY)
+        self.delete_record(realmdomain + '.')
 
     @screenshot
     def test_del_domain_of_ipa_server_bug1035286(self):
@@ -564,7 +579,7 @@ def test_del_domain_of_ipa_server_bug1035286(self):
 
         ipadomain = self.config.get('ipa_domain')
 
-        realmdomain = ZONE_PKEY.strip('.')
+        realmdomain = self.rand_realmdomain()
         self.prepare_dns_zone(realmdomain)
 
         self.navigate_to_entity(ENTITY)
@@ -586,7 +601,7 @@ def test_del_domain_of_ipa_server_bug1035286(self):
         # cleanup
         self.del_realm_domain(realmdomain, 'ok')
         self.navigate_to_entity(ZONE_ENTITY)
-        self.delete_record(ZONE_PKEY)
+        self.delete_record(realmdomain + '.')
 
     @screenshot
     def test_dnszone_add_hooked_to_realmdomains_mod(self):
@@ -604,15 +619,15 @@ def test_dnszone_add_hooked_to_realmdomains_mod(self):
         """
         self.init_app()
 
-        realmdomain = ZONE_PKEY.strip('.')
+        realmdomain = self.rand_realmdomain()
         realm = self.config.get('ipa_realm')
 
         # add DNS domain
         self.navigate_to_entity(ZONE_ENTITY)
-        self.add_record(ZONE_ENTITY, ZONE_DATA)
-        self.assert_record(ZONE_PKEY)
+        self.add_record(ZONE_ENTITY, self.copy_zone_data(realmdomain))
+        self.assert_record(realmdomain + '.')
 
-        self.navigate_to_record(ZONE_PKEY)
+        self.navigate_to_record(realmdomain + '.')
         self.assert_record('_kerberos')
         self.assert_record_value('TXT', '_kerberos', 'type')
         self.assert_record_value(realm, '_kerberos', 'data')
@@ -627,15 +642,15 @@ def test_dnszone_add_hooked_to_realmdomains_mod(self):
         self.wait_for_request()
 
         self.navigate_to_entity(ZONE_ENTITY)
-        self.assert_record(ZONE_PKEY)
+        self.assert_record(realmdomain + '.')
 
-        self.navigate_to_record(ZONE_PKEY)
+        self.navigate_to_record(realmdomain + '.')
         self.facet_button_click('refresh')
         self.assert_record('_kerberos', negative=True)
 
         # cleanup
         self.navigate_to_entity(ZONE_ENTITY)
-        self.delete_record(ZONE_PKEY)
+        self.delete_record(realmdomain + '.')
 
     @screenshot
     def test_dns_reversezone_add_hooked_to_realmdomains_mod(self):
@@ -650,12 +665,13 @@ def test_dns_reversezone_add_hooked_to_realmdomains_mod(self):
         """
         self.init_app()
 
-        realmdomain = FORWARD_ZONE_PKEY.strip('.')
+        realmdomain = self.rand_realmdomain()
 
         # add DNS Reverse zone
         self.navigate_to_entity(FORWARD_ZONE_ENTITY)
-        self.add_record(FORWARD_ZONE_ENTITY, FORWARD_ZONE_DATA)
-        self.assert_record(FORWARD_ZONE_PKEY)
+        self.add_record(FORWARD_ZONE_ENTITY,
+                        self.copy_zone_data(realmdomain, FORWARD_ZONE_DATA))
+        self.assert_record(realmdomain + '.')
 
         self.navigate_to_entity(ENTITY)
         domains = self.get_multivalued_value('associateddomain')
@@ -663,7 +679,7 @@ def test_dns_reversezone_add_hooked_to_realmdomains_mod(self):
 
         # cleanup
         self.navigate_to_entity(FORWARD_ZONE_ENTITY)
-        self.delete_record(FORWARD_ZONE_PKEY)
+        self.delete_record(realmdomain + '.')
 
     @screenshot
     def test_dnszone_del_hooked_to_realmdomains_mod(self):
@@ -680,19 +696,19 @@ def test_dnszone_del_hooked_to_realmdomains_mod(self):
         """
         self.init_app()
 
-        realmdomain = ZONE_PKEY.strip('.')
+        realmdomain = self.rand_realmdomain()
 
         # add DNS domain
         self.navigate_to_entity(ZONE_ENTITY)
-        self.add_record(ZONE_ENTITY, ZONE_DATA)
-        self.assert_record(ZONE_PKEY)
+        self.add_record(ZONE_ENTITY, self.copy_zone_data(realmdomain))
+        self.assert_record(realmdomain + '.')
 
         self.navigate_to_entity(ENTITY)
         domains = self.get_multivalued_value('associateddomain')
         assert realmdomain in domains
 
         self.navigate_to_entity(ZONE_ENTITY)
-        self.delete_record(ZONE_PKEY)
+        self.delete_record(realmdomain + '.')
 
         self.navigate_to_entity(ENTITY)
         domains = self.get_multivalued_value('associateddomain')

From 736e7903ea8c634669deca8263eaa9f60f367c5b Mon Sep 17 00:00:00 2001
From: Serhii Tsymbaliuk <stsym...@redhat.com>
Date: Thu, 30 Aug 2018 08:58:35 +0200
Subject: [PATCH 6/7] Fix test_user::test_login_without_username (Web UI test)

---
 ipatests/test_webui/test_automember.py     |  3 +-
 ipatests/test_webui/test_hostgroup.py      | 11 ++--
 ipatests/test_webui/test_idviews.py        |  4 +-
 ipatests/test_webui/test_netgroup.py       |  5 +-
 ipatests/test_webui/test_selinuxusermap.py |  5 +-
 ipatests/test_webui/test_sudo.py           |  5 +-
 ipatests/test_webui/test_trust.py          |  3 +-
 ipatests/test_webui/test_user.py           |  5 +-
 ipatests/test_webui/ui_driver.py           | 63 +++++++++-------------
 9 files changed, 56 insertions(+), 48 deletions(-)

diff --git a/ipatests/test_webui/test_automember.py b/ipatests/test_webui/test_automember.py
index 5b07849b82..a6b48a26ee 100644
--- a/ipatests/test_webui/test_automember.py
+++ b/ipatests/test_webui/test_automember.py
@@ -95,7 +95,8 @@ def test_rebuild_membership_hosts(self):
         self.init_app()
 
         host_util = host_tasks()
-        host_util.setup(self.driver, self.config)
+        host_util.driver = self.driver
+        host_util.config = self.config
         domain = self.config.get('ipa_domain')
         host1 = 'web1.%s' % domain
         host2 = 'web2.%s' % domain
diff --git a/ipatests/test_webui/test_hostgroup.py b/ipatests/test_webui/test_hostgroup.py
index 5655986150..3899e13c12 100644
--- a/ipatests/test_webui/test_hostgroup.py
+++ b/ipatests/test_webui/test_hostgroup.py
@@ -59,7 +59,9 @@ def test_associations(self):
         """
         self.init_app()
         host = host_tasks()
-        host.setup(self.driver, self.config)
+        host.driver = self.driver
+        host.config = self.config
+        host.prep_data2()
 
         # prepare
         # -------
@@ -101,7 +103,9 @@ def test_indirect_associations(self):
         """
         self.init_app()
         host = host_tasks()
-        host.setup(self.driver, self.config)
+        host.driver = self.driver
+        host.config = self.config
+        host.prep_data2()
 
         # add
         # ---
@@ -163,7 +167,8 @@ def test_names_and_button(self):
         """
         self.init_app()
         host = host_tasks()
-        host.setup(self.driver, self.config)
+        host.driver = self.driver
+        host.config = self.config
 
         self.add_record(hostgroup.ENTITY, hostgroup.DATA6)
         self.add_record(hostgroup.ENTITY, hostgroup.DATA7, navigate=False)
diff --git a/ipatests/test_webui/test_idviews.py b/ipatests/test_webui/test_idviews.py
index 7e7d905644..ca64e368b2 100644
--- a/ipatests/test_webui/test_idviews.py
+++ b/ipatests/test_webui/test_idviews.py
@@ -96,7 +96,9 @@ def test_hosts(self):
         """
         self.init_app()
         host = host_tasks()
-        host.setup(self.driver, self.config)
+        host.driver = self.driver
+        host.config = self.config
+        host.prep_data()
 
         self.add_record(HOST_ENTITY, host.data)
         self.add_record(hostgroup.ENTITY, hostgroup.DATA)
diff --git a/ipatests/test_webui/test_netgroup.py b/ipatests/test_webui/test_netgroup.py
index 6f1c61e547..d6c3c280a4 100644
--- a/ipatests/test_webui/test_netgroup.py
+++ b/ipatests/test_webui/test_netgroup.py
@@ -293,7 +293,10 @@ def test_mod(self):
         """
         self.init_app()
         host = host_tasks()
-        host.setup(self.driver, self.config)
+        host.driver = self.driver
+        host.config = self.config
+        host.prep_data()
+        host.prep_data2()
 
         self.add_record(netgroup.ENTITY, netgroup.DATA2)
         self.add_record(user.ENTITY, user.DATA)
diff --git a/ipatests/test_webui/test_selinuxusermap.py b/ipatests/test_webui/test_selinuxusermap.py
index af93cb66c2..dda47889ff 100644
--- a/ipatests/test_webui/test_selinuxusermap.py
+++ b/ipatests/test_webui/test_selinuxusermap.py
@@ -68,7 +68,10 @@ def test_mod(self):
         """
         self.init_app()
         host = host_tasks()
-        host.setup(self.driver, self.config)
+        host.driver = self.driver
+        host.config = self.config
+        host.prep_data()
+        host.prep_data2()
 
         self.add_record(user.ENTITY, user.DATA)
         self.add_record(user.ENTITY, user.DATA2, navigate=False)
diff --git a/ipatests/test_webui/test_sudo.py b/ipatests/test_webui/test_sudo.py
index eb6430fd02..4aae2f14b2 100644
--- a/ipatests/test_webui/test_sudo.py
+++ b/ipatests/test_webui/test_sudo.py
@@ -53,7 +53,10 @@ def test_mod(self):
         """
         self.init_app()
         host = host_tasks()
-        host.setup(self.driver, self.config)
+        host.driver = self.driver
+        host.config = self.config
+        host.prep_data()
+        host.prep_data2()
 
         self.add_record(netgroup.ENTITY, netgroup.DATA2)
 
diff --git a/ipatests/test_webui/test_trust.py b/ipatests/test_webui/test_trust.py
index 621b2d4778..57d7e7aab7 100644
--- a/ipatests/test_webui/test_trust.py
+++ b/ipatests/test_webui/test_trust.py
@@ -124,7 +124,8 @@ def test_range_types(self):
         self.init_app()
 
         r_tasks = range_tasks()
-        r_tasks.setup(self.driver, self.config)
+        r_tasks.driver = self.driver
+        r_tasks.config = self.config
         r_tasks.get_shifts()
         range_add = r_tasks.get_add_data('')
         base_id = range_add[2][2]
diff --git a/ipatests/test_webui/test_user.py b/ipatests/test_webui/test_user.py
index 98fb176442..b3b0332163 100644
--- a/ipatests/test_webui/test_user.py
+++ b/ipatests/test_webui/test_user.py
@@ -419,7 +419,10 @@ def fill_password_dialog(self, password, current=None):
 
     @screenshot
     def test_login_without_username(self):
-
+        """
+        Try to login with no username provided
+        """
+        self.driver.delete_all_cookies()
         self.init_app(login='', password='xxx123')
 
         alert_e = self.find('.alert[data-name="username"]',
diff --git a/ipatests/test_webui/ui_driver.py b/ipatests/test_webui/ui_driver.py
index 5aa300a121..48d5200dbc 100644
--- a/ipatests/test_webui/ui_driver.py
+++ b/ipatests/test_webui/ui_driver.py
@@ -122,20 +122,22 @@ def setup_class(cls):
         if NO_SELENIUM:
             raise unittest.SkipTest('Selenium not installed')
 
-    def setup(self, driver=None, config=None):
+        cls.driver = None
+        cls.config = None
+        cls.load_config()
+        if not cls.driver:
+            cls.driver = cls.get_driver()
+
+    def setup(self):
         self.request_timeout = 60
-        self.driver = driver
-        self.config = config
-        if not config:
-            self.load_config()
-        if not self.driver:
-            self.driver = self.get_driver()
         self.driver.maximize_window()
 
-    def teardown(self):
-        self.driver.quit()
+    @classmethod
+    def teardown_class(cls):
+        cls.driver.quit()
 
-    def load_config(self):
+    @classmethod
+    def load_config(cls):
         """
         Load configuration
 
@@ -148,7 +150,7 @@ def load_config(self):
         if not NO_YAML and os.path.isfile(path):
             try:
                 with open(path, 'r') as conf:
-                    self.config = yaml.load(conf)
+                    cls.config = yaml.load(conf)
             except yaml.YAMLError as e:
                 raise unittest.SkipTest("Invalid Web UI config.\n%s" % e)
             except IOError as e:
@@ -156,9 +158,9 @@ def load_config(self):
                     "Can't load Web UI test config: %s" % e
                 )
         else:
-            self.config = {}
+            cls.config = {}
 
-        c = self.config
+        c = cls.config
 
         # override with environmental variables
         for k, v in ENV_MAP.items():
@@ -174,13 +176,14 @@ def load_config(self):
         if 'type' not in c:
             c['type'] = DEFAULT_TYPE
 
-    def get_driver(self):
+    @classmethod
+    def get_driver(cls):
         """
         Get WebDriver according to configuration
         """
-        browser = self.config["browser"]
-        port = self.config["port"]
-        driver_type = self.config["type"]
+        browser = cls.config["browser"]
+        port = cls.config["port"]
+        driver_type = cls.config["type"]
 
         options = None
 
@@ -189,9 +192,9 @@ def get_driver(self):
             options.binary_location = paths.CHROMIUM_BROWSER
 
         if driver_type == 'remote':
-            if 'host' not in self.config:
+            if 'host' not in cls.config:
                 raise unittest.SkipTest('Selenium server host not configured')
-            host = self.config["host"]
+            host = cls.config["host"]
 
             if browser == 'chrome':
                 capabilities = DesiredCapabilities.CHROME
@@ -221,9 +224,9 @@ def get_driver(self):
                     driver = webdriver.Ie()
                 else:
                     fp = None
-                    if "ff_profile" in self.config:
-                        fp = webdriver.FirefoxProfile(self.config["ff_profile"])
-                    ff_log_path = self.config.get("geckodriver_log_path")
+                    if "ff_profile" in cls.config:
+                        fp = webdriver.FirefoxProfile(cls.config["ff_profile"])
+                    ff_log_path = cls.config.get("geckodriver_log_path")
                     driver = webdriver.Firefox(fp, log_path=ff_log_path)
             except URLError as e:
                 raise unittest.SkipTest(
@@ -354,22 +357,6 @@ def load(self):
         """
         Navigate to Web UI first page and wait for loading of all dependencies.
         """
-        # If the application is already loaded, there is no need to re-enter
-        # the URL on the address bar and reloading everything.
-        # This help us to create scenarios like login -> logout -> login
-
-        # if a page is already loaded we click in the IPA logo to go to the
-        # initial page
-        ipa_logo = self.find('.navbar-brand', By.CSS_SELECTOR)
-        if ipa_logo and ipa_logo.is_displayed():
-            self.move_to_element_in_page(ipa_logo)
-            ipa_logo.click()
-            return
-
-        # already on the first page
-        if self.login_screen_visible():
-            return
-
         # if is not any of above cases, we need to load the application for
         # its first time entering the URL in the address bar
         self.driver.get(self.get_base_url())

From 9f25517885762b66e439647c81a74fb02d4f9480 Mon Sep 17 00:00:00 2001
From: Serhii Tsymbaliuk <stsym...@redhat.com>
Date: Tue, 4 Sep 2018 08:55:01 +0200
Subject: [PATCH 7/7] Fix unpermitted user session in test_selfservice (Web UI
 test)

---
 ipatests/test_webui/test_selfservice.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/ipatests/test_webui/test_selfservice.py b/ipatests/test_webui/test_selfservice.py
index de7455aeda..9c501c8247 100644
--- a/ipatests/test_webui/test_selfservice.py
+++ b/ipatests/test_webui/test_selfservice.py
@@ -287,4 +287,10 @@ def test_reset_sshkey_permsission(self):
         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
+        btn_is_displayed = btn.is_displayed
+
+        # logout needs to prevent using this unpermitted user in other tests
+        try:
+            assert btn_is_displayed is not True
+        finally:
+            self.logout()
_______________________________________________
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.fedorahosted.org/archives/list/freeipa-devel@lists.fedorahosted.org

Reply via email to