-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test case project level policy content trust. (#6309)
Add test case project level policy content trust. Signed-off-by: danfengliu <danfengl@vmware.com>
- Loading branch information
1 parent
88cab5b
commit ad77098
Showing
4 changed files
with
130 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
tests/apitests/python/test_project_level_policy_content_trust.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from __future__ import absolute_import | ||
|
||
import unittest | ||
|
||
from testutils import ADMIN_CLIENT | ||
from testutils import harbor_server | ||
|
||
from testutils import TEARDOWN | ||
from library.project import Project | ||
from library.user import User | ||
from library.repository import Repository | ||
from library.repository import push_image_to_project | ||
from library.repository import pull_harbor_image_successfully | ||
from library.repository import pull_harbor_image_unsuccessfully | ||
|
||
class TestProjects(unittest.TestCase): | ||
@classmethod | ||
def setUp(self): | ||
project = Project() | ||
self.project= project | ||
|
||
user = User() | ||
self.user= user | ||
|
||
repo = Repository() | ||
self.repo= repo | ||
|
||
@classmethod | ||
def tearDown(self): | ||
print "Case completed" | ||
|
||
@unittest.skipIf(TEARDOWN == False, "Test data should be remain in the harbor.") | ||
def test_ClearData(self): | ||
#1. Delete repository(RA) by user(UA); | ||
self.repo.delete_repoitory(TestProjects.repo_name, **TestProjects.USER_CONTENT_TRUST_CLIENT) | ||
|
||
#2. Delete project(PA); | ||
self.project.delete_project(TestProjects.project_content_trust_id, **TestProjects.USER_CONTENT_TRUST_CLIENT) | ||
|
||
#3. Delete user(UA); | ||
self.user.delete_user(TestProjects.user_content_trust_id, **ADMIN_CLIENT) | ||
|
||
def testProjectLevelPolicyContentTrust(self): | ||
""" | ||
Test case: | ||
Project Level Policy Content Trust | ||
Test step & Expectation: | ||
1. Create a new user(UA); | ||
2. Create a new project(PA) by user(UA); | ||
3. Push a new image(IA) in project(PA) by admin; | ||
4. Image(IA) should exist; | ||
5. Pull image(IA) successfully; | ||
6. Enable content trust in project(PA) configuration; | ||
7. Pull image(IA) failed and the reason is "The image is not signed in Notary". | ||
Tear down: | ||
1. Delete repository(RA) by user(UA); | ||
2. Delete project(PA); | ||
3. Delete user(UA); | ||
""" | ||
url = ADMIN_CLIENT["endpoint"] | ||
admin_name = ADMIN_CLIENT["username"] | ||
admin_password = ADMIN_CLIENT["password"] | ||
user_content_trust_password = "Aa123456" | ||
|
||
#1. Create a new user(UA); | ||
TestProjects.user_content_trust_id, user_content_trust_name = self.user.create_user_success(user_password = user_content_trust_password, **ADMIN_CLIENT) | ||
|
||
TestProjects.USER_CONTENT_TRUST_CLIENT=dict(endpoint = url, username = user_content_trust_name, password = user_content_trust_password) | ||
|
||
#2. Create a new project(PA) by user(UA); | ||
TestProjects.project_content_trust_id, project_content_trust_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_CONTENT_TRUST_CLIENT) | ||
|
||
#3. Push a new image(IA) in project(PA) by admin; | ||
TestProjects.repo_name, tag = push_image_to_project(project_content_trust_name, harbor_server, admin_name, admin_password, "hello-world", "latest") | ||
|
||
#4. Image(IA) should exist; | ||
self.repo.image_should_exist(TestProjects.repo_name, tag, **TestProjects.USER_CONTENT_TRUST_CLIENT) | ||
|
||
#5. Pull image(IA) successfully; | ||
pull_harbor_image_successfully(harbor_server, admin_name, admin_password, TestProjects.repo_name, tag) | ||
|
||
#6. Enable content trust in project(PA) configuration; | ||
self.project.update_project(TestProjects.project_content_trust_id, metadata = {"enable_content_trust": "true"}, **TestProjects.USER_CONTENT_TRUST_CLIENT) | ||
|
||
#7. Pull image(IA) failed and the reason is "The image is not signed in Notary". | ||
pull_harbor_image_unsuccessfully(harbor_server, admin_name, admin_password, TestProjects.repo_name, tag, "The image is not signed in Notary") | ||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters