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 Update Request And Check Status Code
111 [Documentation] Send certificate update request and check status code
112 [Arguments] ${path} ${update_path} ${csr_file} ${pk_file} ${update_csr_file} ${update_pk_file} ${expected_status_code}
113 ${old_cert}= Send Certificate Initialization Request And Return Certificate ${path} ${csr_file} ${pk_file}
114 ${resp}= Send Certificate Update Request And Return Response ${update_path} ${update_csr_file} ${update_pk_file} ${old_cert} ${pk_file}
115 Should Be Equal As Strings ${resp.status_code} ${expected_status_code}
117 Send Certificate Initialization Request And Return Certificate
118 [Documentation] Send certificate initialization request and return base64 encoded certificate from response
119 [Arguments] ${path} ${csr_file} ${pk_file}
120 [Return] ${base64Certificate}
121 ${resp}= Send Get Request with Header ${path} ${csr_file} ${pk_file}
122 ${json}= Parse Json ${resp.content}
123 ${base64Certificate}= Parse Response ${json}
125 Send Certificate Update Request And Return Response
126 [Documentation] Send certificate update request and return response code
127 [Arguments] ${path} ${csr_file} ${pk_file} ${old_cert} ${old_pk_file}
129 ${headers}= Create Header for Certificate Update ${csr_file} ${pk_file} ${old_cert} ${old_pk_file}
130 ${resp}= Get Request ${https_valid_cert_session} ${path} headers=${headers}
132 Create Header for Certificate Update
133 [Documentation] Create header with CSR and PK, OLD_CERT and OLD_PK
134 [Arguments] ${csr_file} ${pk_file} ${old_cert} ${old_pk_file}
136 ${csr}= Get Data From File ${csr_file}
137 ${pk}= Get Data From File ${pk_file}
138 ${old_pk}= Get Data From File ${old_pk_file}
139 ${headers}= Create Dictionary CSR=${csr} PK=${pk} OLD_CERT=${old_cert} OLD_PK=${old_pk}
141 Verify Key Update Request Sent By Cert Service
142 [Documentation] Verify that request was key update request
143 [Arguments] ${start_time}
144 ${result}= Run Process docker logs oomcert-service --since ${start_time} shell=yes
145 Should Contain ${result.stdout} ${EXPECTED_KUR_LOG}
147 Verify Certification Request Sent By Cert Service
148 [Documentation] Verify that request was certification request
149 [Arguments] ${start_time}
150 ${result}= Run Process docker logs oomcert-service --since ${start_time} shell=yes
151 Should Contain ${result.stdout} ${EXPECTED_CR_LOG}
153 Get Current Timestamp For Docker Log
154 [Documentation] Gets current timestamp valid for docker
155 [Return] ${timestamp}
156 ${timestamp}= Get Current Date result_format=%Y-%m-%dT%H:%M:%S.%f
158 Run Cert Service Client And Validate PKCS12 File Creation And Client Exit Code
159 [Documentation] Run Cert Service Client Container And Validate Exit Code
160 [Arguments] ${env_file} ${expected_exit_code}
161 [Teardown] Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} positive_path
162 ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK}
163 ${can_open}= Can Open Keystore And Truststore With Pass
164 Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return: ${exitcode} exit code, but expected: ${expected_exit_code}
165 Should Be True ${can_open} Cannot Open Keystore/TrustStore by passpshase
167 Run Cert Service Client And Validate JKS File Creation And Client Exit Code
168 [Documentation] Run Cert Service Client Container And Validate Exit Code
169 [Arguments] ${env_file} ${expected_exit_code}
170 [Teardown] Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} positive_path
171 ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK}
172 ${can_open}= Can Open Keystore And Truststore With Pass Jks
173 Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return: ${exitcode} exit code, but expected: ${expected_exit_code}
174 Should Be True ${can_open} Cannot Open Keystore/TrustStore by passpshase
176 Run Cert Service Client And Validate PKCS12 Files Contain Expected Data
177 [Documentation] Run Cert Service Client Container And Validate PKCS12 Files Contain Expected Data
178 [Arguments] ${env_file} ${expected_exit_code}
179 [Teardown] Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} positive_path_with_data
180 ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK}
181 ${data} ${isEqual}= Get And Compare Data P12 ${env_file}
182 Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return: ${exitcode} exit code, but expected: ${expected_exit_code}
183 Should Be True ${isEqual} Keystore doesn't contain ${data.expectedData}. Actual data is: ${data.actualData}
185 Run Cert Service Client And Validate JKS Files Contain Expected Data
186 [Documentation] Run Cert Service Client Container And Validate JKS Files Contain Expected Data
187 [Arguments] ${env_file} ${expected_exit_code}
188 [Teardown] Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} positive_path_with_data
189 ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK}
190 ${data} ${isEqual}= Get And Compare Data Jks ${env_file}
191 Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return: ${exitcode} exit code, but expected: ${expected_exit_code}
192 Should Be True ${isEqual} Keystore doesn't contain ${data.expectedData}. Actual data is: ${data.actualData}
194 Run Cert Service Client And Validate PEM Files Contain Expected Data
195 [Documentation] Run Cert Service Client Container And Validate PEM Files Contain Expected Data
196 [Arguments] ${env_file} ${expected_exit_code}
197 [Teardown] Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} positive_path_with_data
198 ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK}
199 ${existNotEmpty}= Artifacts Exist And Are Not Empty
200 ${data} ${isEqual}= Get And Compare Data Pem ${env_file}
201 Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return: ${exitcode} exit code, but expected: ${expected_exit_code}
202 Should Be True ${existNotEmpty} PEM artifacts not created properly
203 Should Be True ${isEqual} Keystore doesn't contain ${data.expectedData}. Actual data is: ${data.actualData}
205 Run Cert Service Client And Validate Http Response Code And Client Exit Code
206 [Documentation] Run Cert Service Client Container And Validate Exit Code
207 [Arguments] ${env_file} ${expected_api_response_code} ${expected_exit_code}
208 ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK}
209 ${can_find_API_response}= Can Find Api Response In Logs ${CLIENT_CONTAINER_NAME}
210 ${api_response_code}= Get Api Response From Logs ${CLIENT_CONTAINER_NAME}
211 [Teardown] Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} negative_path
212 Should Be True ${can_find_API_response} Cannot Find API response in logs
213 Should Be Equal As Strings ${api_response_code} ${expected_api_response_code} API return ${api_response_code} but expected: ${expected_api_response_code}
214 Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return unexpected exit code return: ${exitcode} , but expected: ${expected_exit_code}
216 Run Cert Service Client And Validate Client Exit Code
217 [Documentation] Run Cert Service Client Container And Validate Exit Code
218 [Arguments] ${env_file} ${expected_exit_code}
219 [Teardown] Remove Client Container And Save Logs ${CLIENT_CONTAINER_NAME} negative_path
220 ${exit_code}= Run Client Container ${DOCKER_CLIENT_IMAGE} ${CLIENT_CONTAINER_NAME} ${env_file} ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT} ${CERT_SERVICE_NETWORK}
221 Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return unexpected exit code return: ${exitcode} , but expected: ${expected_exit_code}