|
| 1 | +import pytest |
| 2 | +import json |
| 3 | +import uuid |
| 4 | + |
| 5 | +from pulpcore.client.pulp_deb.exceptions import ApiException |
| 6 | + |
| 7 | + |
| 8 | +def test_domain_create( |
| 9 | + deb_domain_factory, |
| 10 | + deb_init_and_sync, |
| 11 | + apt_package_api, |
| 12 | + apt_repository_api, |
| 13 | +): |
| 14 | + """Test repo-creation in a domain.""" |
| 15 | + domain_name = deb_domain_factory().name |
| 16 | + |
| 17 | + # create and sync in default domain (not specified) |
| 18 | + deb_init_and_sync() |
| 19 | + |
| 20 | + # check that newly created domain doesn't have a repo or any packages |
| 21 | + assert apt_repository_api.list(pulp_domain=domain_name).count == 0 |
| 22 | + assert apt_package_api.list(pulp_domain=domain_name).count == 0 |
| 23 | + |
| 24 | + |
| 25 | +def test_domain_sync( |
| 26 | + deb_domain_factory, |
| 27 | + deb_init_and_sync, |
| 28 | + apt_repository_api, |
| 29 | + apt_package_api, |
| 30 | + deb_cleanup_domains, |
| 31 | +): |
| 32 | + """Test repo-sync in a domain.""" |
| 33 | + domain = deb_domain_factory() |
| 34 | + try: |
| 35 | + domain_name = domain.name |
| 36 | + repo, _ = deb_init_and_sync(pulp_domain=domain_name) |
| 37 | + repos = apt_repository_api.list(name=repo.name, pulp_domain=domain_name) |
| 38 | + print(f"repos = {repos}") |
| 39 | + assert len(repos) == 1 |
| 40 | + assert repos[0].pulp_href == repo.pulp_href |
| 41 | + assert apt_repository_api.list(pulp_domain=domain_name).count == 1 |
| 42 | + assert ( |
| 43 | + apt_package_api.list( |
| 44 | + repository_version=repo.latest_version_href, pulp_domain=domain_name |
| 45 | + ).count |
| 46 | + == 2 |
| 47 | + ) |
| 48 | + finally: |
| 49 | + deb_cleanup_domains([domain], content_api_client=apt_package_api, cleanup_repositories=True) |
| 50 | + |
| 51 | + |
| 52 | +@pytest.mark.parallel |
| 53 | +def test_object_creation( |
| 54 | + deb_domain_factory, |
| 55 | + deb_repository_factory, |
| 56 | + apt_repository_api, |
| 57 | + deb_remote_factory, |
| 58 | + deb_sync_repository, |
| 59 | + deb_get_fixture_server_url, |
| 60 | +): |
| 61 | + """Test basic object creation in a separate domain.""" |
| 62 | + domain = deb_domain_factory() |
| 63 | + domain_name = domain.name |
| 64 | + |
| 65 | + repo = deb_repository_factory(pulp_domain=domain_name) |
| 66 | + assert f"{domain_name}/api/v3/" in repo.pulp_href |
| 67 | + |
| 68 | + repos = apt_repository_api.list(pulp_domain=domain_name) |
| 69 | + assert repos.count == 1 |
| 70 | + assert repo.pulp_href == repos.results[0].pulp_href |
| 71 | + |
| 72 | + # list repos on default domain |
| 73 | + default_repos = apt_repository_api.list(name=repo.name) |
| 74 | + assert default_repos.count == 0 |
| 75 | + |
| 76 | + # try to create an object with cross domain relations |
| 77 | + url = deb_get_fixture_server_url() |
| 78 | + default_remote = deb_remote_factory(url) |
| 79 | + with pytest.raises(ApiException) as e: |
| 80 | + repo_body = {"name": str(uuid.uuid4()), "remote": default_remote.pulp_href} |
| 81 | + apt_repository_api.create(repo_body, pulp_domain=domain_name) |
| 82 | + assert e.value.status == 400 |
| 83 | + assert json.loads(e.value.body) == { |
| 84 | + "non_field_errors": [f"Objects must all be apart of the {domain_name} domain."] |
| 85 | + } |
| 86 | + |
| 87 | + with pytest.raises(ApiException) as e: |
| 88 | + deb_sync_repository(remote=default_remote, repo=repo) |
| 89 | + assert e.value.status == 400 |
| 90 | + assert json.loads(e.value.body) == { |
| 91 | + "non_field_errors": [f"Objects must all be apart of the {domain_name} domain."] |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | +@pytest.mark.parallel |
| 96 | +def test_content_promotion( |
| 97 | + deb_domain_factory, |
| 98 | + deb_cleanup_domains, |
| 99 | + deb_publication_factory, |
| 100 | + deb_distribution_factory, |
| 101 | + deb_delete_repository, |
| 102 | + deb_init_and_sync, |
| 103 | + deb_get_repository_by_href, |
| 104 | +): |
| 105 | + """Tests Content promotion path with domains: Sync->Publish->Distribute""" |
| 106 | + domain = deb_domain_factory() |
| 107 | + |
| 108 | + try: |
| 109 | + # Sync |
| 110 | + repo, _, task = deb_init_and_sync(pulp_domain=domain.name, return_task=True) |
| 111 | + assert len(task.created_resources) == 1 |
| 112 | + |
| 113 | + repo = deb_get_repository_by_href(repo.pulp_href) |
| 114 | + assert repo.latest_version_href[-2] == "1" |
| 115 | + |
| 116 | + # Publish |
| 117 | + publication = deb_publication_factory(repo=repo, pulp_domain=domain.name) |
| 118 | + assert publication.repository == repo.pulp_href |
| 119 | + |
| 120 | + # Distribute |
| 121 | + distribution = deb_distribution_factory(publication=publication, pulp_domain=domain.name) |
| 122 | + assert distribution.publication == publication.pulp_href |
| 123 | + # url structure should be host/CONTENT_ORIGIN/DOMAIN_PATH/BASE_PATH |
| 124 | + assert domain.name == distribution.base_url.rstrip("/").split("/")[-2] |
| 125 | + |
| 126 | + # check that content can be downloaded from base_url |
| 127 | + # for pkg in ("", ""): |
| 128 | + # pkg_path = get_package_repo_path(pkg) |
| 129 | + # download_content_unit(distribution.base_path, pkg_path, domain=domain.name) |
| 130 | + |
| 131 | + # cleanup to delete the domain |
| 132 | + deb_delete_repository(repo) |
| 133 | + finally: |
| 134 | + deb_cleanup_domains([domain], cleanup_repositories=True) |
| 135 | + |
| 136 | + |
| 137 | +@pytest.mark.parallel |
| 138 | +def test_domain_rbac( |
| 139 | + deb_domain_factory, deb_cleanup_domains, apt_repository_api, deb_repository_factory, gen_user |
| 140 | +): |
| 141 | + """Test domain level roles.""" |
| 142 | + domain = deb_domain_factory() |
| 143 | + |
| 144 | + try: |
| 145 | + deb_viewer = "deb.aptrepository_viewer" |
| 146 | + deb_creator = "deb.aptrepository_creator" |
| 147 | + user_a = gen_user(username="a", domain_roles=[(deb_viewer, domain.pulp_href)]) |
| 148 | + user_b = gen_user(username="b", domain_roles=[(deb_creator, domain.pulp_href)]) |
| 149 | + |
| 150 | + # create two repos in different domains with admin user |
| 151 | + deb_repository_factory() |
| 152 | + deb_repository_factory(pulp_domain=domain.name) |
| 153 | + |
| 154 | + with user_b: |
| 155 | + repo = deb_repository_factory(pulp_domain=domain.name) |
| 156 | + repos = apt_repository_api.list(pulp_domain=domain.name) |
| 157 | + assert repos.count == 1 |
| 158 | + assert repos.results[0].pulp_href == repo.pulp_href |
| 159 | + |
| 160 | + # try to create a repository in default domain |
| 161 | + with pytest.raises(ApiException) as e: |
| 162 | + deb_repository_factory() |
| 163 | + assert e.value.status == 403 |
| 164 | + |
| 165 | + with user_a: |
| 166 | + repos = apt_repository_api.list(pulp_domain=domain.name) |
| 167 | + assert repos.count == 2 |
| 168 | + |
| 169 | + # try to read repos in the default domain |
| 170 | + repos = apt_repository_api.list() |
| 171 | + assert repos.count == 0 |
| 172 | + |
| 173 | + # try to create a repo |
| 174 | + with pytest.raises(ApiException) as e: |
| 175 | + deb_repository_factory(pulp_domain=domain.name) |
| 176 | + assert e.value.status == 403 |
| 177 | + finally: |
| 178 | + deb_cleanup_domains([domain], cleanup_repositories=True) |
| 179 | + |
| 180 | + |
| 181 | +# @pytest.mark.parallel |
| 182 | +# def test_cross_domain_copy_all( |
| 183 | +# deb_domain_factory, |
| 184 | +# ): |
| 185 | +# """Test attempting to copy between different domains.""" |
| 186 | +# domain_1 = None |
| 187 | +# domain_2 = None |
0 commit comments