Skip to content

Commit

Permalink
Update Robot Account Test Case
Browse files Browse the repository at this point in the history
Update project and system robot account testcase
Update system robot account do replication testcase

Signed-off-by: Yang Jiao <jiaoya@vmware.com>
  • Loading branch information
Yang Jiao committed Dec 14, 2023
1 parent 2532ffe commit 340d6f4
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 73 deletions.
12 changes: 6 additions & 6 deletions tests/apitests/python/test_project_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ def call(self):
create_tag_retention_rule = Permission("{}/retentions".format(harbor_base_url), "POST", 201, tag_retention_rule_payload, "id", id_from_header=True)
read_tag_retention = Permission("{}/retentions/{}".format(harbor_base_url, ID_PLACEHOLDER), "GET", 200, tag_retention_rule_payload, payload_id_field="id")
update_tag_retention = Permission("{}/retentions/{}".format(harbor_base_url, ID_PLACEHOLDER), "PUT", 200, tag_retention_rule_payload, payload_id_field="id")
execute_tag_retention = Permission("{}/retentions/888/executions".format(harbor_base_url), "POST", 400, tag_retention_rule_payload, payload_id_field="id")
execute_tag_retention = Permission("{}/retentions/88888888/executions".format(harbor_base_url), "POST", 400, tag_retention_rule_payload, payload_id_field="id")
list_tag_retention_execution = Permission("{}/retentions/{}/executions".format(harbor_base_url, ID_PLACEHOLDER), "GET", 200, tag_retention_rule_payload, payload_id_field="id")
tag_retention_rule_payload["action"] = "stop"
stop_tag_retention = Permission("{}/retentions/{}/executions/888".format(harbor_base_url, ID_PLACEHOLDER), "PATCH", 404, tag_retention_rule_payload, payload_id_field="id")
list_tag_retention_tasks = Permission("{}/retentions/{}/executions/888/tasks".format(harbor_base_url, ID_PLACEHOLDER), "GET", 404, tag_retention_rule_payload, payload_id_field="id")
read_tag_retention_tasks = Permission("{}/retentions/{}/executions/888/tasks/888".format(harbor_base_url, ID_PLACEHOLDER), "GET", 404, tag_retention_rule_payload, payload_id_field="id")
stop_tag_retention = Permission("{}/retentions/{}/executions/88888888".format(harbor_base_url, ID_PLACEHOLDER), "PATCH", 404, tag_retention_rule_payload, payload_id_field="id")
list_tag_retention_tasks = Permission("{}/retentions/{}/executions/88888888/tasks".format(harbor_base_url, ID_PLACEHOLDER), "GET", 404, tag_retention_rule_payload, payload_id_field="id")
read_tag_retention_tasks = Permission("{}/retentions/{}/executions/88888888/tasks/88888888".format(harbor_base_url, ID_PLACEHOLDER), "GET", 404, tag_retention_rule_payload, payload_id_field="id")
delete_tag_retention = Permission("{}/retentions/{}".format(harbor_base_url, ID_PLACEHOLDER), "DELETE", 200, tag_retention_rule_payload, payload_id_field="id")

# 16. Resource log actions: ['list']
Expand Down Expand Up @@ -226,8 +226,8 @@ def call(self):
read_webhook = Permission("{}/projects/{}/webhook/policies/{}".format(harbor_base_url, project_id, ID_PLACEHOLDER), "GET", 200, webhook_payload, payload_id_field="id")
update_webhook = Permission("{}/projects/{}/webhook/policies/{}".format(harbor_base_url, project_id, ID_PLACEHOLDER), "PUT", 200, webhook_payload, payload_id_field="id")
list_webhook_executions = Permission("{}/projects/{}/webhook/policies/{}/executions".format(harbor_base_url, project_id, ID_PLACEHOLDER), "GET", 200, webhook_payload, payload_id_field="id")
list_webhook_executions_tasks = Permission("{}/projects/{}/webhook/policies/{}/executions/888/tasks".format(harbor_base_url, project_id, ID_PLACEHOLDER), "GET", 404, webhook_payload, payload_id_field="id")
read_webhook_executions_tasks = Permission("{}/projects/{}/webhook/policies/{}/executions/888/tasks/888/log".format(harbor_base_url, project_id, ID_PLACEHOLDER), "GET", 404, webhook_payload, payload_id_field="id")
list_webhook_executions_tasks = Permission("{}/projects/{}/webhook/policies/{}/executions/88888888/tasks".format(harbor_base_url, project_id, ID_PLACEHOLDER), "GET", 404, webhook_payload, payload_id_field="id")
read_webhook_executions_tasks = Permission("{}/projects/{}/webhook/policies/{}/executions/88888888/tasks/88888888/log".format(harbor_base_url, project_id, ID_PLACEHOLDER), "GET", 404, webhook_payload, payload_id_field="id")
list_webhook_events = Permission("{}/projects/{}/webhook/events".format(harbor_base_url, project_id), "GET", 200)
delete_webhook = Permission("{}/projects/{}/webhook/policies/{}".format(harbor_base_url, project_id, ID_PLACEHOLDER), "DELETE", 200, webhook_payload, payload_id_field="id")

