Aleksandra Maciaga | 6def597 | 2020-02-20 09:42:03 +0100 | [diff] [blame] | 1 | *** Settings *** |
| 2 | |
Joanna Jeremicz | 9c14f19 | 2020-03-19 14:51:51 +0100 | [diff] [blame] | 3 | Resource ../../../common.robot |
| 4 | Resource ./cert-service-properties.robot |
Aleksandra Maciaga | 6def597 | 2020-02-20 09:42:03 +0100 | [diff] [blame] | 5 | Library RequestsLibrary |
| 6 | Library HttpLibrary.HTTP |
| 7 | Library Collections |
Aleksandra Maciaga | 13b7d05 | 2020-03-26 17:28:47 +0100 | [diff] [blame] | 8 | Library ../libraries/CertClientManager.py ${MOUNT_PATH} ${TRUSTSTORE_PATH} |
Joanna Jeremicz | 9c14f19 | 2020-03-19 14:51:51 +0100 | [diff] [blame] | 9 | Library ../libraries/JksFilesValidator.py ${MOUNT_PATH} |
Aleksandra Maciaga | 6def597 | 2020-02-20 09:42:03 +0100 | [diff] [blame] | 10 | |
| 11 | *** Keywords *** |
| 12 | |
| 13 | Create sessions |
| 14 | [Documentation] Create all required sessions |
Aleksandra Maciaga | 13b7d05 | 2020-03-26 17:28:47 +0100 | [diff] [blame] | 15 | ${certs}= Create List ${CERTSERVICE_SERVER_CRT} ${CERTSERVICE_SERVER_KEY} |
| 16 | Create Client Cert Session alias ${AAFCERT_URL} client_certs=${certs} verify=${ROOTCA} |
| 17 | Set Suite Variable ${https_valid_cert_session} alias |
Aleksandra Maciaga | 6def597 | 2020-02-20 09:42:03 +0100 | [diff] [blame] | 18 | |
| 19 | Run Healthcheck |
| 20 | [Documentation] Run Healthcheck |
Aleksandra Maciaga | 13b7d05 | 2020-03-26 17:28:47 +0100 | [diff] [blame] | 21 | ${resp}= Get Request ${https_valid_cert_session} /actuator/health |
Aleksandra Maciaga | 6def597 | 2020-02-20 09:42:03 +0100 | [diff] [blame] | 22 | Should Be Equal As Strings ${resp.status_code} 200 |
| 23 | Validate Recieved Response ${resp} status UP |
| 24 | |
Aleksandra Maciaga | 6def597 | 2020-02-20 09:42:03 +0100 | [diff] [blame] | 25 | Validate Recieved Response |
| 26 | [Documentation] Validare message that has been received |
| 27 | [Arguments] ${resp} ${key} ${expected_value} |
| 28 | ${json}= Parse Json ${resp.content} |
Aleksandra Maciaga | 8d762b1 | 2020-02-24 14:24:42 +0100 | [diff] [blame] | 29 | ${value}= Get From Dictionary ${json} ${key} |
| 30 | Should Be Equal As Strings ${value} ${expected_value} |
| 31 | |
| 32 | Send Get Request And Validate Response |
| 33 | [Documentation] Send request to passed url and validate received response |
| 34 | [Arguments] ${path} ${resp_code} |
Aleksandra Maciaga | 13b7d05 | 2020-03-26 17:28:47 +0100 | [diff] [blame] | 35 | ${resp}= Get Request ${https_valid_cert_session} ${path} |
Aleksandra Maciaga | 8d762b1 | 2020-02-24 14:24:42 +0100 | [diff] [blame] | 36 | Should Be Equal As Strings ${resp.status_code} ${resp_code} |
| 37 | |
Aleksandra Maciaga | f630068 | 2020-03-04 17:11:30 +0100 | [diff] [blame] | 38 | Send Get Request with Header |
| 39 | [Documentation] Send request to passed url |
| 40 | [Arguments] ${path} ${csr_file} ${pk_file} |
| 41 | [Return] ${resp} |
Aleksandra Maciaga | 8d762b1 | 2020-02-24 14:24:42 +0100 | [diff] [blame] | 42 | ${headers}= Create Header with CSR and PK ${csr_file} ${pk_file} |
Aleksandra Maciaga | 13b7d05 | 2020-03-26 17:28:47 +0100 | [diff] [blame] | 43 | ${resp}= Get Request ${https_valid_cert_session} ${path} headers=${headers} |
Aleksandra Maciaga | f630068 | 2020-03-04 17:11:30 +0100 | [diff] [blame] | 44 | |
| 45 | Send Get Request with Header And Expect Success |
| 46 | [Documentation] Send request to passed url and validate received response |
| 47 | [Arguments] ${path} ${csr_file} ${pk_file} |
| 48 | ${resp}= Send Get Request with Header ${path} ${csr_file} ${pk_file} |
| 49 | Should Be Equal As Strings ${resp.status_code} 200 |
| 50 | Check Message Recieved On Success ${resp.content} |
| 51 | |
| 52 | Check Message Recieved On Success |
| 53 | [Documentation] Check if correct messsage has been sent on successful request |
| 54 | [Arguments] ${content} |
| 55 | ${resp_content}= Parse Json ${content} |
| 56 | Dictionary Should Contain Key ${resp_content} certificateChain |
| 57 | @{list}= Get From Dictionary ${resp_content} certificateChain |
| 58 | List Should Contain Certificates @{list} |
| 59 | Dictionary Should Contain Key ${resp_content} trustedCertificates |
| 60 | |
| 61 | List Should Contain Certificates |
| 62 | [Documentation] Verify if list contains certificates |
| 63 | [Arguments] @{list} |
| 64 | :FOR ${content} IN @{list} |
| 65 | \ Should Contain ${content} BEGIN CERTIFICATE |
| 66 | \ Should Contain ${content} END CERTIFICATE |
| 67 | |
| 68 | Send Get Request with Header And Expect Error |
| 69 | [Documentation] Send request to passed url and validate received response |
| 70 | [Arguments] ${path} ${csr_file} ${pk_file} ${resp_code} |
| 71 | ${resp}= Send Get Request with Header ${path} ${csr_file} ${pk_file} |
Aleksandra Maciaga | 8d762b1 | 2020-02-24 14:24:42 +0100 | [diff] [blame] | 72 | Should Be Equal As Strings ${resp.status_code} ${resp_code} |
| 73 | |
| 74 | Create Header with CSR and PK |
| 75 | [Documentation] Create header with CSR and PK |
| 76 | [Arguments] ${csr_file} ${pk_file} |
| 77 | [Return] ${headers} |
| 78 | ${csr}= Get Data From File ${csr_file} |
| 79 | ${pk}= Get Data From File ${pk_file} |
| 80 | ${headers}= Create Dictionary CSR=${csr} PK=${pk} |
| 81 | |
| 82 | Send Post Request And Validate Response |
| 83 | [Documentation] Send request to passed url and validate received response |
| 84 | [Arguments] ${path} ${resp_code} |
Aleksandra Maciaga | 13b7d05 | 2020-03-26 17:28:47 +0100 | [diff] [blame] | 85 | ${resp}= Post Request ${https_valid_cert_session} ${path} |
Aleksandra Maciaga | 8d762b1 | 2020-02-24 14:24:42 +0100 | [diff] [blame] | 86 | Should Be Equal As Strings ${resp.status_code} ${resp_code} |
Tomasz Wrobel | 75573b0 | 2020-03-05 16:43:50 +0100 | [diff] [blame] | 87 | |
Tomasz Wrobel | 6ed06d5 | 2020-03-11 15:31:10 +0100 | [diff] [blame] | 88 | Run Cert Service Client And Validate JKS File Creation And Client Exit Code |
Tomasz Wrobel | 75573b0 | 2020-03-05 16:43:50 +0100 | [diff] [blame] | 89 | [Documentation] Run Cert Service Client Container And Validate Exit Code |
Tomasz Wrobel | 6ed06d5 | 2020-03-11 15:31:10 +0100 | [diff] [blame] | 90 | [Arguments] ${env_file} ${expected_exit_code} |
kjaniak | 25fac3a | 2020-03-18 13:01:36 +0100 | [diff] [blame] | 91 | ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK} |
Remigiusz Janeczek | ed0f3be | 2020-03-19 14:20:22 +0100 | [diff] [blame] | 92 | ${can_open}= Can Open Keystore And Truststore With Pass |
Tomasz Wrobel | 6ed06d5 | 2020-03-11 15:31:10 +0100 | [diff] [blame] | 93 | Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} positive_path |
| 94 | Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return: ${exitcode} exit code, but expected: ${expected_exit_code} |
| 95 | Should Be True ${can_open} Cannot Open Keystore/TrustStore by passpshase |
| 96 | |
Joanna Jeremicz | 9c14f19 | 2020-03-19 14:51:51 +0100 | [diff] [blame] | 97 | Run Cert Service Client And Validate JKS Files Contain Expected Data |
| 98 | [Documentation] Run Cert Service Client Container And Validate JKS Files Contain Expected Data |
| 99 | [Arguments] ${env_file} ${expected_exit_code} |
| 100 | ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK} |
| 101 | ${data} ${isEqual}= Get And Compare Data ${env_file} |
| 102 | Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} positive_path_with_data |
| 103 | Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return: ${exitcode} exit code, but expected: ${expected_exit_code} |
| 104 | Should Be True ${isEqual} Keystore doesn't contain ${data.expectedData}. Actual data is: ${data.actualData} |
| 105 | |
Tomasz Wrobel | 6ed06d5 | 2020-03-11 15:31:10 +0100 | [diff] [blame] | 106 | Run Cert Service Client And Validate Http Response Code And Client Exit Code |
| 107 | [Documentation] Run Cert Service Client Container And Validate Exit Code |
| 108 | [Arguments] ${env_file} ${expected_api_response_code} ${expected_exit_code} |
kjaniak | 25fac3a | 2020-03-18 13:01:36 +0100 | [diff] [blame] | 109 | ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK} |
Tomasz Wrobel | 6ed06d5 | 2020-03-11 15:31:10 +0100 | [diff] [blame] | 110 | ${can_find_API_response}= Can Find Api Response In Logs ${CLIENT_CONTAINER_NAME} |
| 111 | ${api_response_code}= Get Api Response From Logs ${CLIENT_CONTAINER_NAME} |
| 112 | Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} negative_path |
| 113 | Should Be True ${can_find_API_response} Cannot Find API response in logs |
| 114 | Should Be Equal As Strings ${api_response_code} ${expected_api_response_code} API return ${api_response_code} but expected: ${expected_api_response_code} |
| 115 | Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return unexpected exit code return: ${exitcode} , but expected: ${expected_exit_code} |