harbor/tests/resources/Harbor-Pages/Vulnerability.robot
Yang Jiao 8aac52ace4
[cherry-pick]Add Job Service Dashboard Schedules testcase (#18557)
Add Job Service Dashboard Schedules testcase

Fix #17949

Signed-off-by: Yang Jiao <jiaoya@vmware.com>
2023-04-20 11:12:06 +08:00

114 lines
5.9 KiB
Plaintext

*** Settings ***
Documentation This resource provides any keywords related to the Harbor private registry appliance
Resource ../../resources/Util.robot
*** Variables ***
*** Keywords ***
Disable Scan Schedule
Retry Double Keywords When Error Retry Element Click ${vulnerability_edit_btn} Retry Wait Until Page Not Contains Element ${vulnerability_edit_btn}
Retry Element Click ${vulnerability_dropdown_list}
Retry Element Click ${vulnerability_dropdown_list_item_none}
Retry Double Keywords When Error Retry Element Click ${vulnerability_save_btn} Retry Wait Until Page Not Contains Element ${vulnerability_save_btn}
Set Scan Schedule
[Arguments] ${type} ${value}=${null}
Retry Double Keywords When Error Retry Element Click ${vulnerability_edit_btn} Retry Wait Until Page Not Contains Element ${vulnerability_edit_btn}
Retry Double Keywords When Error Retry Element Click ${vulnerability_dropdown_list} Retry Element Click //select[@id='selectPolicy']//option[contains(.,'${type}')]
Run Keyword If '${type}'=='Custom' Retry Text Input ${targetCron_id} ${value}
Retry Double Keywords When Error Retry Element Click ${vulnerability_save_btn} Retry Wait Until Page Not Contains Element ${vulnerability_save_btn}
Trigger Scan Now And Wait Until The Result Appears
Retry Element Click xpath=${scan_now_button}
Retry Action Keyword Wait Until Element Is Visible And Enabled ${scan_now_button}
Switch To Vulnerability Page
Retry Element Click xpath=//clr-main-container//clr-vertical-nav//a[contains(.,'Interrogation')]
Retry Element Click xpath=//app-interrogation-services//a[contains(.,'Vulnerability')]
Retry Wait Element ${scan_now_button}
Set Vulnerabilty Serverity
#0 is critical, 1 is high, 2 is medium, 3 is low, 4 is negligible.
[Arguments] ${level}
Goto Project Config
#enable first
Retry Element Click ${project_config_prevent_vulenrability_checkbox_label}
Checkbox Should Be Selected //project-detail//clr-checkbox-wrapper//input[@name='prevent-vulenrability-image-input']
Retry Element Click //project-detail//select
#wait for dropdown popup
Sleep 1
Select From List By Index //project-detail//select ${level}
Retry Element Click ${project_config_save_btn}
Scan Is Disabled
Retry Wait Until Page Contains Element //button[@id='scan-btn' and @disabled='']
Scan Repo
#use fail for image can not scan, otherwise use success
[Arguments] ${tagname} ${status}
#select one tag
Retry Element Click //clr-dg-row[contains(.,'${tagname}')]//label
Retry Element Click //button[@id='scan-btn']
Run Keyword If '${status}' == 'Succeed' Wait Until Element Is Visible //hbr-vulnerability-bar//hbr-result-tip-histogram 300
Run Keyword If '${status}' == 'Fail' Wait Until Element Is Visible //hbr-vulnerability-bar//a 300
Scan Result Should Display In List Row
[Arguments] ${tagname} ${is_no_vulerabilty}=${false}
Run Keyword If ${is_no_vulerabilty}==${true} Retry Wait Until Page Contains Element //artifact-list-tab//clr-dg-row[contains(.,'No vulnerability') and contains(.,'${tagname}')]//clr-dg-cell//clr-tooltip
... ELSE Retry Wait Until Page Contains Element //artifact-list-tab//clr-dg-row[contains(.,'Total') and contains(.,'Fixable') and contains(.,'${tagname}')]//clr-dg-cell//clr-tooltip
Enable Scan On Push
Checkbox Should Not Be Selected //clr-checkbox-wrapper[@id='scan-image-on-push-wrapper']//input
Retry Element Click //clr-checkbox-wrapper[@id='scan-image-on-push-wrapper']//label
Checkbox Should Be Selected //clr-checkbox-wrapper[@id='scan-image-on-push-wrapper']//input
Retry Element Click ${project_config_save_btn}
Sleep 10
Vulnerability Not Ready Project Hint
Sleep 2
${element}= Set Variable xpath=//span[contains(@class, 'db-status-warning')]
Wait Until Element Is Visible And Enabled ${element}
Switch To Scanners Page
Retry Element Click xpath=//clr-main-container//clr-vertical-nav//a[contains(.,'Interrogation')]
Retry Wait Until Page Contains Element ${set_default_scanner}
Should Display The Default Trivy Scanner
Retry Wait Until Page Contains Element //clr-datagrid//clr-dg-row//clr-dg-cell[contains(.,'Trivy')]//span[contains(.,'Default')]
Trivy Is Immutable Scanner
Retry Element Click //clr-dg-row[contains(.,'Trivy')]//clr-radio-wrapper/label
Retry Double Keywords When Error Retry Element Click ${scanner_action_xpath} Retry Wait Until Page Contains Element ${delete_scanner_action_xpath}
Retry Double Keywords When Error Retry Element Click ${delete_scanner_action_xpath} Retry Wait Until Page Contains Element ${delete_scanner_confirm_btn}
Retry Double Keywords When Error Retry Element Click ${delete_scanner_confirm_btn} Retry Wait Until Page Contains Element ${immutable_trivy_msg_xpath}
Set Default Scanner
[Arguments] ${scanner_name}
Retry Element Click //clr-dg-row[contains(.,'${scanner_name}')]//clr-radio-wrapper/label
Retry Double Keywords When Error Retry Element Click ${scanner_set_default} Retry Wait Until Page Contains Element ${scanner_set_default_success_xpath}
Check Listed In CVE Allowlist
[Arguments] ${project_name} ${image} ${tag} ${cve_id} ${is_in}=Yes
Go Into Project ${project_name}
Go Into Repo ${project_name}/${image}
Go Into Artifact ${tag}
Scroll Element Into View //clr-dg-row[contains(.,'${cve_id}')]
${text}= Get Text //clr-dg-row[contains(.,'${cve_id}')]//clr-dg-cell[7]
Capture Page Screenshot
Log All is_in_allow_list:${text}
Should Be Equal As Strings '${text}' '${is_in}'
Scan All Artifact
Switch To Vulnerability Page
Retry Element Click ${scan_now_button}
Stop Scan All Artifact
Retry Element Click ${stop_scan_button}
Check Scan All Artifact Job Status Is Stopped
Wait Until Element Is Visible ${stopped_icon}
${stopped_total}= Get Text ${stopped_icon}
Should Be True ${stopped_total} > 0