From 87631678f2e20a785b01ee3febf8e63e291ecaa2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fl=C3=A1vio=20Ramalho?= <framalho@suse.com>
Date: Fri, 18 Dec 2020 14:58:51 +0100
Subject: [PATCH] Tests: support pulling images from specific repository
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This change adds support for pulling images that are used for the
tests from an specific repository instead of pulling from them from
DockerHub.

Signed-off-by: Flávio Ramalho <framalho@suse.com>
---
 tests/apitests/python/library/docker_api.py   |  7 ++++--
 .../python/test_add_sys_label_to_tag.py       | 10 +++++---
 .../python/test_assign_role_to_ldap_group.py  | 12 +++++----
 .../test_copy_artifact_outside_project.py     | 12 ++++++---
 .../apitests/python/test_create_delete_tag.py |  3 +++
 tests/apitests/python/test_del_repo.py        |  8 ++++--
 .../python/test_manage_project_member.py      |  8 ++++--
 ...test_project_level_policy_content_trust.py |  7 ++++--
 tests/apitests/python/test_project_quota.py   |  8 +++---
 .../apitests/python/test_push_cnab_bundle.py  |  8 +++++-
 .../test_push_image_with_special_name.py      | 10 +++++---
 .../test_push_index_by_docker_manifest.py     |  4 +++
 .../python/test_push_sif_by_singularity.py    |  3 +++
 tests/apitests/python/test_registry_api.py    | 23 +++++++++++------
 tests/apitests/python/test_robot_account.py   | 14 ++++++++---
 .../python/test_scan_image_artifact.py        | 15 +++++++----
 ...t_scan_image_artifact_in_public_project.py |  5 +++-
 tests/apitests/python/test_sign_image.py      |  9 ++++---
 .../python/test_system_level_scan_all.py      | 25 +++++++++----------
 tests/apitests/python/test_tag_crud.py        |  3 +++
 tests/apitests/python/test_user_view_logs.py  |  8 ++++--
 tests/apitests/python/testutils.py            |  1 +
 22 files changed, 139 insertions(+), 64 deletions(-)

diff --git a/tests/apitests/python/library/docker_api.py b/tests/apitests/python/library/docker_api.py
index be8013613..45be15d9a 100644
--- a/tests/apitests/python/library/docker_api.py
+++ b/tests/apitests/python/library/docker_api.py
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 
 import base
+import os
 import subprocess
 import json
 from testutils import DOCKER_USER, DOCKER_PWD
@@ -167,11 +168,13 @@ class DockerAPI(object):
     def docker_image_build(self, harbor_registry, tags=None, size=1, expected_error_message = None):
         ret = ""
         try:
-            baseimage='busybox:latest'
+            base_img_repository = os.environ.get("HARBOR_TEST_IMAGES_REPOSITORY", "")
+            baseimage = os.path.join(base_img_repository, "library/busybox:latest")
+
             self.DCLIENT.login(username=DOCKER_USER, password=DOCKER_PWD)
             if not self.DCLIENT.images(name=baseimage):
                 self.DCLIENT.pull(baseimage)
-            c=self.DCLIENT.create_container(image='busybox:latest',command='dd if=/dev/urandom of=test bs=1M count=%d' % size )
+            c=self.DCLIENT.create_container(image=baseimage,command='dd if=/dev/urandom of=test bs=1M count=%d' % size )
             self.DCLIENT.start(c)
             self.DCLIENT.wait(c)
             if not tags:
diff --git a/tests/apitests/python/test_add_sys_label_to_tag.py b/tests/apitests/python/test_add_sys_label_to_tag.py
index a0373a2d1..b80ee2c6b 100644
--- a/tests/apitests/python/test_add_sys_label_to_tag.py
+++ b/tests/apitests/python/test_add_sys_label_to_tag.py
@@ -5,6 +5,7 @@ import unittest
 from testutils import harbor_server, suppress_urllib3_warning
 from testutils import TEARDOWN
 from testutils import ADMIN_CLIENT
+from testutils import IMAGES_REPOSITORY
 from library.artifact import Artifact
 from library.project import Project
 from library.user import User
@@ -24,7 +25,7 @@ class TestProjects(unittest.TestCase):
     @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
     def tearDown(self):
         #1. Delete repository(RA) by user(UA);
-        self.repo.delete_repoitory(TestProjects.project_add_g_lbl_name, TestProjects.repo_name.split('/')[1], **TestProjects.USER_add_g_lbl_CLIENT)
+        self.repo.delete_repoitory(TestProjects.project_add_g_lbl_name, TestProjects.repo_name.split('/', 1)[1], **TestProjects.USER_add_g_lbl_CLIENT)
 
         #2. Delete project(PA);
         self.project.delete_project(TestProjects.project_add_g_lbl_id, **TestProjects.USER_add_g_lbl_CLIENT)
@@ -55,6 +56,9 @@ class TestProjects(unittest.TestCase):
         """
         url = ADMIN_CLIENT["endpoint"]
         user_001_password = "Aa123456"
+        image = "hello-world"
+        if IMAGES_REPOSITORY:
+            image = r"{}/library/{}".format(IMAGES_REPOSITORY, image)
 
         #1. Create user-001
         TestProjects.user_add_g_lbl_id, user_add_g_lbl_name = self.user.create_user(user_password = user_001_password, **ADMIN_CLIENT)
@@ -72,13 +76,13 @@ class TestProjects(unittest.TestCase):
             expected_project_id = TestProjects.project_add_g_lbl_id, **TestProjects.USER_add_g_lbl_CLIENT)
 
         #5. Create a new repository(RA) and tag(TA) in project(PA) by user(UA);
-        TestProjects.repo_name, tag = push_image_to_project(TestProjects.project_add_g_lbl_name, harbor_server, user_add_g_lbl_name, user_001_password, "hello-world", "latest")
+        TestProjects.repo_name, tag = push_image_to_project(TestProjects.project_add_g_lbl_name, harbor_server, user_add_g_lbl_name, user_001_password, image, "latest")
 
         #6. Create a new label(LA) in project(PA) by admin;
         TestProjects.label_id, _ = self.label.create_label(**ADMIN_CLIENT)
 
         #7. Add this system global label to repository(RA)/tag(TA).
-        self.artifact.add_label_to_reference(TestProjects.project_add_g_lbl_name, TestProjects.repo_name.split('/')[1], tag, int(TestProjects.label_id), **TestProjects.USER_add_g_lbl_CLIENT)
+        self.artifact.add_label_to_reference(TestProjects.project_add_g_lbl_name, TestProjects.repo_name.split('/', 1)[1], tag, int(TestProjects.label_id), **TestProjects.USER_add_g_lbl_CLIENT)
 
 if __name__ == '__main__':
     unittest.main()
diff --git a/tests/apitests/python/test_assign_role_to_ldap_group.py b/tests/apitests/python/test_assign_role_to_ldap_group.py
index f15bf2a6f..0fa9182c4 100644
--- a/tests/apitests/python/test_assign_role_to_ldap_group.py
+++ b/tests/apitests/python/test_assign_role_to_ldap_group.py
@@ -4,6 +4,7 @@ import unittest
 from testutils import harbor_server, suppress_urllib3_warning
 from testutils import TEARDOWN
 from testutils import ADMIN_CLIENT
+from testutils import IMAGES_REPOSITORY
 from testutils import created_user, created_project
 from library.project import Project
 from library.user import User
@@ -44,9 +45,10 @@ class TestAssignRoleToLdapGroup(unittest.TestCase):
             9. Delete project(PA);
         """
         url = ADMIN_CLIENT["endpoint"]
-        USER_ADMIN=dict(endpoint = url, username = "admin_user", password = "zhu88jie", repo = "hello-world")
-        USER_DEV=dict(endpoint = url, username = "dev_user", password = "zhu88jie", repo = "alpine")
-        USER_GUEST=dict(endpoint = url, username = "guest_user", password = "zhu88jie", repo = "busybox")
+        repo = r"{}/library/".format(IMAGES_REPOSITORY) if IMAGES_REPOSITORY else ""
+        USER_ADMIN=dict(endpoint = url, username = "admin_user", password = "zhu88jie", repo = r"{}hello-world".format(repo))
+        USER_DEV=dict(endpoint = url, username = "dev_user", password = "zhu88jie", repo = r"{}alpine".format(repo))
+        USER_GUEST=dict(endpoint = url, username = "guest_user", password = "zhu88jie", repo = r"{}busybox".format(repo))
         USER_TEST=dict(endpoint = url, username = "test", password = "123456")
         USER_MIKE=dict(endpoint = url, username = "mike", password = "zhu88jie")
         #USER001 is in group harbor_group3
@@ -85,8 +87,8 @@ class TestAssignRoleToLdapGroup(unittest.TestCase):
             self.assertTrue(self.project.query_user_logs(project_name, **USER_GUEST)>0, "guest user can see logs")
             self.assertTrue(self.project.query_user_logs(project_name, status_code=403, **USER_TEST)==0, "test user can not see any logs")
 
-            self.repo.delete_repoitory(project_name, repo_name_admin.split('/')[1], **USER_ADMIN)
-            self.repo.delete_repoitory(project_name, repo_name_dev.split('/')[1], **USER_ADMIN)
+            self.repo.delete_repoitory(project_name, repo_name_admin.split('/', 1)[1], **USER_ADMIN)
+            self.repo.delete_repoitory(project_name, repo_name_dev.split('/', 1)[1], **USER_ADMIN)
 
 if __name__ == '__main__':
     unittest.main()
\ No newline at end of file
diff --git a/tests/apitests/python/test_copy_artifact_outside_project.py b/tests/apitests/python/test_copy_artifact_outside_project.py
index 8f3d282d0..03a5be209 100644
--- a/tests/apitests/python/test_copy_artifact_outside_project.py
+++ b/tests/apitests/python/test_copy_artifact_outside_project.py
@@ -6,6 +6,7 @@ import unittest
 from testutils import ADMIN_CLIENT, suppress_urllib3_warning
 from testutils import harbor_server
 from testutils import TEARDOWN
+from testutils import IMAGES_REPOSITORY
 from library.base import _assert_status_code
 from library.artifact import Artifact
 from library.project import Project
@@ -25,10 +26,10 @@ class TestProjects(unittest.TestCase):
     @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
     def tearDown(self):
         #1. Delete repository(RA);
-        self.repo.delete_repoitory(TestProjects.project_src_repo_name, (TestProjects.src_repo_name).split('/')[1], **TestProjects.USER_RETAG_CLIENT)
+        self.repo.delete_repoitory(TestProjects.project_src_repo_name, (TestProjects.src_repo_name).split('/', 1)[1], **TestProjects.USER_RETAG_CLIENT)
 
         #2. Delete repository by retag;
-        self.repo.delete_repoitory(TestProjects.project_dst_repo_name, (TestProjects.dst_repo_name).split('/')[1], **TestProjects.USER_RETAG_CLIENT)
+        self.repo.delete_repoitory(TestProjects.project_dst_repo_name, (TestProjects.dst_repo_name).split('/', 1)[1], **TestProjects.USER_RETAG_CLIENT)
 
         #3. Delete project(PA);
         self.project.delete_project(TestProjects.project_src_repo_id, **TestProjects.USER_RETAG_CLIENT)
@@ -65,6 +66,9 @@ class TestProjects(unittest.TestCase):
         user_retag_password = "Aa123456"
         pull_tag_name = "latest"
         dst_repo_sub_name = "repo"
+        image = "hello-world"
+        if IMAGES_REPOSITORY:
+            image = r"{}/library/{}".format(IMAGES_REPOSITORY, image)
 
         #1. Create a new user(UA);
         TestProjects.user_retag_id, user_retag_name = self.user.create_user(user_password = user_retag_password, **ADMIN_CLIENT)
@@ -83,14 +87,14 @@ class TestProjects(unittest.TestCase):
         self.project.update_project_member_role(TestProjects.project_dst_repo_id, retag_member_id, 3, **ADMIN_CLIENT)
 
         #5. Create a new repository(RA) in project(PA) by user(UA);
-        TestProjects.src_repo_name, tag_name = push_image_to_project(TestProjects.project_src_repo_name, harbor_server, 'admin', 'Harbor12345', "hello-world", pull_tag_name)
+        TestProjects.src_repo_name, tag_name = push_image_to_project(TestProjects.project_src_repo_name, harbor_server, 'admin', 'Harbor12345', image, pull_tag_name)
 
         #6. Get repository in project(PA), there should be one repository which was created by user(UA);
         src_repo_data = self.repo.list_repositories(TestProjects.project_src_repo_name, **TestProjects.USER_RETAG_CLIENT)
         _assert_status_code(TestProjects.src_repo_name, src_repo_data[0].name)
 
         #7. Get repository(RA)'s image tag detail information;
-        src_tag_data = self.artifact.get_reference_info(TestProjects.project_src_repo_name, TestProjects.src_repo_name.split('/')[1], tag_name, **TestProjects.USER_RETAG_CLIENT)
+        src_tag_data = self.artifact.get_reference_info(TestProjects.project_src_repo_name, TestProjects.src_repo_name.split('/', 1)[1], tag_name, **TestProjects.USER_RETAG_CLIENT)
         TestProjects.dst_repo_name = TestProjects.project_dst_repo_name+"/"+ dst_repo_sub_name
         #8. Retag image in project(PA) to project(PB), it should be forbidden;
         self.artifact.copy_artifact(TestProjects.project_dst_repo_name, dst_repo_sub_name, TestProjects.src_repo_name+"@"+src_tag_data.digest, expect_status_code=403, **TestProjects.USER_RETAG_CLIENT)
diff --git a/tests/apitests/python/test_create_delete_tag.py b/tests/apitests/python/test_create_delete_tag.py
index 40ced9e64..dcdfe635a 100644
--- a/tests/apitests/python/test_create_delete_tag.py
+++ b/tests/apitests/python/test_create_delete_tag.py
@@ -6,6 +6,7 @@ import unittest
 from testutils import ADMIN_CLIENT
 from testutils import harbor_server
 from testutils import TEARDOWN
+from testutils import IMAGES_REPOSITORY
 import library.repository
 import library.docker_api
 from library.base import _assert_status_code
@@ -26,6 +27,8 @@ class TestProjects(unittest.TestCase):
         self.url = ADMIN_CLIENT["endpoint"]
         self.user_password = "Aa123456"
         self.repo_name = "hello-world"
+        if IMAGES_REPOSITORY:
+            self.repo_name = r"{}/library/{}".format(IMAGES_REPOSITORY, self.repo_name)
 
     @classmethod
     def tearDownClass(self):
diff --git a/tests/apitests/python/test_del_repo.py b/tests/apitests/python/test_del_repo.py
index a6d6cb5c5..be507be36 100644
--- a/tests/apitests/python/test_del_repo.py
+++ b/tests/apitests/python/test_del_repo.py
@@ -6,6 +6,7 @@ import unittest
 from testutils import ADMIN_CLIENT, suppress_urllib3_warning
 from testutils import harbor_server
 from testutils import TEARDOWN
+from testutils import IMAGES_REPOSITORY
 from library.base import _assert_status_code
 from library.project import Project
 from library.user import User
@@ -44,6 +45,9 @@ class TestProjects(unittest.TestCase):
         """
         url = ADMIN_CLIENT["endpoint"]
         user_del_repo_password = "Aa123456"
+        image = "hello-world"
+        if IMAGES_REPOSITORY:
+            image = r"{}/library/{}".format(IMAGES_REPOSITORY, image)
 
         #1. Create a new user(UA);
         TestProjects.user_del_repo_id, user_del_repo_name = self.user.create_user(user_password = user_del_repo_password, **ADMIN_CLIENT)
@@ -54,14 +58,14 @@ class TestProjects(unittest.TestCase):
         TestProjects.project_del_repo_id, TestProjects.project_del_repo_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_del_repo_CLIENT)
 
         #3. Create a new repository(RA) in project(PA) by user(UA);
-        repo_name, _ = push_image_to_project(TestProjects.project_del_repo_name, harbor_server, 'admin', 'Harbor12345', "hello-world", "latest")
+        repo_name, _ = push_image_to_project(TestProjects.project_del_repo_name, harbor_server, 'admin', 'Harbor12345', image, "latest")
 
         #4. Get repository in project(PA), there should be one repository which was created by user(UA);
         repo_data = self.repo.list_repositories(TestProjects.project_del_repo_name, **TestProjects.USER_del_repo_CLIENT)
         _assert_status_code(repo_name, repo_data[0].name)
 
         #5. Delete repository(RA) by user(UA);
-        self.repo.delete_repoitory(TestProjects.project_del_repo_name, repo_name.split('/')[1], **TestProjects.USER_del_repo_CLIENT)
+        self.repo.delete_repoitory(TestProjects.project_del_repo_name, repo_name.split('/', 1)[1], **TestProjects.USER_del_repo_CLIENT)
 
         #6. Get repository by user(UA), it should get nothing;
         repo_data = self.repo.list_repositories(TestProjects.project_del_repo_name, **TestProjects.USER_del_repo_CLIENT)
diff --git a/tests/apitests/python/test_manage_project_member.py b/tests/apitests/python/test_manage_project_member.py
index 19c291fd4..8a04d26f1 100644
--- a/tests/apitests/python/test_manage_project_member.py
+++ b/tests/apitests/python/test_manage_project_member.py
@@ -5,6 +5,7 @@ import unittest
 from testutils import harbor_server, suppress_urllib3_warning
 from testutils import TEARDOWN
 from testutils import ADMIN_CLIENT
+from testutils import IMAGES_REPOSITORY
 from library.project import Project
 from library.user import User
 from library.repository import push_image_to_project
@@ -20,7 +21,7 @@ class TestProjects(unittest.TestCase):
     @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
     def tearDown(self):
         #1. Delete repository(RA) by admin;
-        self.repo.delete_repoitory(TestProjects.project_alice_name, TestProjects.repo_name.split('/')[1], **ADMIN_CLIENT)
+        self.repo.delete_repoitory(TestProjects.project_alice_name, TestProjects.repo_name.split('/', 1)[1], **ADMIN_CLIENT)
 
         #2. Delete project(Alice);
         self.project.delete_project(TestProjects.project_alice_id, **ADMIN_CLIENT)
@@ -54,6 +55,9 @@ class TestProjects(unittest.TestCase):
         user_alice_password = "Aa123456"
         user_bob_password = "Test1@34"
         user_carol_password = "Test1@34"
+        image = "hello-world"
+        if IMAGES_REPOSITORY:
+            image = r"{}/library/{}".format(IMAGES_REPOSITORY, image)
 
         #1.1 Create user Alice
         TestProjects.user_alice_id, user_alice_name = self.user.create_user(user_password = user_alice_password, **ADMIN_CLIENT)
@@ -70,7 +74,7 @@ class TestProjects(unittest.TestCase):
         TestProjects.project_alice_id, TestProjects.project_alice_name = self.project.create_project(metadata = {"public": "false"}, **USER_ALICE_CLIENT)
 
         #2.2 Add a repository to project(PA) by Alice
-        TestProjects.repo_name, _ = push_image_to_project(TestProjects.project_alice_name, harbor_server, user_alice_name, user_alice_password, "hello-world", "latest")
+        TestProjects.repo_name, _ = push_image_to_project(TestProjects.project_alice_name, harbor_server, user_alice_name, user_alice_password, image, "latest")
 
         #3. Bob is not a member of project(PA);
         self.project.check_project_member_not_exist(TestProjects.project_alice_id, user_bob_name, **USER_ALICE_CLIENT)
diff --git a/tests/apitests/python/test_project_level_policy_content_trust.py b/tests/apitests/python/test_project_level_policy_content_trust.py
index e598d3c55..bb04b838f 100644
--- a/tests/apitests/python/test_project_level_policy_content_trust.py
+++ b/tests/apitests/python/test_project_level_policy_content_trust.py
@@ -5,6 +5,7 @@ import unittest
 from testutils import ADMIN_CLIENT, suppress_urllib3_warning
 from testutils import harbor_server
 from testutils import TEARDOWN
+from testutils import IMAGES_REPOSITORY
 from library.artifact import Artifact
 from library.project import Project
 from library.user import User
@@ -23,7 +24,7 @@ class TestProjects(unittest.TestCase):
     @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
     def tearDown(self):
         #1. Delete repository(RA) by user(UA);
-        self.repo.delete_repoitory(TestProjects.project_content_trust_name, TestProjects.repo_name.split('/')[1], **TestProjects.USER_CONTENT_TRUST_CLIENT)
+        self.repo.delete_repoitory(TestProjects.project_content_trust_name, TestProjects.repo_name.split('/', 1)[1], **TestProjects.USER_CONTENT_TRUST_CLIENT)
 
         #2. Delete project(PA);
         self.project.delete_project(TestProjects.project_content_trust_id, **TestProjects.USER_CONTENT_TRUST_CLIENT)
@@ -49,10 +50,12 @@ class TestProjects(unittest.TestCase):
             3. Delete user(UA);
         """
         url = ADMIN_CLIENT["endpoint"]
