<commit_before>*** Settings ***

Documentation  Test OpenBMC GUI "SSL Certificates" sub-menu of "Access control".

Resource        ../../lib/resource.robot
Resource        ../../../lib/certificate_utils.robot

Suite Setup     Suite Setup Execution
Suite Teardown  Close Browser
Test Setup      Test Setup Execution


*** Variables ***

${xpath_certificate_heading}       //h1[text()="SSL certificates"]
${xpath_add_certificate_button}    //button[contains(text(),"Add new certificate")]
${xpath_generate_csr_button}       //*[@data-test-id='sslCertificates-button-generateCsr']
${xpath_generate_csr_heading}      //h5[contains(text(), "Generate a Certificate Signing Request")]
${xpath_select_certificate_type}   //*[@data-test-id='modalGenerateCsr-select-certificateType']
${xpath_select_country}            //*[@data-test-id='modalGenerateCsr-select-country']
${xpath_input_state}               //*[@data-test-id='modalGenerateCsr-input-state']
${xpath_input_city}                //*[@data-test-id='modalGenerateCsr-input-city']
${xpath_input_company_name}        //*[@data-test-id='modalGenerateCsr-input-companyName']
${xpath_input_company_unit}        //*[@data-test-id='modalGenerateCsr-input-companyUnit']
${xpath_input_common_name}         //*[@data-test-id='modalGenerateCsr-input-commonName']
${xpath_input_challenge_password}  //*[@data-test-id='modalGenerateCsr-input-challengePassword']
${xpath_input_contact_person}      //*[@data-test-id='modalGenerateCsr-input-contactPerson']
${xpath_input_email_address}       //*[@data-test-id='modalGenerateCsr-input-emailAddress']
${xpath_generate_csr_submit}       //*[@data-test-id='modalGenerateCsr-button-ok']
${xpath_csr_cancel_button}         //button[contains(text(),"Cancel")]
${xpath_input_alternate_name}      //input[@id='alternate-name']
${xpath_select_algorithm_button}   //*[@data-test-id='modalGenerateCsr-select-keyPairAlgorithm']

*** Test Cases ***

Verify Navigation To SSL Certificate Page
    [Documentation]  Verify navigation to SSL certificate page.
    [Tags]  Verify_Navigation_To_SSL_Certificate_Page

    Page Should Contain Element  ${xpath_certificate_heading}


Verify Existence Of All Sections In Certificate Page
    [Documentation]  Verify existence of all sections in certificate page.
    [Tags]  Verify_Existence_Of_All_Sections_In_Certificate_Page

    Page should contain  Certificate
    Page should contain  Valid from
    Page should contain  Valid until


Verify Existence Of Add Certificate Button
    [Documentation]  Verify existence of add certificate button.
    [Tags]  Verify_Existence_Of_Add_Certificate_Button

    Page Should Contain Element  ${xpath_add_certificate_button}

Verify Generate CSR Certificate Button
    [Documentation]  Verify existence of all the fields of CSR generation.
    [Tags]  Verify_Generate_CSR_Certificate_Button
    [Teardown]  Click Element  ${xpath_csr_cancel_button}

    Page Should Contain Element  ${xpath_generate_csr_button}
    Click Element  ${xpath_generate_csr_button}
    Wait Until Page Contains Element  ${xpath_generate_csr_heading}
    Page Should Contain Element  ${xpath_select_certificate_type}
    Page Should Contain Element  ${xpath_select_country}
    Page Should Contain Element  ${xpath_input_state}
    Page Should Contain Element  ${xpath_input_city}
    Page Should Contain Element  ${xpath_input_company_name}
    Page Should Contain Element  ${xpath_input_common_name}
    Page Should Contain Element  ${xpath_input_challenge_password}
    Page Should Contain Element  ${xpath_input_contact_person}
    Page Should Contain Element  ${xpath_input_email_address}
    Page Should Contain Element  ${xpath_input_alternate_name}
    Page Should Contain Element  ${xpath_select_algorithm_button}
    Page Should Contain Element  ${xpath_generate_csr_submit}


Verify Installed CA Certificate
    [Documentation]  Install CA certificate and verify the same via GUI.
    [Tags]  Verify_Installed_CA_Certificate

    Delete All CA Certificate Via Redfish

    # Install CA certificate via Redfish.
    ${file_data}=  Generate Certificate File Data
    Install Certificate File On BMC  ${REDFISH_CA_CERTIFICATE_URI}  ok  data=${file_data}

    # Verify CA certificate availability in GUI.
    Page Should Contain  CA Certificate