Expand Down
45 changes: 44 additions & 1 deletion tests/apitests/python/test_system_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,47 @@ def call(self):
read_catalog = Permission("{}/v2/_catalog".format(endpoint_URL), "GET", 200)
# catalog permissions end

# garbage-collection permissions start
gc_payload = {
"parameters": {
"delete_untagged": True,
"workers": 1,
"dry_run": True
},
"schedule": {
"type": "Manual"
}
}
create_gc = Permission("{}/system/gc/schedule".format(harbor_base_url), "POST", 201, gc_payload, "id", id_from_header=True)
list_gc = Permission("{}/system/gc".format(harbor_base_url), "GET", 200)
read_gc = Permission("{}/system/gc/{}".format(harbor_base_url, ID_PLACEHOLDER), "GET", 200, payload=gc_payload, payload_id_field="id")
stop_gc = Permission("{}/system/gc/{}".format(harbor_base_url, ID_PLACEHOLDER), "PUT", 200, payload=gc_payload, payload_id_field="id")
read_gc_log = Permission("{}/system/gc/{}/log".format(harbor_base_url, "88888888"), "GET", 404)
read_gc_schedule = Permission("{}/system/gc/schedule".format(harbor_base_url), "GET", 200)
update_gc_schedule = Permission("{}/system/gc/schedule".format(harbor_base_url), "PUT", 200, gc_payload)
# garbage-collection permissions end

# purge-audit permissions start
purge_audit_payload = {
"parameters": {
"audit_retention_hour": 24,
"include_operations": "create,delete,pull",
"dry_run": True
},
"schedule": {
"type": "Manual"
}
}
create_purge_audit = Permission("{}/system/purgeaudit/schedule".format(harbor_base_url), "POST", 201, purge_audit_payload, "id", id_from_header=True)
list_purge_audit = Permission("{}/system/purgeaudit".format(harbor_base_url), "GET", 200)
read_purge_audit = Permission("{}/system/purgeaudit/{}".format(harbor_base_url, ID_PLACEHOLDER), "GET", 200, payload=purge_audit_payload, payload_id_field="id")
stop_purge_audit = Permission("{}/system/purgeaudit/{}".format(harbor_base_url, ID_PLACEHOLDER), "PUT", 200, payload=purge_audit_payload, payload_id_field="id")
read_purge_audit_log = Permission("{}/system/purgeaudit/{}/log".format(harbor_base_url, "88888888"), "GET", 404)
read_purge_audit_schedule = Permission("{}/system/purgeaudit/schedule".format(harbor_base_url), "GET", 200)
update_purge_audit_schedule = Permission("{}/system/purgeaudit/schedule".format(harbor_base_url), "PUT", 200, purge_audit_payload)
# purge-audit permissions end