-        image = "hello-world"
         admin_name = ADMIN_CLIENT["username"]
         admin_password = ADMIN_CLIENT["password"]
         user_content_trust_password = "Aa123456"
+        image = "hello-world"
+        if IMAGES_REPOSITORY:
+            image = r"{}/library/{}".format(IMAGES_REPOSITORY, image)
 
         #1. Create a new user(UA);
         TestProjects.user_content_trust_id, user_content_trust_name = self.user.create_user(user_password = user_content_trust_password, **ADMIN_CLIENT)
diff --git a/tests/apitests/python/test_project_quota.py b/tests/apitests/python/test_project_quota.py
index 6bab2dc98..fe81b0155 100644
--- a/tests/apitests/python/test_project_quota.py
+++ b/tests/apitests/python/test_project_quota.py
@@ -2,7 +2,7 @@ from __future__ import absolute_import
 import unittest
 
 from testutils import harbor_server, created_project, created_user, \
-                      TEARDOWN, ADMIN_CLIENT,suppress_urllib3_warning
+                      IMAGES_REPOSITORY, TEARDOWN, ADMIN_CLIENT,suppress_urllib3_warning
 from library.repository import Repository
 from library.repository import push_image_to_project
 from library.system import System
@@ -45,6 +45,8 @@ class TestProjects(unittest.TestCase):
             with created_project(metadata={"public": "false"}, user_id=user_id) as (project_id, project_name):
                 #4. Push an image to project(PA) by user(UA), then check the project quota usage; -- {"count": 1, "storage": 2791709}
                 image, tag = "goharbor/alpine", "3.10"
+                if IMAGES_REPOSITORY:
+                    image = r"{}/{}".format(IMAGES_REPOSITORY, image)
                 push_image_to_project(project_name, harbor_server, user_name, user_001_password, image, tag)
 
                 #5. Get project quota
@@ -59,11 +61,11 @@ class TestProjects(unittest.TestCase):
                 self.assertEqual(quota[0].used["storage"], 2789002)
 
                 #8. Delete repository(RA) by user(UA);
-                self.repo.delete_repoitory(project_name, "goharbor%2Falpine", **ADMIN_CLIENT)
+                self.repo.delete_repoitory(project_name, image, **ADMIN_CLIENT)
 
                 #9. Quota should be 0
                 quota = self.system.get_project_quota("project", project_id, **ADMIN_CLIENT)
                 self.assertEqual(quota[0].used["storage"], 0)
 
 if __name__ == '__main__':
-    unittest.main()
\ No newline at end of file
+    unittest.main()
diff --git a/tests/apitests/python/test_push_cnab_bundle.py b/tests/apitests/python/test_push_cnab_bundle.py
index 86854394b..c3df25e43 100644
--- a/tests/apitests/python/test_push_cnab_bundle.py
+++ b/tests/apitests/python/test_push_cnab_bundle.py
@@ -6,6 +6,7 @@ import unittest
 from testutils import ADMIN_CLIENT, suppress_urllib3_warning
 from testutils import harbor_server
 from testutils import TEARDOWN
+from testutils import IMAGES_REPOSITORY
 import library.repository
 import library.cnab
 from library.project import Project
@@ -24,6 +25,11 @@ class TestProjects(unittest.TestCase):
         self.user_push_cnab_password = "Aa123456"
         self.cnab_repo_name = "test_cnab"
         self.cnab_tag = "test_cnab_tag"
+        self.alpine_image = "alpine"
+        self.haproxy_image = "haproxy"
+        if IMAGES_REPOSITORY:
+            self.alpine_image = r"{}/library/{}".format(IMAGES_REPOSITORY, self.alpine_image)
+            self.haproxy_image = r"{}/library/{}".format(IMAGES_REPOSITORY, self.haproxy_image)
 
     @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
     def tearDown(self):
@@ -63,7 +69,7 @@ class TestProjects(unittest.TestCase):
 
         #3. Push bundle to harbor as repository(RA);
         target = harbor_server + "/" + TestProjects.project_push_bundle_name  + "/" + self.cnab_repo_name  + ":" + self.cnab_tag
-        reference_sha256 = library.cnab.push_cnab_bundle(harbor_server, user_name, self.user_push_cnab_password, "alpine:latest", "haproxy:latest", target)
+        reference_sha256 = library.cnab.push_cnab_bundle(harbor_server, user_name, self.user_push_cnab_password, r"{}:latest".format(self.alpine_image), r"{}:latest".format(self.haproxy_image), target)
 
         #4. Get repository from Harbor successfully;
         index_data = self.repo.get_repository(TestProjects.project_push_bundle_name, self.cnab_repo_name, **TestProjects.USER_CLIENT)
diff --git a/tests/apitests/python/test_push_image_with_special_name.py b/tests/apitests/python/test_push_image_with_special_name.py
index f7c6a1ce0..7b49ae6a9 100644
--- a/tests/apitests/python/test_push_image_with_special_name.py
+++ b/tests/apitests/python/test_push_image_with_special_name.py
@@ -5,6 +5,7 @@ import urllib
 from testutils import ADMIN_CLIENT, suppress_urllib3_warning
 from testutils import harbor_server
 from testutils import TEARDOWN
+from testutils import IMAGES_REPOSITORY
 from library.sign import sign_image
 from library.artifact import Artifact
 from library.project import Project