Verify Installed HTTPS Certificate
    [Documentation]  Install HTTPS certificate via Redfish and verify it in GUI.
    [Tags]  Verify_Installed_HTTPS_Certificate

    # Install HTTPS certificate.
    ${file_data}=  Generate Certificate File Data
    Install Certificate File On BMC  ${REDFISH_HTTPS_CERTIFICATE_URI}  ok  data=${file_data}

    # Verify certificate is available in GUI.
    Page Should Contain  HTTPS Certificate


Verify Installed LDAP Certificate
    [Documentation]  Install LDAP certificate via Redfish and verify it in GUI.
    [Tags]  Verify_Installed_LDAP_Certificate

    Delete Certificate Via BMC CLI  Client

    # Install LDAP certificate.
    ${file_data}=  Generate Certificate File Data
    Install Certificate File On BMC  ${REDFISH_LDAP_CERTIFICATE_URI}  ok  data=${file_data}

    # Verify certificate is available in GUI.
    Page Should Contain  LDAP Certificate


*** Keywords ***

Generate Certificate File Data
    [Documentation]  Generate data of certificate file.

    ${cert_file_path}=  Generate Certificate File Via Openssl  Valid Certificate  365
    ${bytes}=  OperatingSystem.Get Binary File  ${cert_file_path}
    ${file_data}=  Decode Bytes To String  ${bytes}  UTF-8

    [return]  ${file_data}


Test Setup Execution
    [Documentation]  Do test case setup tasks.

    Click Element  ${xpath_access_control_menu}
    Click Element  ${xpath_ssl_certificates_sub_menu}<commit_msg>Fix installation failure of ladap cert in GUI automtation TC<commit_after>*** Settings ***

Documentation  Test OpenBMC GUI "SSL Certificates" sub-menu of "Access control".

Resource        ../../lib/resource.robot
Resource        ../../../lib/certificate_utils.robot

Suite Setup     Suite Setup Execution
Suite Teardown  Close Browser
Test Setup      Test Setup Execution


*** Variables ***

${xpath_certificate_heading}       //h1[text()="SSL certificates"]
${xpath_add_certificate_button}    //button[contains(text(),"Add new certificate")]
${xpath_generate_csr_button}       //*[@data-test-id='sslCertificates-button-generateCsr']
${xpath_generate_csr_heading}      //h5[contains(text(), "Generate a Certificate Signing Request")]
${xpath_select_certificate_type}   //*[@data-test-id='modalGenerateCsr-select-certificateType']
${xpath_select_country}            //*[@data-test-id='modalGenerateCsr-select-country']
${xpath_input_state}               //*[@data-test-id='modalGenerateCsr-input-state']
${xpath_input_city}                //*[@data-test-id='modalGenerateCsr-input-city']
${xpath_input_company_name}        //*[@data-test-id='modalGenerateCsr-input-companyName']
${xpath_input_company_unit}        //*[@data-test-id='modalGenerateCsr-input-companyUnit']
${xpath_input_common_name}         //*[@data-test-id='modalGenerateCsr-input-commonName']
${xpath_input_challenge_password}  //*[@data-test-id='modalGenerateCsr-input-challengePassword']
${xpath_input_contact_person}      //*[@data-test-id='modalGenerateCsr-input-contactPerson']
${xpath_input_email_address}       //*[@data-test-id='modalGenerateCsr-input-emailAddress']
${xpath_generate_csr_submit}       //*[@data-test-id='modalGenerateCsr-button-ok']
${xpath_csr_cancel_button}         //button[contains(text(),"Cancel")]
${xpath_input_alternate_name}      //input[@id='alternate-name']
${xpath_select_algorithm_button}   //*[@data-test-id='modalGenerateCsr-select-keyPairAlgorithm']

*** Test Cases ***

Verify Navigation To SSL Certificate Page
    [Documentation]  Verify navigation to SSL certificate page.
    [Tags]  Verify_Navigation_To_SSL_Certificate_Page

    Page Should Contain Element  ${xpath_certificate_heading}