resource_permissions = {
"audit-log": [list_audit_logs],
"preheat-instance": [create_preheat_instance, list_preheat_instance, read_preheat_instance, update_preheat_instance, delete_preheat_instance],
Expand All @@ -302,7 +343,9 @@ def call(self):
"scanner": [list_scanner, create_scanner, ping_scanner, read_scanner, update_scanner, delete_scanner, set_default_scanner, get_scanner_metadata],
"label": [create_label, read_label, update_label, delete_label],
"security-hub": [read_summary, list_vul],
"catalog": [read_catalog]
"catalog": [read_catalog],
"garbage-collection": [create_gc, list_gc, read_gc, stop_gc, read_gc_log, read_gc_schedule, update_gc_schedule],
"purge-audit": [create_purge_audit, list_purge_audit, read_purge_audit, stop_purge_audit, read_purge_audit_log, read_purge_audit_schedule, update_purge_audit_schedule]
}
resource_permissions["all"] = [item for sublist in resource_permissions.values() for item in sublist]

Expand Down
62 changes: 51 additions & 11 deletions tests/resources/Harbor-Pages/Project_Robot_Account.robot
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,56 @@ Switch To Project Robot Account
Retry Element Click ${project_robot_account_tabpage}
Retry Wait Until Page Contains Element ${project_robot_account_create_btn}

Create A Robot Account And Return Token
[Arguments] ${projectname} ${robot_account_name} ${project_has_image}=${false}
Go Into Project ${projectname} has_image=${project_has_image}
Switch To Project Robot Account
Retry Element Click ${project_robot_account_create_btn}
Retry Text Input ${project_robot_account_create_name_input} ${robot_account_name}
Retry Element Click xpath=//select[@id='expiration-type']
Retry Element Click xpath=//select[@id='expiration-type']//option[@value='never']
Retry Double Keywords When Error Retry Element Click ${project_robot_account_create_save_btn} Retry Wait Until Page Not Contains Element ${project_robot_account_create_save_btn}
${token}= Get Value ${project_robot_account_token_input}
[Return] ${token}
Create A Project Robot Account
[Arguments] ${robot_account_name} ${expiration_type} ${description}=${null} ${days}=${null} ${resources}=${null}
Retry Element Click ${project_robot_account_create_btn}
Retry Wait Element Should Be Disabled //button[text()='Next']
Retry Text Input ${project_robot_account_create_name_input} ${robot_account_name}
Run Keyword If '${description}' != '${null}' Retry Text Input //textarea ${description}
Select From List By Value ${project_robot_account_create_sexpiration_type_btn} ${expiration_type}
Run Keyword If '${expiration_type}' == 'days' Retry Text Input ${project_robot_account_token_expiration_days} ${days}
Retry Double Keywords When Error Retry Button Click //button[text()='Next'] Retry Wait Element Not Visible //button[text()='Next']
Retry Wait Element Should Be Disabled ${project_robot_account_create_finish_btn}
${first_resource}= Set Variable ${resources}[0]
${permission_count}= Create Dictionary
${total}= Set Variable 0
IF '${first_resource}' == 'all'
Set To Dictionary ${permission_count} all=55
${total}= Set Variable 55
Retry Element Click //span[text()='Select all']
ELSE
FOR ${item} IN @{resources}
${elements}= Get WebElements //table//tr[./td[text()='${item}']]//label
${elements_count}= Get Length ${elements}
Set To Dictionary ${permission_count} ${item}=${elements_count}
${total}= Evaluate ${total} + ${elements_count}
FOR ${element} IN @{elements}
Retry Element Click ${element}
END
END
END
Retry Double Keywords When Error Retry Element Click ${project_robot_account_create_finish_btn} Retry Wait Until Page Not Contains Element ${project_robot_account_create_finish_btn}
${robot_account_name}= Get Text ${project_robot_account_name_xpath}
${token}= Get Value ${project_robot_account_token_input}
Retry Element Click //hbr-copy-input//clr-icon
IF '${days}' == '${null}'
${expires}= Set Variable Never Expires
ELSE
${days}= Evaluate ${days} - 1
${expires}= Set Variable ${days}d 23h
END
Retry Wait Element Visible //clr-dg-row[.//clr-dg-cell[contains(.,'${robot_account_name}')] and .//clr-icon[contains(@class, 'color-green')] and .//button[text()=' ${total} PERMISSION(S) '] and .//span[contains(.,'${expires}')] and .//clr-dg-cell[text()='${description}'] ]
[Return] ${robot_account_name} ${token} ${permission_count}