@@ -49,6 +50,11 @@ class TestProjects(unittest.TestCase):
         """
         url = ADMIN_CLIENT["endpoint"]
         user_001_password = "Aa123456"
+        image = "hello-world"
+        src_tag = "latest"
+        profix = "aaa/bbb"
+        if IMAGES_REPOSITORY:
+            image = r"{}/library/{}".format(IMAGES_REPOSITORY, image)
 
         #1. Create user-001
         TestProjects.user_sign_image_id, user_sign_image_name = self.user.create_user(user_password = user_001_password, **ADMIN_CLIENT)
@@ -65,10 +71,6 @@ class TestProjects(unittest.TestCase):
         self.project.projects_should_exist(dict(public=False), expected_count = 1,
             expected_project_id = TestProjects.project_sign_image_id, **TestProjects.USER_sign_image_CLIENT)
 
-        image = "hello-world"
-        src_tag = "latest"
-        profix = "aaa/bbb"
-
         #5. Create a new repository(RA) and tag(TA) in project(PA) by user(UA);
         TestProjects.repo_name, tag = push_image_to_project(TestProjects.project_sign_image_name, harbor_server, user_sign_image_name, user_001_password, image, src_tag, profix_for_image=profix)
 
diff --git a/tests/apitests/python/test_push_index_by_docker_manifest.py b/tests/apitests/python/test_push_index_by_docker_manifest.py
index 3a66a1ee0..36878dd5b 100644
--- a/tests/apitests/python/test_push_index_by_docker_manifest.py
+++ b/tests/apitests/python/test_push_index_by_docker_manifest.py
@@ -6,6 +6,7 @@ import unittest
 from testutils import ADMIN_CLIENT, suppress_urllib3_warning
 from testutils import harbor_server
 from testutils import TEARDOWN
+from testutils import IMAGES_REPOSITORY
 import library.repository
 import library.docker_api
 import library.containerd
@@ -30,6 +31,9 @@ class TestProjects(unittest.TestCase):
         self.index_tag = "test_tag"
         self.image_a = "alpine"
         self.image_b = "busybox"
+        if IMAGES_REPOSITORY:
+            self.image_a = r"{}/library/{}".format(IMAGES_REPOSITORY, self.image_a)
+            self.image_b = r"{}/library/{}".format(IMAGES_REPOSITORY, self.image_b)
 
     @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
     def tearDown(self):
diff --git a/tests/apitests/python/test_push_sif_by_singularity.py b/tests/apitests/python/test_push_sif_by_singularity.py
index 1be1eda79..414a8b832 100644
--- a/tests/apitests/python/test_push_sif_by_singularity.py
+++ b/tests/apitests/python/test_push_sif_by_singularity.py
@@ -5,6 +5,7 @@ import urllib
 from testutils import ADMIN_CLIENT, suppress_urllib3_warning
 from testutils import harbor_server
 from testutils import TEARDOWN
+from testutils import IMAGES_REPOSITORY
 import library.singularity
 from library.sign import sign_image
 from library.user import User
@@ -22,6 +23,8 @@ class TestProjects(unittest.TestCase):
         self.repo = Repository()
         self.repo_name = "busybox"
         self.tag = "1.28"
+        if IMAGES_REPOSITORY:
+            repo_name = r"{}/library/{}".format(IMAGES_REPOSITORY, repo_name)
 
     @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
     def tearDown(self):
diff --git a/tests/apitests/python/test_registry_api.py b/tests/apitests/python/test_registry_api.py
index 95043c85c..8448cff97 100644
--- a/tests/apitests/python/test_registry_api.py
+++ b/tests/apitests/python/test_registry_api.py
@@ -6,6 +6,7 @@ from testutils import admin_user
 from testutils import admin_pwd
 from testutils import TEARDOWN
 from testutils import ADMIN_CLIENT
+from testutils import IMAGES_REPOSITORY
 from library.system import System
 from library.project import Project
 from library.user import User
@@ -28,13 +29,15 @@ class TestProjects(unittest.TestCase):
         self.artifact = Artifact()
         self.repo = Repository()
         self.repo_name = "hello-world"
+        if IMAGES_REPOSITORY:
+            self.repo_name = r"{}/library/{}".format(IMAGES_REPOSITORY, self.repo_name)
 
     @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
     def tearDown(self):
         #1. Delete Alice's repository and Luca's repository;
-        self.repo.delete_repoitory(TestProjects.project_Alice_name, TestProjects.repo_a.split('/')[1], **ADMIN_CLIENT)
-        self.repo.delete_repoitory(TestProjects.project_Alice_name, TestProjects.repo_b.split('/')[1], **ADMIN_CLIENT)
-        self.repo.delete_repoitory(TestProjects.project_Alice_name, TestProjects.repo_c.split('/')[1], **ADMIN_CLIENT)
+        self.repo.delete_repoitory(TestProjects.project_Alice_name, TestProjects.repo_a.split('/', 1)[1], **ADMIN_CLIENT)
+        self.repo.delete_repoitory(TestProjects.project_Alice_name, TestProjects.repo_b.split('/', 1)[1], **ADMIN_CLIENT)
+        self.repo.delete_repoitory(TestProjects.project_Alice_name, TestProjects.repo_c.split('/', 1)[1], **ADMIN_CLIENT)
 
         #2. Delete Alice's project and Luca's project;
         self.project.delete_project(TestProjects.project_Alice_id, **ADMIN_CLIENT)
@@ -61,6 +64,15 @@ class TestProjects(unittest.TestCase):
         """
         url = ADMIN_CLIENT["endpoint"]
         user_common_password = "Aa123456"
+        image_a = "busybox"
+        image_b = "alpine"
+        image_c = "hello-world"
+        src_tag = "latest"
+        if IMAGES_REPOSITORY:
+            image_a = r"{}/library/{}".format(IMAGES_REPOSITORY, image_a)
+            image_b = r"{}/library/{}".format(IMAGES_REPOSITORY, image_b)
+            image_c = r"{}/library/{}".format(IMAGES_REPOSITORY, image_c)
+
         #1. Create user Alice and Luca;
         TestProjects.user_Alice_id, user_Alice_name = self.user.create_user(user_password = user_common_password, **ADMIN_CLIENT)
 
@@ -70,13 +82,8 @@ class TestProjects(unittest.TestCase):
         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"
-        image_a = "busybox"
         TestProjects.repo_a, tag_a = push_image_to_project(TestProjects.project_Alice_name, harbor_server, user_Alice_name, user_common_password, image_a, src_tag)
-        image_b = "alpine"
         TestProjects.repo_b, tag_b = push_image_to_project(TestProjects.project_Alice_name, harbor_server, user_Alice_name, user_common_password, image_b, src_tag)
-        image_c = "hello-world"
         TestProjects.repo_c, tag_c = push_image_to_project(TestProjects.project_Alice_name, harbor_server, user_Alice_name, user_common_password, image_c, src_tag)
         create_tags = ["1.0","2.0","3.0"]
         for tag in create_tags:
