Skip to content

Commit

Permalink
fix: test robot account permission (#20241)
Browse files Browse the repository at this point in the history
Signed-off-by: Shengwen Yu <yshengwen@vmware.com>
  • Loading branch information
zyyw committed Apr 8, 2024
1 parent a823845 commit 1a741cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions api/v2.0/swagger.yaml
Expand Up @@ -1226,6 +1226,8 @@ paths:
description: Successfully get scan log file
schema:
type: string
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'403':
Expand Down
12 changes: 9 additions & 3 deletions tests/apitests/python/test_project_permission.py
Expand Up @@ -91,7 +91,7 @@ def call(self):
# 6. Resource scan actions: ['read', 'create', 'stop']
create_scan = Permission("{}/projects/{}/repositories/{}/artifacts/{}/scan".format(harbor_base_url, project_name, source_artifact_name, source_artifact_tag), "POST", 202)
stop_scan = Permission("{}/projects/{}/repositories/{}/artifacts/{}/scan/stop".format(harbor_base_url, project_name, source_artifact_name, source_artifact_tag), "POST", 202)
read_scan = Permission("{}/projects/{}/repositories/{}/artifacts/{}/scan/0/log".format(harbor_base_url, project_name, source_artifact_name, source_artifact_tag), "get", 404)
read_scan = Permission("{}/projects/{}/repositories/{}/artifacts/{}/scan/83be44fd-1234-5678-b49f-4b6d6e8f5730/log".format(harbor_base_url, project_name, source_artifact_name, source_artifact_tag), "get", 404)

# 7. Resource tag actions: ['list', 'create', 'delete']
tag_payload = { "name": "test-{}".format(int(random.randint(1000, 9999))) }
Expand Down Expand Up @@ -249,16 +249,22 @@ def call(self):
"log": [list_log],
"notification-policy": [create_webhook, list_webhook, read_webhook, update_webhook, list_webhook_executions, list_webhook_executions_tasks, read_webhook_executions_tasks, list_webhook_events, delete_webhook]
}
resource_permissions["all"] = [item for sublist in resource_permissions.values() for item in sublist]


def main():
global resources # Declare resources as a global variable

if str(resources) == "all":
resources = ','.join(str(key) for key in resource_permissions.keys())

for resource in resources.split(","):
for permission in resource_permissions[resource]:
print("=================================================")
print("call: {} {}".format(permission.method, permission.url))
print("payload: {}".format(json.dumps(permission.payload)))
print("response: {}".format(permission.call().text))
resp = permission.call()
print("response: {}".format(resp.text))
print("response status code: {}".format(resp.status_code))
print("=================================================\n")


Expand Down

0 comments on commit 1a741cb

Please sign in to comment.