mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 02:35:17 +01:00
Add audit log and log rotation test cases (#17465)
1. Add audit log test case 2. Add log rotation test case 3. Add log rotation schedule test case Signed-off-by: Yang Jiao <jiaoya@vmware.com> Signed-off-by: Yang Jiao <jiaoya@vmware.com>
This commit is contained in:
parent
c3e98c8848
commit
0ec167a7c1
58
tests/resources/Harbor-Pages/Log_Rotation.robot
Normal file
58
tests/resources/Harbor-Pages/Log_Rotation.robot
Normal file
@ -0,0 +1,58 @@
|
||||
# Copyright Project Harbor Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License
|
||||
|
||||
*** Settings ***
|
||||
Documentation This resource provides any keywords related to the Harbor private registry appliance
|
||||
|
||||
*** Keywords ***
|
||||
Switch To Log Rotation
|
||||
Retry Element Click //clr-main-container//clr-vertical-nav-group//span[contains(.,'Clean Up')]
|
||||
Retry Element Click ${log_rotation_page_xpath}
|
||||
|
||||
Purge Now
|
||||
[Arguments] ${keep_records} ${keep_records_unit} ${expected_status}=SUCCESS ${exclude_operations}=@{EMPTY}
|
||||
Retry Text Input ${keep_records_input} ${keep_records}
|
||||
Retry Double Keywords When Error Retry Element Click ${keep_records_unit_select} Retry Element Click ${keep_records_unit_select}//option[contains(.,'${keep_records_unit}')]
|
||||
${len}= Get Length ${exclude_operations}
|
||||
Run Keyword If ${len} > 0 Click Exclude Operation @{exclude_operations}
|
||||
Retry Double Keywords When Error Retry Button Click ${purge_now_btn} Retry Wait Until Page Contains Element ${latest_purge_job_status_xpath}\[contains(.,'SUCCESS')]
|
||||
Retry Action Keyword Verify Last completed Time
|
||||
|
||||
Click Exclude Operation
|
||||
[Arguments] @{exclude_operations}
|
||||
FOR ${element} IN @{exclude_operations}
|
||||
Retry Element Click //form//div//label[contains(.,'${element}')]
|
||||
END
|
||||
|
||||
Verify Last completed Time
|
||||
${latest_purge_job_update_time}= Get Text ${latest_purge_job_update_time_xpath}
|
||||
${purge_job_last_completed_time}= Get Text ${purge_job_last_completed_time_xpath}
|
||||
Should Be Equal ${latest_purge_job_update_time} ${purge_job_last_completed_time}
|
||||
|
||||
Set Log Rotation Schedule
|
||||
[Arguments] ${keep_records} ${keep_records_unit} ${type} ${cron}=${null} ${exclude_operations}=@{EMPTY}
|
||||
Retry Text Input ${keep_records_input} ${keep_records}
|
||||
Retry Double Keywords When Error Retry Element Click ${keep_records_unit_select} Retry Element Click ${keep_records_unit_select}//option[contains(.,'${keep_records_unit}')]
|
||||
Retry Button Click ${log_rotation_schedule_edit_btn}
|
||||
Retry Double Keywords When Error Retry Element Click ${log_rotation_schedule_select} Retry Element Click ${log_rotation_schedule_select}//option[contains(.,'${type}')]
|
||||
Run Keyword If '${type}' == 'Custom' Retry Text Input ${log_rotation_schedule_cron_input} ${cron}
|
||||
${len}= Get Length ${exclude_operations}
|
||||
Run Keyword If ${len} > 0 Click Exclude Operation @{exclude_operations}
|
||||
Retry Double Keywords When Error Retry Button Click ${log_rotation_schedule_save_btn} Retry Wait Until Page Contains Purge schedule has been reset
|
||||
|
||||
Get Purge Job Results
|
||||
${cmd}= Set Variable curl -u ${HARBOR_ADMIN}:${HARBOR_PASSWORD} -s --insecure -H "Content-Type: application/json" -X GET "https://${ip}/api/v2.0/system/purgeaudit?sort=-creation_time&page=1&page_size=100"
|
||||
${rc} ${output}= Run And Return Rc And Output ${cmd}
|
||||
Log ${output}
|
||||
[Return] ${output}
|
29
tests/resources/Harbor-Pages/Log_Rotation_Elements.robot
Normal file
29
tests/resources/Harbor-Pages/Log_Rotation_Elements.robot
Normal file
@ -0,0 +1,29 @@
|
||||
# Copyright Project Harbor Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License
|
||||
|
||||
*** Settings ***
|
||||
Documentation This resource provides any keywords related to the Harbor private registry appliance
|
||||
|
||||
*** Variables ***
|
||||
${log_rotation_page_xpath} //app-clearing-job//nav//a[contains(.,'Log Rotation')]
|
||||
${keep_records_input} //*[@id='retentionTime']
|
||||
${keep_records_unit_select} //*[@id='expiration-type']
|
||||
${latest_purge_job_status_xpath} //app-purge-history//div//clr-dg-row[1]//clr-dg-cell[4]
|
||||
${latest_purge_job_update_time_xpath} //app-purge-history//div//clr-dg-row[1]//clr-dg-cell[6]
|
||||
${purge_job_last_completed_time_xpath} //app-set-job//div//span[contains(@class,'mr-3')]
|
||||
${purge_now_btn} //app-set-job//button[contains(.,'PURGE NOW')]
|
||||
${log_rotation_schedule_edit_btn} //*[@id='editSchedule']
|
||||
${log_rotation_schedule_select} //*[@id='selectPolicy']
|
||||
${log_rotation_schedule_save_btn} //*[@id='config-save']
|
||||
${log_rotation_schedule_cron_input} //*[@id='targetCron']
|
36
tests/resources/Harbor-Pages/Logs.robot
Normal file
36
tests/resources/Harbor-Pages/Logs.robot
Normal file
@ -0,0 +1,36 @@
|
||||
# Copyright Project Harbor Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License
|
||||
|
||||
*** Settings ***
|
||||
Documentation This resource provides any keywords related to the Harbor private registry appliance
|
||||
Resource ../../resources/Util.robot
|
||||
|
||||
*** Keywords ***
|
||||
Switch To Logs
|
||||
Retry Element Click ${logs_xpath}
|
||||
|
||||
Refresh Logs
|
||||
Retry Element Click ${logs_refresh_btn}
|
||||
|
||||
Verify Log
|
||||
[Arguments] ${username} ${resource} ${resource_type} ${operation} ${row_num}=1
|
||||
Refresh Logs
|
||||
${real_username}= Get Text //clr-datagrid//clr-dg-row[${row_num}]//clr-dg-cell[1]
|
||||
${real_resource}= Get Text //clr-datagrid//clr-dg-row[${row_num}]//clr-dg-cell[2]
|
||||
${real_resource_type}= Get Text //clr-datagrid//clr-dg-row[${row_num}]//clr-dg-cell[3]
|
||||
${real_operation}= Get Text //clr-datagrid//clr-dg-row[${row_num}]//clr-dg-cell[4]
|
||||
Should Be Equal ${real_username} ${username}
|
||||
Should Be Equal ${real_resource} ${resource}
|
||||
Should Be Equal ${real_resource_type} ${resource_type}
|
||||
Should Be Equal ${real_operation} ${operation}
|
20
tests/resources/Harbor-Pages/Logs_Elements.robot
Normal file
20
tests/resources/Harbor-Pages/Logs_Elements.robot
Normal file
@ -0,0 +1,20 @@
|
||||
# Copyright Project Harbor Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License
|
||||
|
||||
*** Settings ***
|
||||
Documentation This resource provides any keywords related to the Harbor private registry appliance
|
||||
|
||||
*** Variables ***
|
||||
${logs_xpath} //clr-main-container//clr-vertical-nav//a[contains(.,'Logs')]
|
||||
${logs_refresh_btn} //hbr-log//span[contains(@class,'refresh-btn')]
|
@ -61,10 +61,6 @@ Switch To Member
|
||||
Retry Element Click xpath=${project_member_xpath}
|
||||
Sleep 1
|
||||
|
||||
Switch To Log
|
||||
Retry Element Click xpath=${log_xpath}
|
||||
Sleep 1
|
||||
|
||||
Switch To Replication
|
||||
Retry Element Click xpath=${project_replication_xpath}
|
||||
Sleep 1
|
||||
|
@ -20,7 +20,6 @@ ${create_project_button_xpath} //clr-main-container//button[contains(., 'New Pr
|
||||
${project_name_xpath} //*[@id='create_project_name']
|
||||
${project_public_xpath} //input[@name='public']/..//label
|
||||
${project_save_css} html body.no-scrolling harbor-app harbor-shell clr-main-container.main-container div.content-container div.content-area.content-area-override project div.row div.col-lg-12.col-md-12.col-sm-12.col-xs-12 div.row.flex-items-xs-between div.option-left create-project clr-modal div.modal div.modal-dialog div.modal-content div.modal-footer button.btn.btn-primary
|
||||
${log_xpath} //clr-main-container//clr-vertical-nav//a[contains(.,'Logs')]
|
||||
${projects_xpath} //clr-main-container//clr-vertical-nav//a[contains(.,'Projects')]
|
||||
${project_replication_xpath} //project-detail//a[contains(.,'Replication')]
|
||||
${project_log_xpath} //project-detail//a[contains(.,'Logs')]
|
||||
|
@ -44,9 +44,8 @@ Filter Object
|
||||
Sleep 3
|
||||
|
||||
Filter Project
|
||||
#Filter project repo user tag.
|
||||
[Arguments] ${kw}
|
||||
Retry Element Click ${log_xpath}
|
||||
Retry Element Click ${logs_xpath}
|
||||
Retry Element Click ${projects_xpath}
|
||||
Filter Object ${kw}
|
||||
|
||||
|
@ -27,7 +27,7 @@ Change Password
|
||||
Retry Text Input ${new_password_xpath} ${new_pw}
|
||||
Retry Text Input ${renew_password_xpath} ${new_pw}
|
||||
Retry Element Click ${change_password_confirm_btn_xpath}
|
||||
Retry Element Click xpath=${log_xpath}
|
||||
Retry Element Click xpath=${logs_xpath}
|
||||
Sleep 1
|
||||
|
||||
Update User Comment
|
||||
|
@ -67,6 +67,10 @@ Resource Harbor-Pages/OIDC_Auth.robot
|
||||
Resource Harbor-Pages/OIDC_Auth_Elements.robot
|
||||
Resource Harbor-Pages/Robot_Account.robot
|
||||
Resource Harbor-Pages/Robot_Account_Elements.robot
|
||||
Resource Harbor-Pages/Logs.robot
|
||||
Resource Harbor-Pages/Logs_Elements.robot
|
||||
Resource Harbor-Pages/Log_Rotation.robot
|
||||
Resource Harbor-Pages/Log_Rotation_Elements.robot
|
||||
Resource Harbor-Pages/Verify.robot
|
||||
Resource Docker-Util.robot
|
||||
Resource CNAB_Util.robot
|
||||
|
@ -266,7 +266,7 @@ Test Case - User View Projects
|
||||
Create An New Project And Go Into Project test${d}1
|
||||
Create An New Project And Go Into Project test${d}2
|
||||
Create An New Project And Go Into Project test${d}3
|
||||
Switch To Log
|
||||
Switch To Logs
|
||||
Wait Until Page Contains test${d}1
|
||||
Wait Until Page Contains test${d}2
|
||||
Wait Until Page Contains test${d}3
|
||||
@ -834,6 +834,7 @@ Test Case - WASM Push And Pull To Harbor
|
||||
Wait Unitl Command Success wasm-to-oci pull ${ip}/project${d}/wasm-to-oci:v1 --out test.wasm
|
||||
Wait Unitl Command Success docker logout ${ip}
|
||||
Retry file should exist test.wasm
|
||||
Close Browser
|
||||
|
||||
Test Case - Carvel Imgpkg Push And Pull To Harbor
|
||||
[Tags] imgpkg_push_and_pull
|
||||
@ -853,6 +854,7 @@ Test Case - Carvel Imgpkg Push And Pull To Harbor
|
||||
Docker Logout ${ip}
|
||||
Retry File Should Exist ${out_path}/.imgpkg/bundle.yml
|
||||
Retry File Should Exist ${out_path}/.imgpkg/images.yml
|
||||
Close Browser
|
||||
|
||||
Test Case - Cosign And Cosign Deployment Security Policy
|
||||
[Tags] cosign
|
||||
@ -882,3 +884,61 @@ Test Case - Cosign And Cosign Deployment Security Policy
|
||||
Pull image ${ip} ${user} ${pwd} project${d} ${image}:${tag}
|
||||
|
||||
Retry Double Keywords When Error Delete Accessory ${tag} Should be Accessory deleted ${tag}
|
||||
Close Browser
|
||||
|
||||
Test Case - Audit Log And Purge
|
||||
[Tags] audit_log_and_purge
|
||||
Init Chrome Driver
|
||||
${user}= Set Variable user003
|
||||
${pwd}= Set Variable Test1@34
|
||||
${d}= Get Current Date result_format=%m%s
|
||||
${image}= Set Variable alpine
|
||||
${tag1}= Set Variable 3.10
|
||||
${tag2}= Set Variable test
|
||||
${sha256}= Set Variable sha256:de78803598bc4c940fc4591d412bffe488205d5d953f94751c6308deeaaa7eb8
|
||||
Sign In Harbor ${HARBOR_URL} ${user} ${pwd}
|
||||
# create project
|
||||
Create An New Project And Go Into Project project${d}
|
||||
Switch To Logs
|
||||
Verify Log ${user} project${d} project create
|
||||
# create artifact
|
||||
Push Image With Tag ${ip} ${user} ${pwd} project${d} ${image} ${tag1} ${tag1}
|
||||
Clean All Local Images
|
||||
Refresh Logs
|
||||
Verify Log ${user} project${d}/${image}:${tag1} artifact create
|
||||
Go Into Project project${d}
|
||||
Go Into Repo ${image}
|
||||
Go Into Artifact ${tag1}
|
||||
# create tag
|
||||
Add A New Tag ${tag2}
|
||||
# delete tag
|
||||
Delete A Tag ${tag2}
|
||||
Switch To Logs
|
||||
Verify Log ${user} project${d}/${image}:${tag2} tag delete
|
||||
Verify Log ${user} project${d}/${image}:${tag2} tag create 2
|
||||
Docker Login ${ip} ${user} ${pwd}
|
||||
# pull artifact
|
||||
Docker Pull ${ip}/project${d}/${image}:${tag1}
|
||||
Docker Logout ${ip}
|
||||
Verify Log ${user} project${d}/${image}:${sha256} artifact pull
|
||||
Go Into Project project${d}
|
||||
Go Into Repo project${d}/${image}
|
||||
# delete artifact
|
||||
@{tag_list} Create List ${tag1}
|
||||
Multi-delete Artifact @{tag_list}
|
||||
Switch To Logs
|
||||
Verify Log ${user} project${d}/${image}:${sha256} artifact delete
|
||||
Go Into Project project${d}
|
||||
# delete repository
|
||||
Delete Repo project${d} ${image}
|
||||
Switch To Logs
|
||||
Verify Log ${user} project${d}/${image} repository delete
|
||||
# delete project
|
||||
Delete Project project${d}
|
||||
Logout Harbor
|
||||
Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD}
|
||||
Switch To Logs
|
||||
Verify Log ${user} project${d} project delete
|
||||
Switch To Log Rotation
|
||||
Purge Now 1 Hours
|
||||
Close Browser
|
@ -229,3 +229,30 @@ Test Case - P2P Preheat Schedule Job
|
||||
Delete A P2P Preheat Policy ${policy_name}
|
||||
Delete A Distribution ${dist_name} ${DISTRIBUTION_ENDPOINT}
|
||||
Close Browser
|
||||
|
||||
Test Case - Log Rotation Schedule Job
|
||||
[Tags] log_rotation_schedule
|
||||
Init Chrome Driver
|
||||
Sign In Harbor ${HARBOR_URL} ${HARBOR_ADMIN} ${HARBOR_PASSWORD}
|
||||
Switch To Log Rotation
|
||||
${exclude_operations} Create List Pull
|
||||
Set Log Rotation Schedule 2 Days Custom 0 */2 * * * * ${exclude_operations}
|
||||
Sleep 480
|
||||
Set Log Rotation Schedule 2 Days None
|
||||
Sleep 180
|
||||
${logs}= Get Purge Job Results
|
||||
${logs}= Replace String ${logs} "{ { count=-1
|
||||
${logs}= Replace String ${logs} }" } count=-1
|
||||
${logs}= Evaluate json.loads("""${logs}""") json
|
||||
${len}= Get Length ${logs}
|
||||
FOR ${log} IN @{logs}
|
||||
Log ${log}
|
||||
Should Be Equal As Strings ${log["job_name"]} PURGE_AUDIT_LOG
|
||||
Should Be Equal As Strings ${log["job_kind"]} SCHEDULE
|
||||
Should Be Equal As Strings ${log["job_status"]} Success
|
||||
Should Be Equal As Strings ${log["job_parameters"]["audit_retention_hour"]} 48
|
||||
Should Be Equal As Strings ${log["job_parameters"]["dry_run"]} False
|
||||
Should Not Contain Any ${log["job_parameters"]["include_operations"]} @{exclude_operations} ignore_case=True
|
||||
END
|
||||
Should Be True ${len} > 3 and ${len} < 6
|
||||
Close Browser
|
Loading…
Reference in New Issue
Block a user