diff --git a/tests/apitests/python/test_robot_account.py b/tests/apitests/python/test_robot_account.py
index 81aa2391d..a7d25503e 100644
--- a/tests/apitests/python/test_robot_account.py
+++ b/tests/apitests/python/test_robot_account.py
@@ -4,6 +4,7 @@ import unittest
 
 from testutils import ADMIN_CLIENT, suppress_urllib3_warning
 from testutils import TEARDOWN
+from testutils import IMAGES_REPOSITORY
 from testutils import harbor_server
 from library.user import User
 from library.project import Project
@@ -26,10 +27,10 @@ class TestProjects(unittest.TestCase):
     @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
     def test_ClearData(self):
         #1. Delete repository(RA) by user(UA);
-        self.repo.delete_repoitory(TestProjects.project_ra_name_a, TestProjects.repo_name_in_project_a.split('/')[1], **TestProjects.USER_RA_CLIENT)
-        self.repo.delete_repoitory(TestProjects.project_ra_name_b, TestProjects.repo_name_in_project_b.split('/')[1], **TestProjects.USER_RA_CLIENT)
-        self.repo.delete_repoitory(TestProjects.project_ra_name_c, TestProjects.repo_name_in_project_c.split('/')[1], **TestProjects.USER_RA_CLIENT)
-        self.repo.delete_repoitory(TestProjects.project_ra_name_a, TestProjects.repo_name_pa.split('/')[1], **TestProjects.USER_RA_CLIENT)
+        self.repo.delete_repoitory(TestProjects.project_ra_name_a, TestProjects.repo_name_in_project_a.split('/', 1)[1], **TestProjects.USER_RA_CLIENT)
+        self.repo.delete_repoitory(TestProjects.project_ra_name_b, TestProjects.repo_name_in_project_b.split('/', 1)[1], **TestProjects.USER_RA_CLIENT)
+        self.repo.delete_repoitory(TestProjects.project_ra_name_c, TestProjects.repo_name_in_project_c.split('/', 1)[1], **TestProjects.USER_RA_CLIENT)
+        self.repo.delete_repoitory(TestProjects.project_ra_name_a, TestProjects.repo_name_pa.split('/', 1)[1], **TestProjects.USER_RA_CLIENT)
 
         #2. Delete project(PA);
         self.project.delete_project(TestProjects.project_ra_id_a, **TestProjects.USER_RA_CLIENT)
@@ -73,6 +74,11 @@ class TestProjects(unittest.TestCase):
         image_project_c = "httpd"
         image_robot_account = "alpine"
         tag = "latest"
+        if IMAGES_REPOSITORY:
+            image_project_a = r"{}/library/{}".format(IMAGES_REPOSITORY, image_project_a)
+            image_project_b = r"{}/library/{}".format(IMAGES_REPOSITORY, image_project_b)
+            image_project_c = r"{}/library/{}".format(IMAGES_REPOSITORY, image_project_c)
+            image_robot_account = r"{}/library/{}".format(IMAGES_REPOSITORY, image_robot_account)
 
         #1. Create user(UA);"
         TestProjects.user_ra_id, user_ra_name = self.user.create_user(user_password = user_ra_password, **ADMIN_CLIENT)
diff --git a/tests/apitests/python/test_scan_image_artifact.py b/tests/apitests/python/test_scan_image_artifact.py
index 8b1301ea0..925befd8e 100644
--- a/tests/apitests/python/test_scan_image_artifact.py
+++ b/tests/apitests/python/test_scan_image_artifact.py
@@ -4,6 +4,7 @@ import sys
 
 from testutils import harbor_server, suppress_urllib3_warning
 from testutils import TEARDOWN
+from testutils import IMAGES_REPOSITORY
 from testutils import ADMIN_CLIENT
 from library.project import Project
 from library.user import User
@@ -38,8 +39,8 @@ class TestScan(unittest.TestCase):
     @unittest.skipIf(TEARDOWN == True, "Test data won't be erased.")
     def do_tearDown(self):
         #1. Delete repository(RA) by user(UA);
-        self.repo.delete_repoitory(self.project_name, self.repo_name1.split('/')[1], **self.USER_CLIENT)
-        self.repo.delete_repoitory(self.project_name, self.repo_name2.split('/')[1], **self.USER_CLIENT)
+        self.repo.delete_repoitory(self.project_name, self.repo_name1.split('/', 1)[1], **self.USER_CLIENT)
+        self.repo.delete_repoitory(self.project_name, self.repo_name2.split('/', 1)[1], **self.USER_CLIENT)
 
         #2. Delete project(PA);
         self.project.delete_project(self.project_id, **self.USER_CLIENT)
@@ -73,12 +74,14 @@ class TestScan(unittest.TestCase):
         #Note: Please make sure that this Image has never been pulled before by any other cases,
         #      so it is a not-scanned image right after repository creation.
         image = "docker"
+        if IMAGES_REPOSITORY:
+            image = r"{}/library/{}".format(IMAGES_REPOSITORY, image)
         src_tag = "1.13"
         #5. Create a new repository(RA) and tag(TA) in project(PA) by user(UA);
         self.repo_name1, tag = push_image_to_project(self.project_name, harbor_server, self.user_name, self.user_password, image, src_tag)
 
         #6. Send scan image command and get tag(TA) information to check scan result, it should be finished;
-        self.scan.scan_artifact(self.project_name, self.repo_name1.split('/')[1], tag, **self.USER_CLIENT)
+        self.scan.scan_artifact(self.project_name, self.repo_name1.split('/', 1)[1], tag, **self.USER_CLIENT)
         self.artifact.check_image_scan_result(self.project_name, image, tag, **self.USER_CLIENT)
 
         self.do_tearDown()
@@ -105,6 +108,8 @@ class TestScan(unittest.TestCase):
         #Note: Please make sure that this Image has never been pulled before by any other cases,
         #      so it is a not-scanned image right after repository creation.
         image = "redis"
+        if IMAGES_REPOSITORY:
+            image = r"{}/library/{}".format(IMAGES_REPOSITORY, image)
         tag = "latest"
         #5. Create a new repository(RA) and tag(TA) in project(PA) by user(UA);
         TestScan.repo_name_1, tag = push_image_to_project(self.project_name, harbor_server, self.user_name, self.user_password, image, tag)
@@ -112,11 +117,11 @@ class TestScan(unittest.TestCase):
         sign_image(harbor_server, self.project_name, image, tag)
 
         #6. Send scan image command and get tag(TA) information to check scan result, it should be finished;
