[cherry-pick]Add export CVE UI testcase (#17675)

Add export CVE UI testcase

1 Add CVE function verification
2 Add content validation of exported CSV file

Signed-off-by: Yang Jiao <jiaoya@vmware.com>
This commit is contained in:
Yang Jiao 2022-10-21 18:41:54 +08:00 committed by GitHub
parent 058e84c73f
commit 585fe6dc83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 106 additions and 9 deletions

View File

@ -36,3 +36,6 @@ ${header} xpath=//clr-header[contains(@class,'header-5')]
${color_theme_light} //span[contains(.,'LIGHT')]
${close_btn} //button[contains(.,'CLOSE')]
${more_info_link_xpath} //sign-in//div//a[contains(.,'More info...')]
${event_log_xpath} //hbr-operation-model//a[contains(., 'EVENT LOG')]
${latest_download_cve_csv_file_xpath} //section/div[1]//clr-icon[@shape='download']
${latest_cve_csv_file_name_xpath} //section/div[1]//span[contains(., 'csv_file')]

View File

@ -85,10 +85,7 @@ Switch To Project Tab Overflow
Sleep 1
Navigate To Projects
Reload Page
Sleep 3
Retry Element Click xpath=${projects_xpath}
Sleep 1
Project Should Display
[Arguments] ${projectname}
@ -399,3 +396,37 @@ Delete Accessory
Should be Accessory deleted
[Arguments] ${tag}
Retry Wait Until Page Not Contains Element //clr-dg-row[contains(.,'${tag}')]//button[contains(@class,'datagrid-expandable-caret-button')]
Export CVEs
[Arguments] ${project} ${repositories} ${tags} ${labels} ${cve_ids}
Filter Project ${project}
Retry Element Click //clr-dg-row[contains(.,'${project}')]//div[contains(@class,'clr-checkbox-wrapper')]//label
Retry Element Click ${project_action_xpath}
Retry Button Click ${export_cve_btn}
Retry Text Input ${export_cve_filter_repo_input} ${repositories}
Retry Text Input ${export_cve_filter_tag_input} ${tags}
Select Export CVEs Filter Label @{labels}
Retry Text Input ${export_cve_filter_cveid_input} ${cve_ids}
Retry Double Keywords When Error Retry Button Click ${export_btn} Retry Wait Until Page Contains Trigger exporting CVEs successfully!
Select Export CVEs Filter Label
[Arguments] @{labels}
Retry Element Click ${filter_label_xpath}
FOR ${label} IN @{labels}
Log ${label}
Retry Element Click //hbr-label-piece//label[contains(text(), '${label}')]
END
Retry Element Click ${filter_label_xpath}
Should Not Be Export CVEs
Retry Element Click ${project_action_xpath}
Retry Wait Element Should Be Disabled ${export_cve_btn}
Retry Element Click ${project_action_xpath}
Download Latest CVE CSV File
Retry Element Click ${event_log_xpath}
${csv_file_name}= Get Text ${latest_cve_csv_file_name_xpath}
${csv_file_path}= Set Variable ${download_directory}/${csv_file_name}.csv
Retry Double Keywords When Error Retry Element Click ${latest_download_cve_csv_file_xpath} Retry Wait Until Page Does Not Contains ${csv_file_name}
Retry File Should Exist ${csv_file_path}
[Return] ${csv_file_path}

View File

@ -20,5 +20,9 @@ ${delete_btn} //clr-modal//button[contains(.,'DELETE')]
${delete_btn_2} //button[contains(.,'Delete')]
${default_scanner_info_close_icon} /html/body/harbor-app/harbor-shell/clr-main-container/div[1]/div[3]/clr-icon
${back_to_home_link} /html/body/harbor-app/harbor-shell/clr-main-container/div[2]/div/search-result/div/div[2]/a
${select_all_project_box} //label[contains(@for, 'clr-dg-select-all-clr-id-75')]
${export_cve_btn} //button[contains(.,'Export CVEs')]
${export_cve_filter_repo_input} //*[@id='repo']
${export_cve_filter_tag_input} //*[@id='tag']
${export_cve_filter_cveid_input} //*[@id='ids']
${export_btn} //clr-modal//button[contains(.,'EXPORT')]

View File

@ -60,9 +60,12 @@ Select Filter Label Model
Retry Element Click ${filter_label_model_select}//option[contains(.,'${type}')]
Select Filter Label
[Arguments] ${label}
[Arguments] @{labels}
Retry Element Click ${filter_label_xpath}
Retry Element Click //div[@class='filterSelect ng-star-inserted'][3]//label[contains(text(), '${label}')]
FOR ${label} IN @{labels}
Log ${label}
Retry Element Click //div[@class='filterSelect ng-star-inserted'][3]//label[contains(text(), '${label}')]
END
Retry Element Click ${filter_label_xpath}
Select Bandwidth Unit

View File

@ -173,6 +173,7 @@ Retry Wait Until Page Contains
[Arguments] ${element_xpath}
@{param} Create List ${element_xpath}
Retry Action Keyword Wait Until Page Contains @{param}
Retry Wait Until Page Does Not Contains
[Arguments] ${element_xpath}
@{param} Create List ${element_xpath}

View File

@ -989,3 +989,58 @@ Test Case - Audit Log Forward
Verify Log ${HARBOR_ADMIN} project${d}/${image}:${tag2} tag delete
Verify Log In File ${HARBOR_ADMIN} project${d}/${image}:${tag2} artifact create
Close Browser
Test Case - Export CVE
[Tags] export_cve
Init Chrome Driver
${d}= Get Current Date result_format=%m%s
${user}= Set Variable user023
${pwd}= Set Variable Test1@34
&{images}= Create Dictionary nginx=1.14.0 redis=5.0 alpine=3.9.4 photon=4.0-20210226 postgres=9.6
${labels}= Create List sys_level_export${d} proj_level_export${d}
${cve_ids}= Create List CVE-2019-18224 CVE-2021-3997 CVE-2022-25315
${nginx_sha256}= Set Variable sha256:d43aa3719937f9df0502f8258f3034a21b720b5b9bbf01bbfdbd09871aac8930
${redis_sha256}= Set Variable sha256:e4b315ad03a1d1d9ff0c111e648a1a91066c09ead8352d3d6a48fa971a82922c
${expected_cve_data}= Create List project${d}/nginx,${nginx_sha256},${cve_ids}[1],libudev1,232-25+deb9u4,,Medium,,"{""CVSS"": {""redhat"": {""V3Score"": 5.5, ""V3Vector"": ""CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H""}}}",Trivy
... project${d}/nginx,${nginx_sha256},${cve_ids}[1],libsystemd0,232-25+deb9u4,,Medium,,"{""CVSS"": {""redhat"": {""V3Score"": 5.5, ""V3Vector"": ""CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H""}}}",Trivy
... project${d}/redis,${redis_sha256},${cve_ids}[0],libidn2-0,2.0.5-1,2.0.5-1+deb10u1,Critical,CWE-787,"{""CVSS"": {""nvd"": {""V2Score"": 7.5, ""V3Score"": 9.8, ""V2Vector"": ""AV:N/AC:L/Au:N/C:P/I:P/A:P"", ""V3Vector"": ""CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H""}, ""redhat"": {""V3Score"": 5.6, ""V3Vector"": ""CVSS:3.0/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L""}}}",Trivy
... project${d}/redis,${redis_sha256},${cve_ids}[1],libudev1,241-7~deb10u2,,Medium,,"{""CVSS"": {""redhat"": {""V3Score"": 5.5, ""V3Vector"": ""CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H""}}}",Trivy
... project${d}/nginx,${nginx_sha256},${cve_ids}[2],libexpat1,2.2.0-2+deb9u1,2.2.0-2+deb9u5,Critical,CWE-190,"{""CVSS"": {""nvd"": {""V2Score"": 7.5, ""V3Score"": 9.8, ""V2Vector"": ""AV:N/AC:L/Au:N/C:P/I:P/A:P"", ""V3Vector"": ""CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H""}, ""redhat"": {""V3Score"": 9.8, ""V3Vector"": ""CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H""}}}",Trivy
... project${d}/redis,${redis_sha256},${cve_ids}[1],libsystemd0,241-7~deb10u2,,Medium,,"{""CVSS"": {""redhat"": {""V3Score"": 5.5, ""V3Vector"": ""CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H""}}}",Trivy
Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD}
Switch To System Labels
Create New Labels ${labels}[0]
Logout Harbor
Sign In Harbor ${HARBOR_URL} ${user} ${pwd}
Create An New Project And Go Into Project project${d}
# push images
FOR ${image} IN @{images.keys()}
Push Image With Tag ${ip} ${user} ${pwd} project${d} ${image} ${images['${image}']} ${images['${image}']}
END
# scan images
Refresh Repositories
FOR ${image} IN @{images.keys()}
Go Into Repo ${image}
Scan Repo ${images['${image}']} Succeed
Back Project Home project${d}
END
Switch To Project Label
Create New Labels ${labels}[1]
Switch To Project Repo
Go Into Repo nginx
Add Labels To Tag ${images['nginx']} ${labels}[0]
Back Project Home project${d}
Go Into Repo redis
Add Labels To Tag ${images['redis']} ${labels}[1]
Navigate To Projects
Should Not Be Export CVEs
Retry Element Click //clr-dg-row[1]//label
Retry Element Click //clr-dg-row[2]//label
Should Not Be Export CVEs
Export CVEs project${d} photon,postgres,nginx,redis ${images['photon']},${images['nginx']},${images['redis']} ${labels} ${cve_ids}[0],${cve_ids}[1],${cve_ids}[2]
${csv_file_path}= Download Latest CVE CSV File
${csv_file}= OperatingSystem.Get File ${csv_file_path}
${csv_file_content}= Create List ${csv_file}
${actual_cve_data}= Split To Lines @{csv_file_content} 1
Lists Should Be Equal ${expected_cve_data} ${actual_cve_data} ignore_order=True
Close Browser