Verify Existence Of All Sections In Certificate Page
    [Documentation]  Verify existence of all sections in certificate page.
    [Tags]  Verify_Existence_Of_All_Sections_In_Certificate_Page

    Page should contain  Certificate
    Page should contain  Valid from
    Page should contain  Valid until


Verify Existence Of Add Certificate Button
    [Documentation]  Verify existence of add certificate button.
    [Tags]  Verify_Existence_Of_Add_Certificate_Button

    Page Should Contain Element  ${xpath_add_certificate_button}

Verify Generate CSR Certificate Button
    [Documentation]  Verify existence of all the fields of CSR generation.
    [Tags]  Verify_Generate_CSR_Certificate_Button
    [Teardown]  Click Element  ${xpath_csr_cancel_button}

    Page Should Contain Element  ${xpath_generate_csr_button}
    Click Element  ${xpath_generate_csr_button}
    Wait Until Page Contains Element  ${xpath_generate_csr_heading}
    Page Should Contain Element  ${xpath_select_certificate_type}
    Page Should Contain Element  ${xpath_select_country}
    Page Should Contain Element  ${xpath_input_state}
    Page Should Contain Element  ${xpath_input_city}
    Page Should Contain Element  ${xpath_input_company_name}
    Page Should Contain Element  ${xpath_input_common_name}
    Page Should Contain Element  ${xpath_input_challenge_password}
    Page Should Contain Element  ${xpath_input_contact_person}
    Page Should Contain Element  ${xpath_input_email_address}
    Page Should Contain Element  ${xpath_input_alternate_name}
    Page Should Contain Element  ${xpath_select_algorithm_button}
    Page Should Contain Element  ${xpath_generate_csr_submit}


Verify Installed CA Certificate
    [Documentation]  Install CA certificate and verify the same via GUI.
    [Tags]  Verify_Installed_CA_Certificate

    Delete All CA Certificate Via Redfish

    # Install CA certificate via Redfish.
    ${file_data}=  Generate Certificate File Data  CA
    Install Certificate File On BMC  ${REDFISH_CA_CERTIFICATE_URI}  ok  data=${file_data}

    # Verify CA certificate availability in GUI.
    Page Should Contain  CA Certificate


Verify Installed HTTPS Certificate
    [Documentation]  Install HTTPS certificate via Redfish and verify it in GUI.
    [Tags]  Verify_Installed_HTTPS_Certificate

    # Install HTTPS certificate.
    ${file_data}=  Generate Certificate File Data  Server
    Install Certificate File On BMC  ${REDFISH_HTTPS_CERTIFICATE_URI}  ok  data=${file_data}

    # Verify certificate is available in GUI.
    Page Should Contain  HTTPS Certificate


Verify Installed LDAP Certificate
    [Documentation]  Install LDAP certificate via Redfish and verify it in GUI.
    [Tags]  Verify_Installed_LDAP_Certificate

    Delete Certificate Via BMC CLI  Client

    # Install LDAP certificate.
    ${file_data}=  Generate Certificate File Data  Client
    Install Certificate File On BMC  ${REDFISH_LDAP_CERTIFICATE_URI}  ok  data=${file_data}

    # Verify certificate is available in GUI.
    Page Should Contain  LDAP Certificate


*** Keywords ***

Generate Certificate File Data
    [Documentation]  Generate data of certificate file.

    [Arguments]  ${cert_type}

    # Description of Arguments(s):
    # cert_type      Certificate type (e.g. "Client" or  "CA").

    ${cert_file_path}=  Run Keyword If  '${cert_type}' == 'Client' or 'Server'
    ...    Generate Certificate File Via Openssl  Valid Certificate Valid Privatekey
    ...  ELSE IF  '${cert_type}' == 'CA'
    ...    Generate Certificate File Via Openssl  Valid Certificate
    ${bytes}=  OperatingSystem.Get Binary File  ${cert_file_path}
    ${file_data}=  Decode Bytes To String  ${bytes}  UTF-8

    [return]  ${file_data}


Test Setup Execution
    [Documentation]  Do test case setup tasks.

    Click Element  ${xpath_access_control_menu}
    Click Element  ${xpath_ssl_certificates_sub_menu}
{'fraction_non_alphanumeric': 0.08847162310750233, 'fraction_numerical': 0.0007612281146917026, 'mean_word_length': 4.288014311270126, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '12733', 'n_tokens_mistral': 3586, 'n_tokens_neox': 3458, 'n_words': 920}