-        self.scan.scan_artifact(self.project_name, TestScan.repo_name_1.split('/')[1], tag, **self.USER_CLIENT)
+        self.scan.scan_artifact(self.project_name, TestScan.repo_name_1.split('/', 1)[1], tag, **self.USER_CLIENT)
         self.artifact.check_image_scan_result(self.project_name, image, tag, **self.USER_CLIENT)
 
 if __name__ == '__main__':
     suite = unittest.TestSuite(unittest.makeSuite(TestScan))
     result = unittest.TextTestRunner(sys.stdout, verbosity=2, failfast=True).run(suite)
     if not result.wasSuccessful():
-        raise Exception(r"Scan test failed: {}".format(result))
+        raise Exception(r"Scan test failed: {}".format(result))
\ No newline at end of file
diff --git a/tests/apitests/python/test_scan_image_artifact_in_public_project.py b/tests/apitests/python/test_scan_image_artifact_in_public_project.py
index 74f72eb18..b31014356 100644
--- a/tests/apitests/python/test_scan_image_artifact_in_public_project.py
+++ b/tests/apitests/python/test_scan_image_artifact_in_public_project.py
@@ -3,6 +3,7 @@ import unittest
 
 from testutils import harbor_server, TEARDOWN, suppress_urllib3_warning
 from testutils import created_user, created_project
+from testutils import IMAGES_REPOSITORY
 from library.artifact import Artifact
 from library.repository import Repository, push_image_to_project
 from library.scan import Scan
@@ -41,9 +42,11 @@ class TestScanImageInPublicProject(unittest.TestCase):
         with created_user(password) as (user_id, username):
             with created_project(metadata={"public": "true"}, user_id=user_id) as (_, project_name):
                 image, src_tag = "docker", "1.13"
+                if IMAGES_REPOSITORY:
+                    image = r"{}/library/{}".format(IMAGES_REPOSITORY, image)
                 full_name, tag = push_image_to_project(project_name, harbor_server, username, password, image, src_tag)
 
-                repo_name = full_name.split('/')[1]
+                repo_name = full_name.split('/', 1)[1]
 
                 # scan image with anonymous user
                 self.scan.scan_artifact(project_name, repo_name, tag, expect_status_code=401, username=None, password=None)
diff --git a/tests/apitests/python/test_sign_image.py b/tests/apitests/python/test_sign_image.py
index 8fa410eb4..0680f763e 100644
--- a/tests/apitests/python/test_sign_image.py
+++ b/tests/apitests/python/test_sign_image.py
@@ -4,6 +4,7 @@ import unittest
 from testutils import ADMIN_CLIENT, suppress_urllib3_warning
 from testutils import harbor_server
 from testutils import TEARDOWN
+from testutils import IMAGES_REPOSITORY
 from library.sign import sign_image
 from library.artifact import Artifact
 from library.project import Project
@@ -50,6 +51,10 @@ class TestProjects(unittest.TestCase):
         """
         url = ADMIN_CLIENT["endpoint"]
         user_001_password = "Aa123456"
+        image = "hello-world"
+        src_tag = "latest"
+        if IMAGES_REPOSITORY:
+            image = r"{}/library/{}".format(IMAGES_REPOSITORY, image)
 
         #1. Create user-001
         TestProjects.user_sign_image_id, user_sign_image_name = self.user.create_user(user_password = user_001_password, **ADMIN_CLIENT)
@@ -66,8 +71,6 @@ class TestProjects(unittest.TestCase):
         self.project.projects_should_exist(dict(public=False), expected_count = 1,
             expected_project_id = TestProjects.project_sign_image_id, **TestProjects.USER_sign_image_CLIENT)
 
-        image = "hello-world"
-        src_tag = "latest"
         #5. Create a new repository(RA) and tag(TA) in project(PA) by user(UA);
         TestProjects.repo_name, tag = push_image_to_project(TestProjects.project_sign_image_name, harbor_server, user_sign_image_name, user_001_password, image, src_tag)
 
@@ -81,7 +84,7 @@ class TestProjects(unittest.TestCase):
         push_special_image_to_project(TestProjects.project_sign_image_name, harbor_server, user_sign_image_name, user_001_password, self.repo_name_1, ['1.0'])
         self.repo.delete_repoitory(TestProjects.project_sign_image_name, self.repo_name_1, **TestProjects.USER_sign_image_CLIENT)
 
-        self.repo.delete_repoitory(TestProjects.project_sign_image_name, TestProjects.repo_name.split('/')[1], expect_status_code=412, expect_response_body = "with signature cannot be deleted", **TestProjects.USER_sign_image_CLIENT)
+        self.repo.delete_repoitory(TestProjects.project_sign_image_name, TestProjects.repo_name.split('/', 1)[1], expect_status_code=412, expect_response_body = "with signature cannot be deleted", **TestProjects.USER_sign_image_CLIENT)
 
 if __name__ == '__main__':
     unittest.main()
diff --git a/tests/apitests/python/test_system_level_scan_all.py b/tests/apitests/python/test_system_level_scan_all.py
index 07acf0909..9d1c0fd6d 100644
--- a/tests/apitests/python/test_system_level_scan_all.py
+++ b/tests/apitests/python/test_system_level_scan_all.py
@@ -4,6 +4,7 @@ import unittest
 from testutils import harbor_server, suppress_urllib3_warning
 from testutils import TEARDOWN
 from testutils import ADMIN_CLIENT
+from testutils import IMAGES_REPOSITORY
 from library.system import System
 from library.project import Project
 from library.user import User
@@ -22,8 +23,8 @@ class TestScanAll(unittest.TestCase):
     @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
     def tearDown(self):
         #1. Delete Alice's repository and Luca's repository;
-        self.repo.delete_repoitory(TestScanAll.project_Alice_name, TestScanAll.repo_Alice_name.split('/')[1], **ADMIN_CLIENT)
-        self.repo.delete_repoitory(TestScanAll.project_Luca_name, TestScanAll.repo_Luca_name.split('/')[1], **ADMIN_CLIENT)
+        self.repo.delete_repoitory(TestScanAll.project_Alice_name, TestScanAll.repo_Alice_name.split('/', 1)[1], **ADMIN_CLIENT)
+        self.repo.delete_repoitory(TestScanAll.project_Luca_name, TestScanAll.repo_Luca_name.split('/', 1)[1], **ADMIN_CLIENT)
 
         #2. Delete Alice's project and Luca's project;
         self.project.delete_project(TestScanAll.project_Alice_id, **ADMIN_CLIENT)
@@ -51,6 +52,14 @@ class TestScanAll(unittest.TestCase):
         """
         url = ADMIN_CLIENT["endpoint"]
         user_common_password = "Aa123456"
