URL: https://github.com/freeipa/freeipa/pull/1961
Author: mrizwan93
 Title: #1961: Extended UI test for Certificates
Action: opened

PR body:
"""
UI test for certificates

Signed-off-by: Mohammad Rizwan Yusuf <myu...@redhat.com>
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/1961/head:pr1961
git checkout pr1961
From 8376597b19410f8dc328be37244c9fae711ea3f8 Mon Sep 17 00:00:00 2001
From: Mohammad Rizwan Yusuf <myu...@redhat.com>
Date: Thu, 24 May 2018 18:56:17 +0530
Subject: [PATCH] Extended UI test for Certificates

Signed-off-by: Mohammad Rizwan Yusuf <myu...@redhat.com>
---
 ipatests/test_webui/data_cert.py |  18 ++
 ipatests/test_webui/test_cert.py | 448 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 464 insertions(+), 2 deletions(-)
 create mode 100644 ipatests/test_webui/data_cert.py

diff --git a/ipatests/test_webui/data_cert.py b/ipatests/test_webui/data_cert.py
new file mode 100644
index 0000000000..72d4d5d3a1
--- /dev/null
+++ b/ipatests/test_webui/data_cert.py
@@ -0,0 +1,18 @@
+ENTITY = 'cert'
+
+CERT_CSR = (""""-----BEGIN NEW CERTIFICATE REQUEST-----
+MIICfDCCAWQCAQAwNzEWMBQGA1UEChMNVEVTVFJFTE0uVEVTVDEdMBsGA1UEAxMU
+bWFzdGVyLnRlc3RyZWxtLnRlc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
+AoIBAQC1tciFuG4ri2XUfY/QmyiA9wNECUWe4BvKe6+HgGj70nG1V5IRLFLUDKxk
+txxIw4W75oQyS4M26cHj8PhyIlnFyhahjWccd66Mij9EWjYLprvsZUcV8t6hfQN7
+a4CZxQ1fe2yEmw4tfT5wKFr1trmdTITaUzcs4f0fVzbTLA5Ird84UJEDFLWJIcUu
+T08I0QPoc2Xd3Zou/olSyF8kBem4LheYaAYQGO8k568oVDOoAB8CNIrANe1GwS7U
+dAjCdOKyJba/tYaC8wuXZAtFFrOwUKq7oTWasdC7jctOwSXz8dbKp3DkqrHRHOOV
+ZMD/h6MBdeYRC7qNucBi7kV/vgetAgMBAAGgADANBgkqhkiG9w0BAQsFAAOCAQEA
+LUgNGI2VGZZPqW0ChDnrG/LxrLxpQF3HkuXblfPlMX9/zTKG4DwSYDN/hoKtuCti
+q9qauq3BRoPkN0gcZGplq8inDP1p9UQOBPF1107ZODOt3W1vjBZ6hziZVbo6w5B3
+kJeLinP7TGZ6SjnEamEJT+WX0LkfxGyficNDs5lb0jaRmY/2aqvP3Tmx924JAzfo
+6x673lBidFz1CxaRAxgV7O50jWt4BdvaPVtcG6H1l3GQrzQUD+Zc70QhTI/3eGJg
+rzgBjBS9cdroNHIJt7Z1CWeFNWzgiH367962uxTdcoVy9Tkx5+9On8muHcMYUl1d
+kkE7vpltl6NGh0qqfrm2VA==
+-----END NEW CERTIFICATE REQUEST-----""")
diff --git a/ipatests/test_webui/test_cert.py b/ipatests/test_webui/test_cert.py
index c1a3461ad0..c1b6b5c9f0 100644
--- a/ipatests/test_webui/test_cert.py
+++ b/ipatests/test_webui/test_cert.py
@@ -23,9 +23,56 @@
 
 from ipatests.test_webui.ui_driver import UI_driver
 from ipatests.test_webui.ui_driver import screenshot
+import ipatests.test_webui.data_cert as data_cert
+from datetime import date, timedelta
 import pytest
 
-ENTITY = 'cert'
+
+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"
+INV_DATE = ("invalid '{}': does not match any of accepted formats: "
+            "%Y%m%d%H%M%SZ, %Y-%m-%dT%H:%M:%SZ, %Y-%m-%dT%H:%MZ, "
+            "%Y-%m-%dZ, %Y-%m-%d %H:%M:%SZ, %Y-%m-%d %H:%MZ")
+
+
+def search_pkey(self, pkey):
+    search_field_s = '.search-filter input[name=filter]'
+    self.fill_text(search_field_s, pkey)
+    self.action_button_click('find', parent=None)
+    self.wait_for_request(n=2)
+
+
+def check_option_negative(self, date, option):
+    self.navigate_to_entity(data_cert.ENTITY)
+    self.select('select[name=search_option]', option)
+    search_pkey(self, date)
+    self.assert_last_error_dialog(INV_DATE.format(option))
+    self.close_all_dialogs()
+
+
+def check_space_error(self, string, option):
+    self.navigate_to_entity(data_cert.ENTITY)
+    self.select('select[name=search_option]', option)
+    search_pkey(self, string)
+    self.assert_last_error_dialog(ERR_SPACE.format(option))
+    self.close_all_dialogs()
+
+
+def check_integer(self, string, option):
+    self.navigate_to_entity(data_cert.ENTITY)
+    self.select('select[name=search_option]', option)
+    search_pkey(self, string)
+    self.assert_last_error_dialog(ERR_MUST_INTEGER.format(option))
+    self.close_all_dialogs()
+
+
+def check_minimum_serial(self, serial, option):
+    self.navigate_to_entity(data_cert.ENTITY)
+    self.select('select[name=search_option]', option)
+    search_pkey(self, serial)
+    self.assert_last_error_dialog(LEAST_SERIAL.format(option))
+    self.close_all_dialogs()
 
 
 @pytest.mark.tier1
@@ -45,7 +92,404 @@ def test_read(self):
         Certs don't have standard mod, add and delete methods.
         """
         self.init_app()
