Fix Cert-service tests
[integration/csit.git] / tests / oom-platform-cert-service / certservice / resources / cert-service-keywords.robot
1 *** Settings ***
2
3 Resource          ../../../common.robot
4 Resource          ./cert-service-properties.robot
5 Library               RequestsLibrary
6 Library           HttpLibrary.HTTP
7 Library           Collections
8 Library           ../libraries/CertClientManager.py  ${MOUNT_PATH}  ${TRUSTSTORE_PATH}
9 Library           ../libraries/P12ArtifactsValidator.py  ${MOUNT_PATH}
10 Library           ../libraries/JksArtifactsValidator.py  ${MOUNT_PATH}
11 Library           ../libraries/PemArtifactsValidator.py  ${MOUNT_PATH}
12
13 *** Keywords ***
14
15 Create sessions
16     [Documentation]  Create all required sessions
17     ${certs}=  Create List  ${CERTSERVICE_SERVER_CRT}  ${CERTSERVICE_SERVER_KEY}
18     Create Client Cert Session  alias  ${OOMCERT_URL}  client_certs=${certs}  verify=${ROOTCA}
19     Set Suite Variable  ${https_valid_cert_session}  alias
20
21 Run Healthcheck
22     [Documentation]  Run Healthcheck
23     ${resp}=  Get Request       ${https_valid_cert_session}     /actuator/health
24     Should Be Equal As Strings  ${resp.status_code}     200
25     Validate Recieved Response  ${resp}  status  UP
26
27 Validate Recieved Response
28     [Documentation]  Validare message that has been received
29     [Arguments]  ${resp}  ${key}  ${expected_value}
30     ${json}=    Parse Json      ${resp.content}
31     ${value}=  Get From Dictionary  ${json}  ${key}
32     Should Be Equal As Strings    ${value}    ${expected_value}
33
34 Send Get Request And Validate Response
35     [Documentation]   Send request to passed url and validate received response
36     [Arguments]   ${path}  ${resp_code}
37     ${resp}=    Get Request     ${https_valid_cert_session}  ${path}
38     Should Be Equal As Strings  ${resp.status_code}     ${resp_code}
39
40 Send Get Request with Header
41     [Documentation]  Send request to passed url
42     [Arguments]  ${path}  ${csr_file}  ${pk_file}
43     [Return]  ${resp}
44     ${headers}=  Create Header with CSR and PK  ${csr_file}  ${pk_file}
45     ${resp}=    Get Request     ${https_valid_cert_session}  ${path}  headers=${headers}
46
47 Send Get Request with Header And Expect Success
48     [Documentation]   Send request to passed url and validate received response
49     [Arguments]   ${path}  ${csr_file}  ${pk_file}
50     ${resp}=    Send Get Request with Header  ${path}  ${csr_file}  ${pk_file}
51     Should Be Equal As Strings  ${resp.status_code}     200
52     Check Message Recieved On Success  ${resp.content}
53
54 Check Message Recieved On Success
55     [Documentation]  Check if correct messsage has been sent on successful request
56     [Arguments]  ${content}
57     ${resp_content}=  Parse Json  ${content}
58     Dictionary Should Contain Key  ${resp_content}  certificateChain
59     @{list}=  Get From Dictionary  ${resp_content}  certificateChain
60     List Should Contain Certificates  @{list}
61     Dictionary Should Contain Key  ${resp_content}  trustedCertificates
62
63 List Should Contain Certificates
64     [Documentation]  Verify if list contains certificates
65     [Arguments]  @{list}
66     FOR    ${content}    IN    @{list}
67         Should Contain  ${content}  BEGIN CERTIFICATE
68         Should Contain  ${content}  END CERTIFICATE
69     END
70
71 Send Get Request with Header And Expect Error
72     [Documentation]   Send request to passed url and validate received response
73     [Arguments]   ${path}  ${csr_file}  ${pk_file}  ${resp_code}
74     ${resp}=    Send Get Request with Header  ${path}  ${csr_file}  ${pk_file}
75     Should Be Equal As Strings  ${resp.status_code}     ${resp_code}
76
77 Create Header with CSR and PK
78     [Documentation]  Create header with CSR and PK
79     [Arguments]  ${csr_file}  ${pk_file}
80     [Return]     ${headers}
81     ${csr}=  Get Data From File  ${csr_file}
82     ${pk}=   Get Data From File  ${pk_file}
83     ${headers}=  Create Dictionary  CSR=${csr}  PK=${pk}
84
85 Send Post Request And Validate Response
86     [Documentation]   Send request to passed url and validate received response
87     [Arguments]   ${path}  ${resp_code}
88     ${resp}=    Post Request    ${https_valid_cert_session}  ${path}
89     Should Be Equal As Strings  ${resp.status_code}     ${resp_code}
90
91 Run Cert Service Client And Validate PKCS12 File Creation And Client Exit Code
92     [Documentation]  Run Cert Service Client Container And Validate Exit Code
93     [Arguments]   ${env_file}  ${expected_exit_code}
94     ${exit_code}=  Run Client Container  ${DOCKER_CLIENT_IMAGE}  ${CLIENT_CONTAINER_NAME}  ${env_file}  ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT}  ${CERT_SERVICE_NETWORK}
95     ${can_open}=  Can Open Keystore And Truststore With Pass
96     Remove Client Container And Save Logs  ${CLIENT_CONTAINER_NAME}  positive_path
97     Should Be Equal As Strings  ${exit_code}  ${expected_exit_code}  Client return: ${exitcode} exit code, but expected: ${expected_exit_code}
98     Should Be True  ${can_open}  Cannot Open Keystore/TrustStore by passpshase
99
100 Run Cert Service Client And Validate JKS File Creation And Client Exit Code
101     [Documentation]  Run Cert Service Client Container And Validate Exit Code
102     [Arguments]   ${env_file}  ${expected_exit_code}
103     ${exit_code}=  Run Client Container  ${DOCKER_CLIENT_IMAGE}  ${CLIENT_CONTAINER_NAME}  ${env_file}  ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT}  ${CERT_SERVICE_NETWORK}
104     ${can_open}=  Can Open Keystore And Truststore With Pass Jks
105     Remove Client Container And Save Logs  ${CLIENT_CONTAINER_NAME}  positive_path
106     Should Be Equal As Strings  ${exit_code}  ${expected_exit_code}  Client return: ${exitcode} exit code, but expected: ${expected_exit_code}
107     Should Be True  ${can_open}  Cannot Open Keystore/TrustStore by passpshase
108
109 Run Cert Service Client And Validate PKCS12 Files Contain Expected Data
110     [Documentation]  Run Cert Service Client Container And Validate PKCS12 Files Contain Expected Data
111     [Arguments]  ${env_file}  ${expected_exit_code}
112     ${exit_code}=  Run Client Container  ${DOCKER_CLIENT_IMAGE}  ${CLIENT_CONTAINER_NAME}  ${env_file}  ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT}  ${CERT_SERVICE_NETWORK}
113     ${data}    ${isEqual}=  Get And Compare Data P12  ${env_file}
114     Remove Client Container And Save Logs  ${CLIENT_CONTAINER_NAME}  positive_path_with_data
115     Should Be Equal As Strings  ${exit_code}  ${expected_exit_code}  Client return: ${exitcode} exit code, but expected: ${expected_exit_code}
116     Should Be True  ${isEqual}  Keystore doesn't contain ${data.expectedData}. Actual data is: ${data.actualData}
117
118 Run Cert Service Client And Validate JKS Files Contain Expected Data
119     [Documentation]  Run Cert Service Client Container And Validate JKS Files Contain Expected Data
120     [Arguments]  ${env_file}  ${expected_exit_code}
121     ${exit_code}=  Run Client Container  ${DOCKER_CLIENT_IMAGE}  ${CLIENT_CONTAINER_NAME}  ${env_file}  ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT}  ${CERT_SERVICE_NETWORK}
122     ${data}    ${isEqual}=  Get And Compare Data Jks  ${env_file}
123     Remove Client Container And Save Logs  ${CLIENT_CONTAINER_NAME}  positive_path_with_data
124     Should Be Equal As Strings  ${exit_code}  ${expected_exit_code}  Client return: ${exitcode} exit code, but expected: ${expected_exit_code}
125     Should Be True  ${isEqual}  Keystore doesn't contain ${data.expectedData}. Actual data is: ${data.actualData}
126
127 Run Cert Service Client And Validate PEM Files Contain Expected Data
128     [Documentation]  Run Cert Service Client Container And Validate PEM Files Contain Expected Data
129     [Arguments]  ${env_file}  ${expected_exit_code}
130     ${exit_code}=  Run Client Container  ${DOCKER_CLIENT_IMAGE}  ${CLIENT_CONTAINER_NAME}  ${env_file}  ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT}  ${CERT_SERVICE_NETWORK}
131     ${existNotEmpty}=  Artifacts Exist And Are Not Empty
132     ${data}    ${isEqual}=  Get And Compare Data Pem  ${env_file}
133     Remove Client Container And Save Logs  ${CLIENT_CONTAINER_NAME}  positive_path_with_data
134     Should Be Equal As Strings  ${exit_code}  ${expected_exit_code}  Client return: ${exitcode} exit code, but expected: ${expected_exit_code}
135     Should Be True  ${existNotEmpty}  PEM artifacts not created properly
136     Should Be True  ${isEqual}  Keystore doesn't contain ${data.expectedData}. Actual data is: ${data.actualData}
137
138 Run Cert Service Client And Validate Http Response Code And Client Exit Code
139     [Documentation]  Run Cert Service Client Container And Validate Exit Code
140     [Arguments]   ${env_file}  ${expected_api_response_code}  ${expected_exit_code}
141     ${exit_code}=  Run Client Container  ${DOCKER_CLIENT_IMAGE}  ${CLIENT_CONTAINER_NAME}  ${env_file}  ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT}  ${CERT_SERVICE_NETWORK}
142     ${can_find_API_response}=  Can Find Api Response In Logs  ${CLIENT_CONTAINER_NAME}
143     ${api_response_code}=  Get Api Response From Logs  ${CLIENT_CONTAINER_NAME}
144     Remove Client Container And Save Logs  ${CLIENT_CONTAINER_NAME}  negative_path
145     Should Be True  ${can_find_API_response}  Cannot Find API response in logs
146     Should Be Equal As Strings  ${api_response_code}  ${expected_api_response_code}  API return ${api_response_code} but expected: ${expected_api_response_code}
147     Should Be Equal As Strings  ${exit_code}  ${expected_exit_code}  Client return unexpected exit code return: ${exitcode} , but expected: ${expected_exit_code}
148
149 Run Cert Service Client And Validate Client Exit Code
150     [Documentation]  Run Cert Service Client Container And Validate Exit Code
151     [Arguments]   ${env_file}  ${expected_exit_code}
152     ${exit_code}=  Run Client Container  ${DOCKER_CLIENT_IMAGE}  ${CLIENT_CONTAINER_NAME}  ${env_file}  ${CERT_SERVICE_ADDRESS}${CERT_SERVICE_ENDPOINT}  ${CERT_SERVICE_NETWORK}
153     Remove Client Container And Save Logs  ${CLIENT_CONTAINER_NAME}  negative_path
154     Should Be Equal As Strings  ${exit_code}  ${expected_exit_code}  Client return unexpected exit code return: ${exitcode} , but expected: ${expected_exit_code}
155