3 Resource ../../../common.robot
4 Resource ./cert-service-properties.robot
5 Library RequestsLibrary
6 Library HttpLibrary.HTTP
10 Library ../libraries/CertClientManager.py ${MOUNT_PATH} ${TRUSTSTORE_PATH}
11 Library ../libraries/P12ArtifactsValidator.py ${MOUNT_PATH}
12 Library ../libraries/JksArtifactsValidator.py ${MOUNT_PATH}
13 Library ../libraries/PemArtifactsValidator.py ${MOUNT_PATH}
14 Library ../libraries/ResponseParser.py
19 [Documentation] Create all required sessions
20 ${certs}= Create List ${CERTSERVICE_SERVER_CRT} ${CERTSERVICE_SERVER_KEY}
21 Create Client Cert Session alias ${OOMCERT_URL} client_certs=${certs} verify=${ROOTCA}
22 Set Suite Variable ${https_valid_cert_session} alias
25 [Documentation] Run Healthcheck
26 ${resp}= Get Request ${https_valid_cert_session} /actuator/health
27 Should Be Equal As Strings ${resp.status_code} 200
28 Validate Recieved Response ${resp} status UP
30 Validate Recieved Response
31 [Documentation] Validare message that has been received
32 [Arguments] ${resp} ${key} ${expected_value}
33 ${json}= Parse Json ${resp.content}
34 ${value}= Get From Dictionary ${json} ${key}
35 Should Be Equal As Strings ${value} ${expected_value}
37 Send Get Request And Validate Response
38 [Documentation] Send request to passed url and validate received response
39 [Arguments] ${path} ${resp_code}
40 ${resp}= Get Request ${https_valid_cert_session} ${path}
41 Should Be Equal As Strings ${resp.status_code} ${resp_code}
43 Send Get Request with Header
44 [Documentation] Send request to passed url
45 [Arguments] ${path} ${csr_file} ${pk_file}
47 ${headers}= Create Header with CSR and PK ${csr_file} ${pk_file}
48 ${resp}= Get Request ${https_valid_cert_session} ${path} headers=${headers}
50 Send Get Request with Header And Expect Success
51 [Documentation] Send request to passed url and validate received response
52 [Arguments] ${path} ${csr_file} ${pk_file}
53 ${resp}= Send Get Request with Header ${path} ${csr_file} ${pk_file}
54 Should Be Equal As Strings ${resp.status_code} 200
55 Check Message Recieved On Success ${resp.content}
57 Check Message Recieved On Success
58 [Documentation] Check if correct messsage has been sent on successful request
59 [Arguments] ${content}
60 ${resp_content}= Parse Json ${content}
61 Dictionary Should Contain Key ${resp_content} certificateChain
62 @{list}= Get From Dictionary ${resp_content} certificateChain
63 List Should Contain Certificates @{list}
64 Dictionary Should Contain Key ${resp_content} trustedCertificates
66 List Should Contain Certificates
67 [Documentation] Verify if list contains certificates
69 FOR ${content} IN @{list}
70 Should Contain ${content} BEGIN CERTIFICATE
71 Should Contain ${content} END CERTIFICATE
74 Send Get Request with Header And Expect Error
75 [Documentation] Send request to passed url and validate received response
76 [Arguments] ${path} ${csr_file} ${pk_file} ${resp_code}
77 ${resp}= Send Get Request with Header ${path} ${csr_file} ${pk_file}
78 Should Be Equal As Strings ${resp.status_code} ${resp_code}
80 Create Header with CSR and PK
81 [Documentation] Create header with CSR and PK
82 [Arguments] ${csr_file} ${pk_file}
84 ${csr}= Get Data From File ${csr_file}
85 ${pk}= Get Data From File ${pk_file}
86 ${headers}= Create Dictionary CSR=${csr} PK=${pk}
88 Send Post Request And Validate Response
89 [Documentation] Send request to passed url and validate received response
90 [Arguments] ${path} ${resp_code}
91 ${resp}= Post Request ${https_valid_cert_session} ${path}
92 Should Be Equal As Strings ${resp.status_code} ${resp_code}
94 Send Initialization Request And Key Update Request And Expect Success
95 [Documentation] Send initialization request and then key update request to passed urls and validate received response
96 [Arguments] ${path} ${update_path} ${csr_file} ${pk_file} ${update_csr_file} ${update_pk_file}
97 ${start_time}= Get Current Timestamp For Docker Log
98 Send Initialization Request And Update Request And Check Status Code ${path} ${update_path} ${csr_file} ${pk_file}
99 ... ${update_csr_file} ${update_pk_file} 200
100 Verify Key Update Request Sent By Cert Service ${start_time}
102 Send Initialization Request And Certification Request And Expect Success
103 [Documentation] Send initialization request and then certification request to passed urls and validate received response
104 [Arguments] ${path} ${update_path} ${csr_file} ${pk_file} ${update_csr_file} ${update_pk_file}
105 ${start_time}= Get Current Timestamp For Docker Log
106 Send Initialization Request And Update Request And Check Status Code ${path} ${update_path} ${csr_file} ${pk_file}
107 ... ${update_csr_file} ${update_pk_file} 200
108 Verify Certification Request Sent By Cert Service ${start_time}
110 Send Initialization Request And Key Update Request With Wrong Old Private Key And Expect Error
111 [Documentation] Send initialization request and then key update request to passed urls and expect status code 500
112 [Arguments] ${path} ${update_path} ${csr_file} ${pk_file} ${update_csr_file} ${update_pk_file} ${wrong_old_pk_file}
113 ${start_time}= Get Current Timestamp For Docker Log
114 ${old_cert}= Send Certificate Initialization Request And Return Certificate ${path} ${csr_file} ${pk_file}
115 ${resp}= Send Certificate Update Request And Return Response ${update_path} ${update_csr_file} ${update_pk_file} ${old_cert} ${wrong_old_pk_file}
116 Should Be Equal As Strings ${resp.status_code} 500
117 Verify Key Update Request Sent By Cert Service ${start_time}
119 Send Update Request With Wrong Header And Expect Error
120 [Documentation] Send update request to passed url and expect wrong header response
121 [Arguments] ${update_path} ${update_csr_file} ${update_pk_file} ${old_cert_base64} ${old_pk_file}
122 ${resp}= Send Certificate Update Request And Return Response ${update_path} ${update_csr_file} ${update_pk_file} ${old_cert_base64} ${old_pk_file}
123 Should Be Equal As Strings ${resp.status_code} 400
125 Send Update Request With Missing Header And Expect Error
126 [Documentation] Send update request to passed url and expect wrong header response
127 [Arguments] ${update_path} ${update_csr_file} ${update_pk_file} ${old_cert_base64} ${old_pk_file} ${header_to_remove}
128 ${headers}= Create Header for Certificate Update ${update_csr_file} ${update_pk_file} ${old_cert_base64} ${old_pk_file}
129 Remove From Dictionary ${headers} ${header_to_remove}
130 ${resp}= Get Request ${https_valid_cert_session} ${update_path} headers=${headers}
131 Should Be Equal As Strings ${resp.status_code} 400
133 Send Initialization Request And Update Request And Check Status Code
134 [Documentation] Send certificate update request and check status code
135 [Arguments] ${path} ${update_path} ${csr_file} ${pk_file} ${update_csr_file} ${update_pk_file} ${expected_status_code}
136 ${old_cert}= Send Certificate Initialization Request And Return Certificate ${path} ${csr_file} ${pk_file}
137 ${resp}= Send Certificate Update Request And Return Response ${update_path} ${update_csr_file} ${update_pk_file} ${old_cert} ${pk_file}
138 Should Be Equal As Strings ${resp.status_code} ${expected_status_code}
140 Send Certificate Initialization Request And Return Certificate
141 [Documentation] Send certificate initialization request and return base64 encoded certificate from response
142 [Arguments] ${path} ${csr_file} ${pk_file}
143 [Return] ${base64Certificate}
144 ${resp}= Send Get Request with Header ${path} ${csr_file} ${pk_file}
145 ${json}= Parse Json ${resp.content}
146 ${base64Certificate}= Parse Response ${json}
148 Send Certificate Update Request And Return Response
149 [Documentation] Send certificate update request and return response code
150 [Arguments] ${path} ${csr_file} ${pk_file} ${old_cert} ${old_pk_file}
152 ${headers}= Create Header for Certificate Update ${csr_file} ${pk_file} ${old_cert} ${old_pk_file}
153 ${resp}= Get Request ${https_valid_cert_session} ${path} headers=${headers}
155 Create Header for Certificate Update
156 [Documentation] Create header with CSR and PK, OLD_CERT and OLD_PK
157 [Arguments] ${csr_file} ${pk_file} ${old_cert} ${old_pk_file}
159 ${csr}= Get Data From File ${csr_file}
160 ${pk}= Get Data From File ${pk_file}
161 ${old_pk}= Get Data From File ${old_pk_file}
162 ${headers}= Create Dictionary CSR=${csr} PK=${pk} OLD_CERT=${old_cert} OLD_PK=${old_pk}
164 Verify Key Update Request Sent By Cert Service
165 [Documentation] Verify that request was key update request
166 [Arguments] ${start_time}
167 ${result}= Run Process docker logs oomcert-service --since ${start_time} shell=yes
168 Should Contain ${result.stdout} ${EXPECTED_KUR_LOG}
170 Verify Certification Request Sent By Cert Service
171 [Documentation] Verify that request was certification request
172 [Arguments] ${start_time}
173 ${result}= Run Process docker logs oomcert-service --since ${start_time} shell=yes
174 Should Contain ${result.stdout} ${EXPECTED_CR_LOG}
176 Get Current Timestamp For Docker Log
177 [Documentation] Gets current timestamp valid for docker
178 [Return] ${timestamp}
179 ${timestamp}= Get Current Date result_format=%Y-%m-%dT%H:%M:%S.%f
181 Run Cert Service Client And Validate PKCS12 File Creation And Client Exit Code
182 [Documentation] Run Cert Service Client Container And Validate Exit Code
183 [Arguments] ${env_file} ${expected_exit_code}
184 [Teardown] Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} positive_path
185 ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK}
186 ${can_open}= Can Open Keystore And Truststore With Pass
187 Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return: ${exitcode} exit code, but expected: ${expected_exit_code}
188 Should Be True ${can_open} Cannot Open Keystore/TrustStore by passpshase
190 Run Cert Service Client And Validate JKS File Creation And Client Exit Code
191 [Documentation] Run Cert Service Client Container And Validate Exit Code
192 [Arguments] ${env_file} ${expected_exit_code}
193 [Teardown] Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} positive_path
194 ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK}
195 ${can_open}= Can Open Keystore And Truststore With Pass Jks
196 Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return: ${exitcode} exit code, but expected: ${expected_exit_code}
197 Should Be True ${can_open} Cannot Open Keystore/TrustStore by passpshase
199 Run Cert Service Client And Validate PKCS12 Files Contain Expected Data
200 [Documentation] Run Cert Service Client Container And Validate PKCS12 Files Contain Expected Data
201 [Arguments] ${env_file} ${expected_exit_code}
202 [Teardown] Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} positive_path_with_data
203 ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK}
204 ${data} ${isEqual}= Get And Compare Data P12 ${env_file}
205 Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return: ${exitcode} exit code, but expected: ${expected_exit_code}
206 Should Be True ${isEqual} Keystore doesn't contain ${data.expectedData}. Actual data is: ${data.actualData}
208 Run Cert Service Client And Validate JKS Files Contain Expected Data
209 [Documentation] Run Cert Service Client Container And Validate JKS Files Contain Expected Data
210 [Arguments] ${env_file} ${expected_exit_code}
211 [Teardown] Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} positive_path_with_data
212 ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK}
213 ${data} ${isEqual}= Get And Compare Data Jks ${env_file}
214 Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return: ${exitcode} exit code, but expected: ${expected_exit_code}
215 Should Be True ${isEqual} Keystore doesn't contain ${data.expectedData}. Actual data is: ${data.actualData}
217 Run Cert Service Client And Validate PEM Files Contain Expected Data
218 [Documentation] Run Cert Service Client Container And Validate PEM Files Contain Expected Data
219 [Arguments] ${env_file} ${expected_exit_code}
220 [Teardown] Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} positive_path_with_data
221 ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK}
222 ${existNotEmpty}= Artifacts Exist And Are Not Empty
223 ${data} ${isEqual}= Get And Compare Data Pem ${env_file}
224 Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return: ${exitcode} exit code, but expected: ${expected_exit_code}
225 Should Be True ${existNotEmpty} PEM artifacts not created properly
226 Should Be True ${isEqual} Keystore doesn't contain ${data.expectedData}. Actual data is: ${data.actualData}
228 Run Cert Service Client And Validate Http Response Code And Client Exit Code
229 [Documentation] Run Cert Service Client Container And Validate Exit Code
230 [Arguments] ${env_file} ${expected_api_response_code} ${expected_exit_code}
231 ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK}
232 ${can_find_API_response}= Can Find Api Response In Logs ${CLIENT_CONTAINER_NAME}
233 ${api_response_code}= Get Api Response From Logs ${CLIENT_CONTAINER_NAME}
234 [Teardown] Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} negative_path
235 Should Be True ${can_find_API_response} Cannot Find API response in logs
236 Should Be Equal As Strings ${api_response_code} ${expected_api_response_code} API return ${api_response_code} but expected: ${expected_api_response_code}
237 Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return unexpected exit code return: ${exitcode} , but expected: ${expected_exit_code}
239 Run Cert Service Client And Validate Client Exit Code
240 [Documentation] Run Cert Service Client Container And Validate Exit Code
241 [Arguments] ${env_file} ${expected_exit_code}
242 [Teardown] Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} negative_path
243 ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK}
244 Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return unexpected exit code return: ${exitcode} , but expected: ${expected_exit_code}