-        self.navigate_to_entity(ENTITY)
+        self.navigate_to_entity(data_cert.ENTITY)
         rows = self.get_rows()
         self.navigate_to_row_record(rows[0])
         self.navigate_by_breadcrumb("Certificates")
+
+    @screenshot
+    def test_search_subject(self):
+        """
+        Try to search certificate by subject
+        """
+        self.init_app()
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'subject')
+        search_pkey(self, 'Certificate Authority')
+        rows = self.get_rows()
+        assert len(rows) != 0
+
+        # try to search non-existent subject
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'subject')
+        search_pkey(self, 'nonexistent')
+        rows = self.get_rows()
+        assert len(rows) == 0
+
+        # try to search subject with speacial char
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'subject')
+        search_pkey(self, '<,>.?/')
+        rows = self.get_rows()
+        assert len(rows) == 0
+
+        # try to search subject with leading space
+        check_space_error(self, ' Certificate Authority', 'subject')
+
+        # try to search subject with trailing space
+        check_space_error(self, 'Certificate Authority ', 'subject')
+
+    @screenshot
+    def test_search_revocation_reason(self):
+        """
+        Try to search certificates by revocation reason
+        """
+        self.init_app()
+        self.navigate_to_entity(data_cert.ENTITY)
+
+        # add a new cert
+        self.facet_button_click('request_cert')
+        self.fill_textbox('principal', 'HTTP/master.testrelm.test')
+        self.check_option('add', 'checked')
+        self.fill_textarea('csr', data_cert.CERT_CSR)
+        self.dialog_button_click('issue')
+
+        # revoke added cert
+        rows = self.get_rows()
+        self.navigate_to_row_record(rows[-1])
+        self.action_list_action('revoke_cert', False)
+        self.select('select[name=revocation_reason]', '1')
+        self.dialog_button_click('ok')
+
+        # search cert by revocation reason
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'revocation_reason')
+        search_pkey(self, '1')
+        rows = self.get_rows()
+        assert len(rows) != 0
+
+        # search cert by string
+        check_integer(self, 'nonexistent', 'revocation_reason')
+
+        # search cert by special char
+        check_integer(self, '<,>.?/', 'revocation_reason')
+
+        # search revocation reason negative Number
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'revocation_reason')
+        search_pkey(self, '-1')
+        rows = self.get_rows()
+        assert len(rows) == 0
+
+        # valid revocation reason can be value from 0 to 10
+        # try revocation reason as other than valid value
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'revocation_reason')
+        search_pkey(self, '11')
+        rows = self.get_rows()
+        assert len(rows) == 0
+
+    @screenshot
+    def test_search_minimum_serial(self):
+        """
+        Try to search cert using minimum serial number option
+        """
+        self.init_app()
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'min_serial_number')
+        search_pkey(self, '1')
+        rows = self.get_rows()
+        assert len(rows) != 0
+
+        # try search using string
+        check_integer(self, 'nonexistent', 'min_serial_number')
+
+        # try searching using -1
+        check_minimum_serial(self, '-1', 'min_serial_number')
+
+        # try using higher value than no. of certs present
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'min_serial_number')
+        search_pkey(self, '99')
+        rows = self.get_rows()
+        assert len(rows) == 0
+
+    @screenshot
+    def test_search_maximum_serial(self):
+        """
+        Try to search cert using maximum serial number option
+        """
+        self.init_app()
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'max_serial_number')
+        search_pkey(self, '2')
+        rows = self.get_rows()
+        assert len(rows) == 2
+
+        # try to search using string
+        check_integer(self, 'nonexisting', 'max_serial_number')
+
+        # try to search using -1
+        check_minimum_serial(self, '-1', 'max_serial_number')
+
+    @screenshot
+    def test_search_valid_not_after_from(self):
+        """
+        Try to search cert using valid not after from option
+        """
+        today = date.today()
+        self.init_app()
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'validnotafter_from')
+        search_pkey(self, str(today))
+        rows = self.get_rows()
+        assert len(rows) != 0
+
+        # try to search with string
+        check_option_negative(self, 'nonexistent', 'validnotafter_from')
+
+        # try to search using invalid date
+        check_option_negative(self, '2018-02-30', 'validnotafter_from')
+
+        # try to search using date beyond
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'validnotafter_from')
+        search_pkey(self, str(today + timedelta(weeks=52 * 30)))
+        rows = self.get_rows()
+        assert len(rows) == 0
+
+        # try to search using leading space
+        check_option_negative(self,
+                              ' {}'.format(str(today)),
+                              'validnotafter_from')
+
+        # try to search trailing space
+        check_option_negative(self,
+                              '{} '.format(str(today)),
+                              'validnotafter_from')
+
+    @screenshot
+    def test_search_valid_not_after_to(self):
+        """
+        Try to search cert using valid not after to option
+        """
+        today = date.today()
+        self.init_app()
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'validnotafter_to')
+        search_pkey(self, str(today + timedelta(weeks=52 * 30)))
+        rows = self.get_rows()
+        assert len(rows) != 0
+
+        # try to search with string
+        check_option_negative(self, 'nonexistent', 'validnotafter_to')
+
+        # try to search using invalid date
+        check_option_negative(self, '2018-02-30', 'validnotafter_to')
+
+        # try to search using date ago
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'validnotafter_to')
+        search_pkey(self, str(today - timedelta(weeks=52 * 10)))
+        rows = self.get_rows()
+        assert len(rows) == 0
+
+        # try to search with leading space
+        check_option_negative(self,
+                              ' {}'.format(str(today)),
+                              'validnotafter_to')
+
+        # try to search with trailing space
+        check_option_negative(self,
+                              '{} '.format(str(today)),
+                              'validnotafter_to')
+
+    @screenshot
+    def test_search_valid_not_before_from(self):
+        """
+        Try to search cert using valid not before from option
+        """
+        today = date.today()
+        self.init_app()
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'validnotbefore_from')
+        search_pkey(self, str(today))
+        rows = self.get_rows()
+        assert len(rows) != 0
+
+        # try to search with string
+        check_option_negative(self, 'nonexistent', 'validnotafter_from')
+
+        # try to search using invalid date
+        check_option_negative(self, '2018-02-30', 'validnotafter_from')
+
+        # try to search using current beyond
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'validnotbefore_from')
+        search_pkey(self, str(today + timedelta(weeks=52 * 30)))
+        rows = self.get_rows()
+        assert len(rows) == 0
+
+        # try to search with leading space
+        check_option_negative(self,
+                              ' {}'.format(str(today)),
+                              'validnotafter_from')
+
+        # try to search with trailing space
+        check_option_negative(self,
+                              '{} '.format(str(today)),
+                              'validnotafter_from')
+
+    @screenshot
+    def test_search_valid_not_before_to(self):
+        """
+        Try to search cert using valid not before to option
+        """
+        today = date.today()
+        self.init_app()
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'validnotbefore_to')
+        search_pkey(self, str(today + timedelta(weeks=52 * 30)))
+        rows = self.get_rows()
+        assert len(rows) != 0
+
+        # try to search with string
+        check_option_negative(self, 'nonexistent', 'validnotafter_from')
+
+        # try to search using invalid date
+        check_option_negative(self, '2018-02-30', 'validnotafter_from')
+
+        # try to search using date ago
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'validnotbefore_to')
+        search_pkey(self, str(today - timedelta(weeks=52 * 10)))
+        rows = self.get_rows()
+        assert len(rows) == 0
+
+        # try to search with leading space
+        check_option_negative(self,
+                              ' {}'.format(str(today)),
+                              'validnotafter_from')
+
+        # try to search with trailing space
+        check_option_negative(self,
+                              '{} '.format(str(today)),
+                              'validnotafter_from')
+
+    @screenshot
+    def test_search_issued_on_from(self):
+        """
+        Try to search cert using issued on from option
+        """
+        today = date.today()
+        self.init_app()
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'issuedon_from')
+        search_pkey(self, str(today))
+        rows = self.get_rows()
+        assert len(rows) != 0
+
+        # try to search with string
+        check_option_negative(self, 'nonexistent', 'issuedon_from')
+
+        # try to search using invalid date
+        check_option_negative(self, '2018-02-30', 'issuedon_from')
+
+        # try to search using date beyond
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'issuedon_from')
+        search_pkey(self, str(today + timedelta(weeks=52 * 30)))
+        rows = self.get_rows()
+        assert len(rows) == 0
+
+        # try to search with leading space
+        check_option_negative(self, ' {}'.format(str(today)), 'issuedon_from')
+
+        # try to search with trailing space
+        check_option_negative(self, '{} '.format(str(today)), 'issuedon_from')
+
+    @screenshot
+    def test_search_issued_on_to(self):
+        """
+        Try to search cert using issued on to option
+        """
+        today = date.today()
+        self.init_app()
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'issuedon_to')
+        search_pkey(self, str(today))
+        rows = self.get_rows()
+        assert len(rows) != 0
+
+        # try to search with string
+        check_option_negative(self, 'nonexistent', 'issuedon_to')
+
+        # try to search using invalid date
+        check_option_negative(self, '2018-02-30', 'issuedon_to')
+
+        # try to search using date ago
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'issuedon_to')
+        search_pkey(self, str(today - timedelta(weeks=52 * 10)))
+        rows = self.get_rows()
+        assert len(rows) == 0
+
+        # try to search with leading space
+        check_option_negative(self, ' {}'.format(str(today)), 'issuedon_to')
+
+        # try to search with trailing space
+        check_option_negative(self, '{} '.format(str(today)), 'issuedon_to')
+
+    @screenshot
+    def test_search_revoked_on_from(self):
+        """
+        Try to search cert using revoked on from option
+        """
+        today = date.today()
+        self.init_app()
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'revokedon_from')
+        search_pkey(self, str(today))
+        rows = self.get_rows()
+        assert len(rows) != 0
+
+        # try to search with string
+        check_option_negative(self, 'nonexistent', 'revokedon_from')
+
+        # try to search using invalid date
+        check_option_negative(self, '2018-02-30', 'revokedon_from')
+
+        # try to search using date beyond
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'revokedon_from')
+        search_pkey(self, str(today + timedelta(weeks=52 * 30)))
+        rows = self.get_rows()
+        assert len(rows) == 0
+
+        # try to search with leading space
+        check_option_negative(self, ' {}'.format(str(today)), 'revokedon_from')
+
+        # try to search with trailing space
+        check_option_negative(self, '{} '.format(str(today)), 'revokedon_from')
+
+    @screenshot
+    def test_search_revoked_on_to(self):
+        """
+        Try to search cert using revoked on to option
+        """
+        today = date.today()
+        self.init_app()
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'revokedon_to')
+        search_pkey(self, str(today))
+        rows = self.get_rows()
+        assert len(rows) != 0
+
+        # try to search with string
+        check_option_negative(self, 'nonexistent', 'revokedon_to')
+
+        # try to search using invalid date
+        check_option_negative(self, '2018-02-30', 'revokedon_to')
+
+        # try to search using date ago
+        self.navigate_to_entity(data_cert.ENTITY)
+        self.select('select[name=search_option]', 'revokedon_to')
+        search_pkey(self, str(today - timedelta(weeks=52 * 10)))
+        rows = self.get_rows()
+        assert len(rows) == 0
+
+        # try to search with leading space
+        check_option_negative(self, ' {}'.format(str(today)), 'revokedon_to')
+
+        # try to search with trailing space
+        check_option_negative(self, '{} '.format(str(today)), 'revokedon_to')
_______________________________________________
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/JBMKLNCIVJ5GLAKBZX2Q76BV55GRLA7H/

Reply via email to