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