Check Project Robot Account Permission
[Arguments] ${robot_account_name} ${permission_count}
Retry Button Click //clr-dg-row[.//clr-dg-cell[contains(., '${robot_account_name}')]]//button
FOR ${key} IN @{permission_count.keys()}
Retry Wait Element Count //table//tr[./td[text()=' ${key} ']]//label ${permission_count['${key}']}
END
Retry Double Keywords When Error Retry Button Click //button[@aria-label='Close'] Retry Wait Until Page Not Contains Element //button[@aria-label='Close']

Check Project Robot Account API Permission
[Arguments] ${robot_account_name} ${token} ${admin_user_name} ${admin_password} ${project_id} ${project_name} ${source_artifact_name} ${source_artifact_tag} ${resources} ${expected_status}=0
${rc} ${output}= Run And Return Rc And Output USER_NAME='${robot_account_name}' PASSWORD='${token}' ADMIN_USER_NAME=${admin_user_name} ADMIN_PASSWORD=${admin_password} HARBOR_BASE_URL=https://${ip}/api/v2.0 PROJECT_ID=${project_id} PROJECT_NAME=${project_name} SOURCE_ARTIFACT_NAME=${source_artifact_name} SOURCE_ARTIFACT_TAG=${source_artifact_tag} RESOURCES=${resources} python ./tests/apitests/python/test_project_permission.py
Should Be Equal As Integers ${rc} ${expected_status}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ Documentation This resource provides any keywords related to the Harbor robot-a
${project_robot_account_tabpage} xpath=//project-detail//a[contains(.,'Robot Accounts')]
${project_robot_account_create_btn} xpath=//project-detail/app-robot-account//button
${project_robot_account_token_input} xpath=//app-robot-account//hbr-copy-input//input
${project_robot_account_name_xpath} //view-token//div[contains(@class,'robot-name')]//span
${project_robot_account_create_name_input} //input[@id='name']
${project_robot_account_create_save_btn} //button[@id='system-robot-save']
${project_robot_account_create_finish_btn} //button[text()='Finish']
${project_robot_account_create_sexpiration_type_btn} //select[@id='expiration-type']
${project_robot_account_token_expiration_days} //*[@id='robotTokenExpiration']
53 changes: 21 additions & 32 deletions tests/resources/Harbor-Pages/Robot_Account.robot
Original file line number Diff line number Diff line change
Expand Up @@ -86,40 +86,29 @@ Select Project Permission
Capture Page Screenshot
END

Create A New System Robot Account
[Arguments] ${name}=${null} ${expiration_type}=default ${expiration_value}=${null} ${description}=${null} ${is_cover_all}=${false} ${cover_all_permission_list}=@{EMPTY} ${project_permission_list}=@{EMPTY}
${d}= Get Current Date result_format=%m%s
${name}= Set Variable If '${name}'=='${null}' robot_name${d} ${name}
Switch To Robot Account
Retry Double Keywords When Error Retry Element Click ${new_sys_robot_account_btn} Retry Wait Until Page Contains Element ${sys_robot_account_name_input}
Retry Text Input ${sys_robot_account_name_input} ${name}
Run Keyword If '${expiration_type}' != 'default' Run Keywords Retry Element Click xpath=${sys_robot_account_expiration_type_select} AND
... Retry Element Click xpath=${sys_robot_account_expiration_type_select}//option[@value='${expiration_type}']
Create A System Robot Account
[Arguments] ${robot_account_name} ${expiration_type} ${description}=${null} ${days}=${null} ${cover_all_system_resources}=${null} ${cover_all_project_resources}=${null}
Retry Element Click ${new_sys_robot_account_btn}
Retry Wait Element Should Be Disabled //button[text()='Next']
Retry Text Input ${sys_robot_account_name_input} ${robot_account_name}
Run Keyword If '${description}' != '${null}' Retry Text Input ${sys_robot_account_description_textarea} ${description}
Run Keyword If '${is_cover_all}' == '${true}' Retry Double Keywords When Error Retry Element Click ${sys_robot_account_coverall_chb} Retry Checkbox Should Be Selected ${sys_robot_account_coverall_chb_input}
... ELSE Clear Global Permissions By JavaScript
Select From List By Value ${sys_robot_account_expiration_type_select} ${expiration_type}
Run Keyword If '${expiration_type}' == 'days' Retry Text Input ${sys_robot_account_expiration_input} ${days}
Retry Button Click //button[text()='Next']
Retry Wait Element Should Be Disabled ${project_robot_account_create_finish_btn}
Run Keyword If '${cover_all_system_resources}' == '${true}' Retry Element Click //*[@id='clr-wizard-page-1']//span[text()='Select all']
Retry Double Keywords When Error Retry Button Click //button[text()='Next'] Retry Wait Element Not Visible //button[text()='Next']
Run Keyword If '${cover_all_project_resources}' == '${true}' Run Keywords Retry Element Click ${sys_robot_account_coverall_chb} AND Retry Element Click //*[@id='clr-wizard-page-2']//span[text()='Select all']
Retry Double Keywords When Error Retry Element Click ${project_robot_account_create_finish_btn} Retry Wait Element Not Visible ${project_robot_account_create_finish_btn}
${robot_account_name}= Get Text ${project_robot_account_name_xpath}
${token}= Get Value //hbr-copy-input//input
Retry Element Click //hbr-copy-input//clr-icon
[Return] ${robot_account_name} ${token}

