1*** Settings ***
2
3Documentation  Test OpenBMC GUI "Certificates" sub-menu of "Security and access".
4
5Resource        ../../lib/gui_resource.robot
6Resource        ../../../lib/certificate_utils.robot
7
8Suite Setup     Suite Setup Execution
9Suite Teardown  Close Browser
10Test Setup      Test Setup Execution
11
12
13*** Variables ***
14
15${xpath_certificate_heading}       //h1[text()="Certificates"]
16${xpath_add_certificate_button}    //button[contains(text(),"Add new certificate")]
17${xpath_generate_csr_button}       //*[@data-test-id='certificates-button-generateCsr']
18${xpath_generate_csr_heading}      //h5[contains(text(), "Generate a Certificate Signing Request")]
19${xpath_select_certificate_type}   //*[@data-test-id='modalGenerateCsr-select-certificateType']
20${xpath_select_country}            //*[@data-test-id='modalGenerateCsr-select-country']
21${xpath_input_state}               //*[@data-test-id='modalGenerateCsr-input-state']
22${xpath_input_city}                //*[@data-test-id='modalGenerateCsr-input-city']
23${xpath_input_company_name}        //*[@data-test-id='modalGenerateCsr-input-companyName']
24${xpath_input_company_unit}        //*[@data-test-id='modalGenerateCsr-input-companyUnit']
25${xpath_input_common_name}         //*[@data-test-id='modalGenerateCsr-input-commonName']
26${xpath_input_challenge_password}  //*[@data-test-id='modalGenerateCsr-input-challengePassword']
27${xpath_input_contact_person}      //*[@data-test-id='modalGenerateCsr-input-contactPerson']
28${xpath_input_email_address}       //*[@data-test-id='modalGenerateCsr-input-emailAddress']
29${xpath_generate_csr_submit}       //*[@data-test-id='modalGenerateCsr-button-ok']
30${xpath_csr_cancel_button}         //button[contains(text(),"Cancel")]
31${xpath_input_alternate_name}      //input[@id='alternate-name']
32${xpath_select_algorithm_button}   //*[@data-test-id='modalGenerateCsr-select-keyPairAlgorithm']
33
34*** Test Cases ***
35
36Verify Navigation To Certificate Page
37    [Documentation]  Verify navigation to certificate page.
38    [Tags]  Verify_Navigation_To_Certificate_Page
39
40    Page Should Contain Element  ${xpath_certificate_heading}
41
42
43Verify Existence Of All Sections In Certificate Page
44    [Documentation]  Verify existence of all sections in certificate page.
45    [Tags]  Verify_Existence_Of_All_Sections_In_Certificate_Page
46
47    Page should contain  Certificate
48    Page should contain  Valid from
49    Page should contain  Valid until
50
51
52Verify Existence Of Add Certificate Button
53    [Documentation]  Verify existence of add certificate button.
54    [Tags]  Verify_Existence_Of_Add_Certificate_Button
55
56    Page Should Contain Element  ${xpath_add_certificate_button}
57
58Verify Generate CSR Certificate Button
59    [Documentation]  Verify existence of all the fields of CSR generation.
60    [Tags]  Verify_Generate_CSR_Certificate_Button
61    [Teardown]  Click Element  ${xpath_csr_cancel_button}
62
63    Page Should Contain Element  ${xpath_generate_csr_button}
64    Click Element  ${xpath_generate_csr_button}
65    Wait Until Page Contains Element  ${xpath_generate_csr_heading}
66    Page Should Contain Element  ${xpath_select_certificate_type}
67    Page Should Contain Element  ${xpath_select_country}
68    Page Should Contain Element  ${xpath_input_state}
69    Page Should Contain Element  ${xpath_input_city}
70    Page Should Contain Element  ${xpath_input_company_name}
71    Page Should Contain Element  ${xpath_input_common_name}
72    Page Should Contain Element  ${xpath_input_challenge_password}
73    Page Should Contain Element  ${xpath_input_contact_person}
74    Page Should Contain Element  ${xpath_input_email_address}
75    Page Should Contain Element  ${xpath_input_alternate_name}
76    Page Should Contain Element  ${xpath_select_algorithm_button}
77    Page Should Contain Element  ${xpath_generate_csr_submit}
78
79
80Verify Installed CA Certificate
81    [Documentation]  Install CA certificate and verify the same via GUI.
82    [Tags]  Verify_Installed_CA_Certificate
83
84    Delete All CA Certificate Via Redfish
85
86    # Install CA certificate via Redfish.
87    ${file_data}=  Generate Certificate File Data  CA
88    Install And Verify Certificate Via Redfish  CA  Valid Certificate  ok
89
90    # Refresh GUI and verify CA certificate availability in GUI.
91    Refresh GUI
92    Wait Until Page Contains  CA Certificate  timeout=10
93
94
95Verify Installed HTTPS Certificate
96    [Documentation]  Install HTTPS certificate via Redfish and verify it in GUI.
97    [Tags]  Verify_Installed_HTTPS_Certificate
98
99    # Replace HTTPS certificate.
100    Redfish.Login
101    Replace Certificate Via Redfish  Server   Valid Certificate Valid Privatekey  ok
102    Redfish.Logout
103
104    # Verify certificate is available in GUI.
105    Wait Until Page Contains  HTTPS Certificate  timeout=10
106
107
108Verify Installed LDAP Certificate
109    [Documentation]  Install LDAP certificate via Redfish and verify it in GUI.
110    [Tags]  Verify_Installed_LDAP_Certificate
111
112    Redfish.Login
113    Delete Certificate Via BMC CLI  Client
114
115    # Install LDAP certificate.
116    ${file_data}=  Generate Certificate File Data  Client
117    Install And Verify Certificate Via Redfish  Client  Valid Certificate Valid Privatekey  ok
118    Redfish.Logout
119
120    # Refresh GUI and verify certificate is available in GUI.
121    Refresh GUI
122    Wait Until Page Contains  LDAP Certificate  timeout=10
123
124
125*** Keywords ***
126
127Generate Certificate File Data
128    [Documentation]  Generate data of certificate file.
129
130    [Arguments]  ${cert_type}
131
132    # Description of Arguments(s):
133    # cert_type      Certificate type (e.g. "Client" or  "CA").
134
135    ${cert_file_path}=  Run Keyword If  '${cert_type}' == 'Client' or 'Server'
136    ...    Generate Certificate File Via Openssl  Valid Certificate Valid Privatekey
137    ...  ELSE IF  '${cert_type}' == 'CA'
138    ...    Generate Certificate File Via Openssl  Valid Certificate
139    ${bytes}=  OperatingSystem.Get Binary File  ${cert_file_path}
140    ${file_data}=  Decode Bytes To String  ${bytes}  UTF-8
141
142    [return]  ${file_data}
143
144
145Test Setup Execution
146    [Documentation]  Do test case setup tasks.
147
148    Click Element  ${xpath_secuity_and_accesss_menu}
149    Click Element  ${xpath_certificates_sub_menu}
150    Wait Until Keyword Succeeds  30 sec  10 sec  Location Should Contain  certificates
151    Wait Until Element Is Not Visible   ${xpath_page_loading_progress_bar}  timeout=30
152
153
154Suite Setup Execution
155    [Documentation]  Do test case suite setup tasks.
156
157    Launch Browser And Login GUI
158    Create Directory  certificate_dir
159