Skip to content

Commit

Permalink
Fixes the permission issue with import-all.
Browse files Browse the repository at this point in the history
Closes #373
  • Loading branch information
decko authored and lubosmj committed Jun 26, 2024
1 parent fcd7fe6 commit 94ed3e5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES/373.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an issue when trying to use import-all as a non-admin user.
3 changes: 1 addition & 2 deletions pulp_ostree/app/tasks/importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def import_all_refs_and_commits(artifact_pk, repository_pk, repository_name):
repository_name (str): The name of an OSTree repository (e.g., "repo").
Raises:
ValueError: If an OSTree repository could not be properly parsed or the specified ref
does not exist.
ValueError: If an OSTree repository could not be properly parsed.
"""
tarball_artifact = Artifact.objects.get(pk=artifact_pk)
repository = Repository.objects.get(pk=repository_pk)
Expand Down
2 changes: 1 addition & 1 deletion pulp_ostree/app/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class OstreeRepositoryViewSet(core.RepositoryViewSet, ModifyRepositoryActionMixi
"principal": "authenticated",
"effect": "allow",
"condition": [
"has_model_or_domain_or_obj_perms:ostree.import_commits_ostreerepository"
"has_model_or_domain_or_obj_perms:ostree.import_commits_ostreerepository",
"has_model_or_domain_or_obj_perms:ostree.view_ostreerepository",
],
},
Expand Down
47 changes: 47 additions & 0 deletions pulp_ostree/tests/functional/api/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,50 @@ def test_import_commits_same_ref(
assert added_content["ostree.commit"]["count"] == 1
assert added_content["ostree.content"]["count"] == 2
assert added_content["ostree.summary"]["count"] == 1


@pytest.mark.parallel
def test_import_all_as_ostree_repo_admin(
pulpcore_bindings,
gen_user,
role_factory,
gen_object_with_cleanup,
monitor_task,
ostree_repository_factory,
ostree_repositories_api_client,
ostree_repositories_versions_api_client,
tmp_path,
):
"""Create a role for ostree admin, then import a repository with import-all."""

os.chdir(tmp_path)
repo_name = "repo"
sample_dir = tmp_path / str(uuid.uuid4())
sample_file1 = sample_dir / str(uuid.uuid4())
branch_name = "foo"

# 1. create a first file
sample_dir.mkdir()
sample_file1.touch()

# 2. initialize a local OSTree repository and commit the created file
subprocess.run(["ostree", f"--repo={repo_name}", "init", "--mode=archive"])
subprocess.run(
["ostree", f"--repo={repo_name}", "commit", f"--branch={branch_name}", f"{sample_dir}/"]
)
subprocess.run(["tar", "-cvf", f"{repo_name}.tar", f"{repo_name}/"])

user = gen_user(model_roles=["ostree.ostreerepository_creator"])

with user:
artifact = gen_object_with_cleanup(pulpcore_bindings.ArtifactsApi, f"{repo_name}.tar")
repo = ostree_repository_factory(name=repo_name)
commit_data = OstreeImportAll(artifact.pulp_href, repo_name)
response = ostree_repositories_api_client.import_all(repo.pulp_href, commit_data)

repo_version = monitor_task(response.task).created_resources[0]

repository_version = ostree_repositories_versions_api_client.read(repo_version)
added_content = repository_version.content_summary.added
assert added_content["ostree.refs"]["count"] == 1
assert added_content["ostree.commit"]["count"] == 1

0 comments on commit 94ed3e5

Please sign in to comment.