# Select project
FOR ${project} IN @{project_permission_list}
Log To Console project: ${project}
Should Be True type($project) is not dict
${tmp} = Convert To Dictionary ${project}
Should Be True type($tmp) is dict
${project_name}= Get From Dictionary ${tmp} project_name
Log To Console project_name: ${project_name}
${permission_item_list}= Get From Dictionary ${tmp} permission_item_list
Log To Console permission_item_list: ${permission_item_list}
Filter Project In Project Permisstion List ${project_name}
Retry Element Click //clr-dg-row[contains(.,'${project_name}')]//div[contains(@class,'clr-checkbox-wrapper')]/label[contains(@class,'clr-control-label')]
Retry Element Click //clr-dg-row[contains(., '${project_name}')]//clr-dropdown/button
Select Project Permission ${project_name} ${permission_item_list}
END
# Save it
Retry Double Keywords When Error Retry Element Click ${save_sys_robot_account_btn} Retry Wait Until Page Not Contains Element ${save_sys_robot_account_btn}
Retry Double Keywords When Error Retry Element Click ${save_sys_robot_export_to_file_btn} Retry Wait Until Page Not Contains Element ${save_sys_robot_export_to_file_btn}
# Get Robot Account Info
${id} ${name} ${secret} ${creation_time} ${expires_at}= Get Robot Account Info By File ${download_directory}/robot$${name}.json
[Return] ${name} ${secret}
Check System Robot Account API Permission
[Arguments] ${robot_account_name} ${token} ${admin_user_name} ${admin_password} ${resources} ${expected_status}=0
${rc} ${output}= Run And Return Rc And Output USER_NAME='${robot_account_name}' PASSWORD='${token}' ADMIN_USER_NAME=${admin_user_name} ADMIN_PASSWORD=${admin_password} HARBOR_BASE_URL=https://${ip}/api/v2.0 RESOURCES=${resources} python ./tests/apitests/python/test_system_permission.py
Should Be Equal As Integers ${rc} ${expected_status}

System Robot Account Exist
[Arguments] ${name} ${project_count}
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/Harbor-Pages/Robot_Account_Elements.robot
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ${sys_robot_account_name_input} //*[@id='name']
${sys_robot_account_expiration_type_select} //*[@id='expiration-type']
${sys_robot_account_expiration_input} //*[@id='robotTokenExpiration']
${sys_robot_account_description_textarea} //*[@id='description']
${sys_robot_account_coverall_chb_input} xpath=//input[@id='coverAll']
${sys_robot_account_coverall_chb_input} //input[@id='coverAll']
${sys_robot_account_coverall_chb} //clr-checkbox-wrapper[contains(@class, 'clr-checkbox-wrapper')]/label[contains(@class,'clr-control-label') and contains(@for, 'coverAll')]
${sys_robot_account_permission_list_btn} //form/section//clr-dropdown/button
${save_sys_robot_account_btn} //*[@id='system-robot-save']
Expand Down
Loading

0 comments on commit 340d6f4

Please sign in to comment.