2020-03-28 04:29:28 +01:00
from __future__ import absolute_import
import unittest
2020-11-04 03:13:12 +01:00
from testutils import harbor_server , suppress_urllib3_warning
2020-03-28 04:29:28 +01:00
from testutils import admin_user
from testutils import admin_pwd
from testutils import TEARDOWN
from testutils import ADMIN_CLIENT
from library . system import System
from library . project import Project
from library . user import User
from library . repository import Repository
2020-12-04 11:28:29 +01:00
from library . repository import push_self_build_image_to_project
2020-03-28 04:29:28 +01:00
from library . artifact import Artifact
from library . scanner import Scanner
2020-08-07 08:56:18 +02:00
from library . docker_api import list_image_tags
from library . docker_api import list_repositories
2020-03-28 04:29:28 +01:00
import os
import library . base
import json
class TestProjects ( unittest . TestCase ) :
2020-11-04 03:13:12 +01:00
@suppress_urllib3_warning
2020-03-28 04:29:28 +01:00
def setUp ( self ) :
self . system = System ( )
self . project = Project ( )
self . user = User ( )
self . artifact = Artifact ( )
self . repo = Repository ( )
@unittest.skipIf ( TEARDOWN == False , " Test data won ' t be erased. " )
2020-11-04 03:13:12 +01:00
def tearDown ( self ) :
2020-03-28 04:29:28 +01:00
#1. Delete Alice's repository and Luca's repository;
2021-01-16 12:34:43 +01:00
self . repo . delete_repository ( TestProjects . project_Alice_name , TestProjects . repo_a . split ( ' / ' ) [ 1 ] , * * ADMIN_CLIENT )
self . repo . delete_repository ( TestProjects . project_Alice_name , TestProjects . repo_b . split ( ' / ' ) [ 1 ] , * * ADMIN_CLIENT )
self . repo . delete_repository ( TestProjects . project_Alice_name , TestProjects . repo_c . split ( ' / ' ) [ 1 ] , * * ADMIN_CLIENT )
2020-03-28 04:29:28 +01:00
#2. Delete Alice's project and Luca's project;
self . project . delete_project ( TestProjects . project_Alice_id , * * ADMIN_CLIENT )
#3. Delete user Alice and Luca.
self . user . delete_user ( TestProjects . user_Alice_id , * * ADMIN_CLIENT )
def testRegistryAPI ( self ) :
"""
Test case :
Catalog API to list all repositories by system admin
Test step and expected result : G
1. Create user Alice ;
2. Create 1 new private projects project_Alice ;
3. Push 3 images to project_Alice and Add 3 tags to the 3 rd image
4. Call the image_list_tag API
5. Call the catalog API using admin account without pagination , can get all 3 images
5.1 Call the catalog API using admin account with pagination n = 1 , page = 2 , twice to get all 3 images .
5.2 Call the catalog API using Alice account , no repos should be found .
Tear down :
1. Delete Alice ' s repository;
2. Delete Alice ' s project;
3. Delete user Alice .
"""
url = ADMIN_CLIENT [ " endpoint " ]
user_common_password = " Aa123456 "
#1. Create user Alice and Luca;
TestProjects . user_Alice_id , user_Alice_name = self . user . create_user ( user_password = user_common_password , * * ADMIN_CLIENT )
USER_ALICE_CLIENT = dict ( endpoint = url , username = user_Alice_name , password = user_common_password )
#2. Create 2 new private projects project_Alice and project_Luca;
TestProjects . project_Alice_id , TestProjects . project_Alice_name = self . project . create_project ( metadata = { " public " : " false " } , * * USER_ALICE_CLIENT )
#3. Push 3 images to project_Alice and Add 3 tags to the 3rd image.
src_tag = " latest "
Upgrade docker and containerd
1. Fix E2E quotas issue, push the same image but with different name;
2. Add checkpoint for robot account test;
3. Upgraded docker and containerd in E2E image;
4. Package base image sample(busybox) into E2E image, so in E2E
container, all local docker images can be cleaned up, once base image is needed for
building image, it can be loaded locally;
5. Adapt OIDC service of supporting LDAP user, and add OIDC group user
test;
6. Restart docker deamon before content trust test, both in API and UI
test;
7. Add retry for keyword "Add A Tag Immutability Rule";
8. Fix tag retention test issue, missing click angle icon, and enhance
checkpoint of dry run and real run;
9. Fix schedule test issue for wrong cron string;
10. Disable quotas verification, it's not stable for script defect;
Signed-off-by: danfengliu <danfengl@vmware.com>
2021-01-29 08:52:21 +01:00
image_a = " image_a "
2020-12-04 11:28:29 +01:00
TestProjects . repo_a , tag_a = push_self_build_image_to_project ( TestProjects . project_Alice_name , harbor_server , user_Alice_name , user_common_password , image_a , src_tag )
Upgrade docker and containerd
1. Fix E2E quotas issue, push the same image but with different name;
2. Add checkpoint for robot account test;
3. Upgraded docker and containerd in E2E image;
4. Package base image sample(busybox) into E2E image, so in E2E
container, all local docker images can be cleaned up, once base image is needed for
building image, it can be loaded locally;
5. Adapt OIDC service of supporting LDAP user, and add OIDC group user
test;
6. Restart docker deamon before content trust test, both in API and UI
test;
7. Add retry for keyword "Add A Tag Immutability Rule";
8. Fix tag retention test issue, missing click angle icon, and enhance
checkpoint of dry run and real run;
9. Fix schedule test issue for wrong cron string;
10. Disable quotas verification, it's not stable for script defect;
Signed-off-by: danfengliu <danfengl@vmware.com>
2021-01-29 08:52:21 +01:00
image_b = " image_b "
2020-12-04 11:28:29 +01:00
TestProjects . repo_b , tag_b = push_self_build_image_to_project ( TestProjects . project_Alice_name , harbor_server , user_Alice_name , user_common_password , image_b , src_tag )
Upgrade docker and containerd
1. Fix E2E quotas issue, push the same image but with different name;
2. Add checkpoint for robot account test;
3. Upgraded docker and containerd in E2E image;
4. Package base image sample(busybox) into E2E image, so in E2E
container, all local docker images can be cleaned up, once base image is needed for
building image, it can be loaded locally;
5. Adapt OIDC service of supporting LDAP user, and add OIDC group user
test;
6. Restart docker deamon before content trust test, both in API and UI
test;
7. Add retry for keyword "Add A Tag Immutability Rule";
8. Fix tag retention test issue, missing click angle icon, and enhance
checkpoint of dry run and real run;
9. Fix schedule test issue for wrong cron string;
10. Disable quotas verification, it's not stable for script defect;
Signed-off-by: danfengliu <danfengl@vmware.com>
2021-01-29 08:52:21 +01:00
image_c = " image_c "
2020-12-04 11:28:29 +01:00
TestProjects . repo_c , tag_c = push_self_build_image_to_project ( TestProjects . project_Alice_name , harbor_server , user_Alice_name , user_common_password , image_c , src_tag )
2020-03-28 04:29:28 +01:00
create_tags = [ " 1.0 " , " 2.0 " , " 3.0 " ]
for tag in create_tags :
Upgrade docker and containerd
1. Fix E2E quotas issue, push the same image but with different name;
2. Add checkpoint for robot account test;
3. Upgraded docker and containerd in E2E image;
4. Package base image sample(busybox) into E2E image, so in E2E
container, all local docker images can be cleaned up, once base image is needed for
building image, it can be loaded locally;
5. Adapt OIDC service of supporting LDAP user, and add OIDC group user
test;
6. Restart docker deamon before content trust test, both in API and UI
test;
7. Add retry for keyword "Add A Tag Immutability Rule";
8. Fix tag retention test issue, missing click angle icon, and enhance
checkpoint of dry run and real run;
9. Fix schedule test issue for wrong cron string;
10. Disable quotas verification, it's not stable for script defect;
Signed-off-by: danfengliu <danfengl@vmware.com>
2021-01-29 08:52:21 +01:00
self . artifact . create_tag ( TestProjects . project_Alice_name , image_c , tag_c , tag , * * USER_ALICE_CLIENT )
2020-03-28 04:29:28 +01:00
#4. Call the image_list_tags API
2020-08-07 08:56:18 +02:00
tags = list_image_tags ( harbor_server , TestProjects . repo_c , user_Alice_name , user_common_password )
for tag in create_tags :
2020-03-28 04:29:28 +01:00
self . assertTrue ( tags . count ( tag ) > 0 , " Expect tag: %s is not listed " % tag )
2020-08-07 08:56:18 +02:00
page_tags = list_image_tags ( harbor_server , TestProjects . repo_c , user_Alice_name , user_common_password , len ( tags ) / 2 + 1 )
page_tags + = list_image_tags ( harbor_server , TestProjects . repo_c , user_Alice_name , user_common_password , len ( tags ) / 2 + 1 , tags [ int ( len ( tags ) / 2 ) ] )
for tag in create_tags :
2020-03-28 04:29:28 +01:00
self . assertTrue ( page_tags . count ( tag ) > 0 , " Expect tag: %s is not listed by the pagination query " % tag )
#5. Call the catalog API;
2020-08-07 08:56:18 +02:00
repos = list_repositories ( harbor_server , admin_user , admin_pwd )
self . assertTrue ( repos . count ( TestProjects . repo_a ) > 0 and repos . count ( TestProjects . repo_b ) > 0 and repos . count ( TestProjects . repo_c ) > 0 , " Expected repo not found " )
2020-03-28 04:29:28 +01:00
for repo in [ TestProjects . repo_a , TestProjects . repo_b , TestProjects . repo_c ] :
self . assertTrue ( repos . count ( repo ) > 0 , " Expected repo: %s is not listed " % repo )
2020-08-07 08:56:18 +02:00
page_repos = list_repositories ( harbor_server , admin_user , admin_pwd , len ( repos ) / 2 + 1 )
page_repos + = list_repositories ( harbor_server , admin_user , admin_pwd , len ( repos ) / 2 + 1 , repos [ int ( len ( repos ) / 2 ) ] )
2020-03-28 04:29:28 +01:00
for repo in [ TestProjects . repo_a , TestProjects . repo_b , TestProjects . repo_c ] :
self . assertTrue ( page_repos . count ( repo ) > 0 , " Expected repo: %s is not listed by the pagination query " % repo )
2020-08-07 08:56:18 +02:00
null_repos = list_repositories ( harbor_server , user_Alice_name , user_common_password )
2020-03-28 04:29:28 +01:00
self . assertEqual ( null_repos , " " )
if __name__ == ' __main__ ' :
unittest . main ( )