URL: https://github.com/freeipa/freeipa/pull/2214
Author: mrizwan93
 Title: #2214: Genrate CSR dynamically for UI tests
Action: opened

PR body:
"""
There were hardcoded csr in test_cert.py. 'host_csr_path'
and 'service_csr_path' needs to be generated before executing
UI tests. This fix removes the hardcoded values as well as need
of generating csr before executing UI testsuit.

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/2214/head:pr2214
git checkout pr2214
From 3b6d3bb2ee554c8506887c9e0aaca4d360f8430d Mon Sep 17 00:00:00 2001
From: Mohammad Rizwan Yusuf <myu...@redhat.com>
Date: Mon, 6 Aug 2018 19:11:46 +0530
Subject: [PATCH] Genrate CSR dynamically for UI tests

There were hardcoded csr in test_cert.py. 'host_csr_path'
and 'service_csr_path' needs to be generated before executing
UI tests. This fix removes the hardcoded values as well as need
of generating csr before executing UI testsuit.

Signed-off-by: Mohammad Rizwan Yusuf <myu...@redhat.com>
---
 ipatests/test_webui/test_cert.py    | 24 ++++++------------------
 ipatests/test_webui/test_host.py    |  3 ++-
 ipatests/test_webui/test_service.py |  2 +-
 ipatests/test_webui/test_user.py    |  3 ++-
 ipatests/test_webui/ui_driver.py    | 10 ++++++++++
 5 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/ipatests/test_webui/test_cert.py b/ipatests/test_webui/test_cert.py
index 1cb8108f3a..a101af74b1 100644
--- a/ipatests/test_webui/test_cert.py
+++ b/ipatests/test_webui/test_cert.py
@@ -25,26 +25,10 @@
 from ipatests.test_webui.ui_driver import screenshot
 from datetime import date, timedelta
 import pytest
+from tempfile import NamedTemporaryFile
 
 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,11 @@ 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)
+        tf = NamedTemporaryFile()
+        csr_file = tf.name
+        self.generate_csr(hostname, csr_file)
+        csr_contents = open(csr_file, 'r').read()
+        record = add_cert(self, 'HTTP/{}'.format(hostname), csr_contents)
 
         # revoke added cert
         revoke_cert(self, record, '1')
diff --git a/ipatests/test_webui/test_host.py b/ipatests/test_webui/test_host.py
index 8f12b71654..b6b456cfdc 100644
--- a/ipatests/test_webui/test_host.py
+++ b/ipatests/test_webui/test_host.py
@@ -160,7 +160,8 @@ def test_certificates(self):
             self.skip('CSR file is not configured')
 
         self.init_app()
-        # ENHANCEMENT: generate csr dynamically
+        hostname = self.config.get('ipa_server')
+        self.generate_csr(hostname, csr_path)
         csr = self.load_file(csr_path)
         cert_widget_sel = "div.certificate-widget"
 
diff --git a/ipatests/test_webui/test_service.py b/ipatests/test_webui/test_service.py
index 74cca36be4..1be1875cb4 100644
--- a/ipatests/test_webui/test_service.py
+++ b/ipatests/test_webui/test_service.py
@@ -56,7 +56,7 @@ def prep_data(self):
         }
 
     def load_file(self, path):
-        # ENHANCEMENT: generate csr dynamically
+        self.generate_csr(hostname, path)
         with open(path, 'r') as file_d:
             content = file_d.read()
         return content
diff --git a/ipatests/test_webui/test_user.py b/ipatests/test_webui/test_user.py
index 0529111537..bba9a49537 100644
--- a/ipatests/test_webui/test_user.py
+++ b/ipatests/test_webui/test_user.py
@@ -232,7 +232,8 @@ def test_certificates(self):
             self.skip('CSR file is not configured')
 
         self.init_app()
-        # ENHANCEMENT: generate csr dynamically
+        hostname = self.config.get('ipa_server')
+        self.generate_csr(hostname, csr_path)
         csr = self.load_file(csr_path)
         cert_widget_sel = "div.certificate-widget"
 
diff --git a/ipatests/test_webui/ui_driver.py b/ipatests/test_webui/ui_driver.py
index 76db402c60..87689bcb19 100644
--- a/ipatests/test_webui/ui_driver.py
+++ b/ipatests/test_webui/ui_driver.py
@@ -28,6 +28,7 @@
 import time
 import re
 import os
+import subprocess
 from functools import wraps
 import unittest
 import paramiko
@@ -174,6 +175,15 @@ def load_config(self):
         if 'type' not in c:
             c['type'] = DEFAULT_TYPE
 
+    def generate_csr(self, cn, csr_file):
+        """ generate a csr with cn and store in csr_file"""
+        cmd_arg = ["openssl", "req", "-new", "-passout", 'pass:"Secret123"',
+                   "-subj", "/CN={}".format(cn), "-out", csr_file,
+                   "-sha512", "-newkey", "rsa:2048"]
+        cmd = subprocess.Popen(cmd_arg)
+        cmd.communicate()
+        assert cmd.returncode == 0
+
     def get_driver(self):
         """
         Get WebDriver according to configuration
_______________________________________________
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/ONJ6EO3UHUFL4LHPVRSQFM5PS2CWDMQQ/

Reply via email to