Fixing Jenkins job failure 72/133272/3
authorwaqas.ikram <waqas.ikram@est.tech>
Thu, 16 Feb 2023 10:45:56 +0000 (10:45 +0000)
committerwaqas.ikram <waqas.ikram@est.tech>
Thu, 16 Feb 2023 19:35:31 +0000 (19:35 +0000)
Change-Id: I1bfd82b6f58edfd9dd6f9030e86f5519f2f38aea
Issue-ID: INT-2201
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
.gitignore
plans/oom-platform-cert-service/certservice/setup.sh
tests/common.robot
tests/oom-platform-cert-service/certservice/libraries/ArtifactParser.py
tests/oom-platform-cert-service/certservice/libraries/CertClientManager.py
tests/oom-platform-cert-service/certservice/libraries/ResponseParser.py
tests/oom-platform-cert-service/certservice/resources/cert-service-keywords.robot
tests/oom-platform-cert-service/postprocessor/libraries/JksValidator.py
tests/oom-platform-cert-service/postprocessor/libraries/PemTruststoreValidator.py
tests/oom-platform-cert-service/postprocessor/libraries/PostProcessorDockerContainerUtils.py

index de8eea8..bf0a425 100644 (file)
@@ -29,3 +29,4 @@ env.properties
 
 /tests/aaf/certservice/tmp/*
 /tests/oom-platform-cert-service/postprocessor/tmp/*
+.robot3_venv
index 0e2a465..4219bf6 100644 (file)
@@ -38,7 +38,7 @@ pip install -U docker==2.7.0
 #reinstall pyopenssl library
 echo "Reinstall pyopenssl library."
 pip uninstall pyopenssl -y
-pip install pyopenssl==17.5.0
+pip install pyopenssl==23.0.0
 
 #install pyjks for .jks files management
 pip install pyjks
@@ -92,7 +92,7 @@ for i in {1..9}
 do
    OOMCERT_IP=`get-instance-ip.sh oomcert-service`
    RESP_CODE=$(curl -s https://localhost:8443/actuator/health --cacert ./certs/root.crt --cert-type p12 --cert ./certs/certServiceServer-keystore.p12 --pass secret | \
-   python2 -c 'import json,sys;obj=json.load(sys.stdin);print obj["status"]')
+   python3 -c 'import json,sys;obj=json.load(sys.stdin);print (obj["status"])')
    if [[ "$RESP_CODE" == "UP" ]]; then
        echo 'OOM Cert Service is ready'
        export OOMCERT_IP=${OOMCERT_IP}
index f0dea25..8af66a5 100644 (file)
@@ -1,7 +1,6 @@
 #Robot functions that will be shared also with other tests
 *** Settings ***
 Library     OperatingSystem
-Library     HttpLibrary.HTTP
 
 *** Keywords ***
 json_from_file
index bc796ed..35e1101 100644 (file)
@@ -37,7 +37,7 @@ class ArtifactParser:
     return SANS_DELIMITER.join(sans_strings)
 
   def remove_nones_from_dict(self, dictionary):
-    return dict((k, v) for k, v in dictionary.iteritems() if k is not None)
+    return dict((k, v) for k, v in dictionary.items() if k is not None)
 
   def get_list_of_pairs_by_mappings(self, list):
     mappings = self.get_mappings()
index 46d69bb..1c957f1 100644 (file)
@@ -21,6 +21,7 @@ class CertClientManager:
         self.create_mount_dir()
         client = docker.from_env()
         environment = EnvsReader().read_env_list_from_file(path_to_env)
+
         environment.append("REQUEST_URL=" + request_url)
         container = client.containers.run(
             image=client_image,
@@ -38,7 +39,7 @@ class CertClientManager:
     def remove_client_container_and_save_logs(self, container_name, log_file_name):
         client = docker.from_env()
         container = client.containers.get(container_name)
-        text_file = open(ARCHIVES_PATH + "client_container_" + log_file_name + ".log", "w")
+        text_file = open(ARCHIVES_PATH + "client_container_" + log_file_name + ".log", "wb")
         text_file.write(container.logs())
         text_file.close()
         container.remove()
index d4de5f2..7ae833c 100644 (file)
@@ -1,3 +1,8 @@
+import base64
+
+
 def parse_response(response):
-  certChain = response["certificateChain"]
-  return "".join(certChain).encode("base64").replace("\n", "").strip()
+    cert_chain = response["certificateChain"]
+    encoded_bytes = base64.b64encode(bytes("".join(cert_chain), 'utf-8'))
+    base64_str = encoded_bytes.decode('utf-8')
+    return base64_str.replace("\n", "").strip()
index 755cf98..4bda619 100644 (file)
@@ -3,7 +3,6 @@
 Resource          ../../../common.robot
 Resource          ./cert-service-properties.robot
 Library              RequestsLibrary
-Library           HttpLibrary.HTTP
 Library           Collections
 Library           Process
 Library           DateTime
@@ -12,6 +11,7 @@ Library           ../libraries/P12ArtifactsValidator.py  ${MOUNT_PATH}
 Library           ../libraries/JksArtifactsValidator.py  ${MOUNT_PATH}
 Library           ../libraries/PemArtifactsValidator.py  ${MOUNT_PATH}
 Library           ../libraries/ResponseParser.py
+Library           json
 
 *** Keywords ***
 
@@ -30,8 +30,9 @@ Run Healthcheck
 Validate Recieved Response
     [Documentation]  Validare message that has been received
     [Arguments]  ${resp}  ${key}  ${expected_value}
-    ${json}=    Parse Json      ${resp.content}
+    ${json}=    Evaluate     json.loads(r"""${resp.content}""", strict=False)    json
     ${value}=  Get From Dictionary  ${json}  ${key}
+    Log To Console    ${value}
     Should Be Equal As Strings    ${value}    ${expected_value}
 
 Send Get Request And Validate Response
@@ -57,7 +58,7 @@ Send Get Request with Header And Expect Success
 Check Message Recieved On Success
     [Documentation]  Check if correct messsage has been sent on successful request
     [Arguments]  ${content}
-    ${resp_content}=  Parse Json  ${content}
+    ${resp_content}=    Evaluate     json.loads(r"""${content}""", strict=False)    json
     Dictionary Should Contain Key  ${resp_content}  certificateChain
     @{list}=  Get From Dictionary  ${resp_content}  certificateChain
     List Should Contain Certificates  @{list}
@@ -142,7 +143,7 @@ Send Certificate Initialization Request And Return Certificate
     [Arguments]   ${path}  ${csr_file}  ${pk_file}
     [Return]    ${base64Certificate}
     ${resp}=   Send Get Request with Header  ${path}  ${csr_file}  ${pk_file}
-    ${json}=    Parse Json      ${resp.content}
+    ${json}=    Evaluate     json.loads(r"""${resp.content}""", strict=False)    json
     ${base64Certificate}=    Parse Response    ${json}
 
 Send Certificate Update Request And Return Response
index 983f66b..c2262a7 100644 (file)
@@ -4,7 +4,8 @@ import jks
 class JksValidator:
 
   def get_jks_entries(self, jks_path, password_path):
-    store = jks.KeyStore.load(jks_path, open(password_path, 'rb').read())
+    passphrase = open(password_path, 'rb').read().decode("utf-8")
+    store = jks.KeyStore.load(jks_path, passphrase)
     return store.entries
 
   def assert_jks_truststores_equal(self, result_truststore_path, password_path, expected_truststore_path):
index 8dc9623..3c15751 100644 (file)
@@ -16,4 +16,5 @@ class PemTruststoreValidator:
 
 
   def get_list_of_pem_certificates(self, path):
-    return re.findall(BEGIN_CERT + '(.+?)' + END_CERT, open(path, 'rb').read(), re.DOTALL)
+    content = open(path, 'rb').read().decode("utf-8")
+    return re.findall(BEGIN_CERT + '(.+?)' + END_CERT, content, re.DOTALL)
index e0563b3..fb5d07c 100644 (file)
@@ -40,7 +40,7 @@ class PostProcessorDockerContainerUtils:
   def remove_container_and_save_logs(self, container_name, log_file_name):
     client = docker.from_env()
     container = client.containers.get(container_name)
-    text_file = open(ARCHIVES_PATH + "certservice_postprocessor_container_" + log_file_name + ".log", "w")
+    text_file = open(ARCHIVES_PATH + "certservice_postprocessor_container_" + log_file_name + ".log", "wb")
     text_file.write(container.logs())
     text_file.close()
     container.remove()