+        #Note: Please make sure that those images has never been pulled before by any other cases,
+        #          so it is a not-scanned image rigth after repository creation.
+        image_a = "mariadb"
+        image_b = "httpd"
+        src_tag = "latest"
+        if IMAGES_REPOSITORY:
+            image_a = r"{}/library/{}".format(IMAGES_REPOSITORY, image_a)
+            image_b = r"{}/library/{}".format(IMAGES_REPOSITORY, image_b)
 
         #1. Create user Alice and Luca;
         TestScanAll.user_Alice_id, user_Alice_name = self.user.create_user(user_password = user_common_password, **ADMIN_CLIENT)
@@ -64,19 +73,9 @@ class TestScanAll(unittest.TestCase):
         TestScanAll.project_Luca_id, TestScanAll.project_Luca_name = self.project.create_project(metadata = {"public": "false"}, **USER_LUCA_CLIENT)
 
         #3. Push a image to project_Alice and push another image to project_Luca;
-
-        #Note: Please make sure that this Image has never been pulled before by any other cases,
-        #          so it is a not-scanned image rigth after repository creation.
-        #image = "tomcat"
-        image_a = "mariadb"
-        src_tag = "latest"
         #3.1 Push a image to project_Alice;
         TestScanAll.repo_Alice_name, tag_Alice = push_image_to_project(TestScanAll.project_Alice_name, harbor_server, user_Alice_name, user_common_password, image_a, src_tag)
 
-        #Note: Please make sure that this Image has never been pulled before by any other cases,
-        #          so it is a not-scanned image rigth after repository creation.
-        image_b = "httpd"
-        src_tag = "latest"
         #3.2 push another image to project_Luca;
         TestScanAll.repo_Luca_name, tag_Luca = push_image_to_project(TestScanAll.project_Luca_name, harbor_server, user_Luca_name, user_common_password, image_b, src_tag)
 
@@ -89,4 +88,4 @@ class TestScanAll(unittest.TestCase):
         self.artifact.check_image_scan_result(TestScanAll.project_Luca_name, image_b, tag_Luca, **USER_LUCA_CLIENT)
 
 if __name__ == '__main__':
-    unittest.main()
\ No newline at end of file
+    unittest.main()
diff --git a/tests/apitests/python/test_tag_crud.py b/tests/apitests/python/test_tag_crud.py
index c68729b2a..ac55a5c22 100644
--- a/tests/apitests/python/test_tag_crud.py
+++ b/tests/apitests/python/test_tag_crud.py
@@ -6,6 +6,7 @@ import unittest
 from testutils import ADMIN_CLIENT, suppress_urllib3_warning
 from testutils import harbor_server
 from testutils import TEARDOWN
+from testutils import IMAGES_REPOSITORY
 from library.project import Project
 from library.user import User
 from library.repository import Repository
@@ -22,6 +23,8 @@ class TestProjects(unittest.TestCase):
         self.url = ADMIN_CLIENT["endpoint"]
         self.user_password = "Aa123456"
         self.repo_name = "hello-world"
+        if IMAGES_REPOSITORY:
+            self.repo_name = r"{}/library/{}".format(IMAGES_REPOSITORY, self.repo_name)
 
     @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
     def tearDown(self):
diff --git a/tests/apitests/python/test_user_view_logs.py b/tests/apitests/python/test_user_view_logs.py
index 64f09807d..26793c083 100644
--- a/tests/apitests/python/test_user_view_logs.py
+++ b/tests/apitests/python/test_user_view_logs.py
@@ -5,6 +5,7 @@ import time
 
 from testutils import ADMIN_CLIENT, suppress_urllib3_warning
 from testutils import TEARDOWN
+from testutils import IMAGES_REPOSITORY
 from testutils import TestResult
 from library.user import User
 from library.projectV2 import ProjectV2
@@ -48,6 +49,9 @@ class TestProjects(unittest.TestCase):
         admin_name = ADMIN_CLIENT["username"]
         admin_password = ADMIN_CLIENT["password"]
         user_content_trust_password = "Aa123456"
+        image = "tomcat"
+        if IMAGES_REPOSITORY:
+            image = r"{}/library/{}".format(IMAGES_REPOSITORY, image)
 
         #1. Create a new user(UA);
         TestProjects.user_user_view_logs_id, user_user_view_logs_name = self.user.create_user(user_password = user_content_trust_password, **ADMIN_CLIENT)
@@ -66,7 +70,7 @@ class TestProjects(unittest.TestCase):
                                              format(user_user_view_logs_name, project_user_view_logs_name, "project", operation, log_count))
 
         #3.1 Push a new image(IA) in project(PA) by admin;
-        repo_name, tag = push_image_to_project(project_user_view_logs_name, harbor_server, admin_name, admin_password, "tomcat", "latest")
+        repo_name, tag = push_image_to_project(project_user_view_logs_name, harbor_server, admin_name, admin_password, image, "latest")
         time.sleep(2)
 
         #3.2 In project(PA), there should be 1 'push' log record;
@@ -76,7 +80,7 @@ class TestProjects(unittest.TestCase):
             test_result.add_test_result("2 - Failed to get log with user:{}, resource:{}, resource_type:{} and operation:{}, expect count 1, but actual is {}.".
                                              format(user_user_view_logs_name, project_user_view_logs_name, "artifact", operation, log_count))
         #4.1 Delete repository(RA) by user(UA);
-        self.repo.delete_repoitory(project_user_view_logs_name, repo_name.split('/')[1], **TestProjects.USER_USER_VIEW_LOGS_CLIENT)
+        self.repo.delete_repoitory(project_user_view_logs_name, repo_name.split('/', 1)[1], **TestProjects.USER_USER_VIEW_LOGS_CLIENT)
         time.sleep(6)
 
         #4.2 In project(PA), there should be 1 'delete' log record;
diff --git a/tests/apitests/python/testutils.py b/tests/apitests/python/testutils.py
index 10ed9f9d3..16c4d8eea 100644
--- a/tests/apitests/python/testutils.py
+++ b/tests/apitests/python/testutils.py
@@ -28,6 +28,7 @@ ADMIN_CLIENT=dict(endpoint = os.environ.get("HARBOR_HOST_SCHEMA", "https")+ "://
 CHART_API_CLIENT=dict(endpoint = os.environ.get("HARBOR_HOST_SCHEMA", "https")+ "://"+harbor_server+"/api", username = admin_user, password =  admin_pwd)
 USER_ROLE=dict(admin=0,normal=1)
 TEARDOWN = os.environ.get('TEARDOWN', 'true').lower() in ('true', 'yes')
+IMAGES_REPOSITORY = os.environ.get("HARBOR_TEST_IMAGES_REPOSITORY", "")
 notary_url = os.environ.get('NOTARY_URL', 'https://'+harbor_server+':4443')
 DOCKER_USER = os.environ.get('DOCKER_USER', '')
 DOCKER_PWD = os.environ.get('DOCKER_PWD', '')
-- 
2.24.3 (Apple Git-128)

