-
Notifications
You must be signed in to change notification settings - Fork 671
feat(job_token_scope): support Groups in job token allowlist API #2816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JohnVillalovos
merged 8 commits into
python-gitlab:main
from
TimKnight-DWP:feat/group-allowlist
May 13, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b9d705a
feat(job_token_scope): support job token access allowlist API
nejch 2fb53e4
test: add api integration test for ci_cd_token allowlist
TimKnight-DWP 09aed71
feat: add support for groups_allowlist in job_token_scope
TimKnight-DWP 3cc75e2
feat: add support for groups_allowlist in job_token_scope
TimKnight-DWP 3bfc726
test: add unit tests for job_token_scope
TimKnight-DWP b6e4d01
chore: update job_token docs and object names
TimKnight-DWP c6a1fc6
refactor: use super().get_id()
TimKnight-DWP 4aab77f
test: cover .get_id() paths
TimKnight-DWP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,116 @@ | ||
# https://docs.gitlab.com/ee/ci/jobs/ci_job_token.html#allow-any-project-to-access-your-project | ||
def test_enable_limit_access_to_this_project(gl, project): | ||
scope = project.job_token_scope.get() | ||
|
||
scope.enabled = True | ||
scope.save() | ||
|
||
scope.refresh() | ||
|
||
assert scope.inbound_enabled | ||
|
||
|
||
def test_disable_limit_access_to_this_project(gl, project): | ||
scope = project.job_token_scope.get() | ||
|
||
scope.enabled = False | ||
scope.save() | ||
|
||
scope.refresh() | ||
|
||
assert not scope.inbound_enabled | ||
|
||
|
||
def test_add_project_to_job_token_scope_allowlist(gl, project): | ||
project_to_add = gl.projects.create({"name": "Ci_Cd_token_add_proj"}) | ||
|
||
scope = project.job_token_scope.get() | ||
resp = scope.allowlist.create({"target_project_id": project_to_add.id}) | ||
|
||
assert resp.source_project_id == project.id | ||
assert resp.target_project_id == project_to_add.id | ||
|
||
project_to_add.delete() | ||
|
||
|
||
def test_projects_job_token_scope_allowlist_contains_added_project_name(gl, project): | ||
scope = project.job_token_scope.get() | ||
project_name = "Ci_Cd_token_named_proj" | ||
project_to_add = gl.projects.create({"name": project_name}) | ||
scope.allowlist.create({"target_project_id": project_to_add.id}) | ||
|
||
scope.refresh() | ||
assert any(allowed.name == project_name for allowed in scope.allowlist.list()) | ||
|
||
project_to_add.delete() | ||
|
||
|
||
def test_remove_project_by_id_from_projects_job_token_scope_allowlist(gl, project): | ||
scope = project.job_token_scope.get() | ||
|
||
project_to_add = gl.projects.create({"name": "Ci_Cd_token_remove_proj"}) | ||
|
||
scope.allowlist.create({"target_project_id": project_to_add.id}) | ||
|
||
scope.refresh() | ||
|
||
scope.allowlist.delete(project_to_add.id) | ||
|
||
scope.refresh() | ||
assert not any( | ||
allowed.id == project_to_add.id for allowed in scope.allowlist.list() | ||
) | ||
|
||
project_to_add.delete() | ||
|
||
|
||
def test_add_group_to_job_token_scope_allowlist(gl, project): | ||
group_to_add = gl.groups.create( | ||
{"name": "add_group", "path": "allowlisted-add-test"} | ||
) | ||
|
||
scope = project.job_token_scope.get() | ||
resp = scope.groups_allowlist.create({"target_group_id": group_to_add.id}) | ||
|
||
assert resp.source_project_id == project.id | ||
assert resp.target_group_id == group_to_add.id | ||
|
||
group_to_add.delete() | ||
|
||
|
||
def test_projects_job_token_scope_groups_allowlist_contains_added_group_name( | ||
gl, project | ||
): | ||
scope = project.job_token_scope.get() | ||
group_name = "list_group" | ||
group_to_add = gl.groups.create( | ||
{"name": group_name, "path": "allowlisted-add-and-list-test"} | ||
) | ||
|
||
scope.groups_allowlist.create({"target_group_id": group_to_add.id}) | ||
|
||
scope.refresh() | ||
assert any(allowed.name == group_name for allowed in scope.groups_allowlist.list()) | ||
|
||
group_to_add.delete() | ||
|
||
|
||
def test_remove_group_by_id_from_projects_job_token_scope_groups_allowlist(gl, project): | ||
scope = project.job_token_scope.get() | ||
|
||
group_to_add = gl.groups.create( | ||
{"name": "delete_group", "path": "allowlisted-delete-test"} | ||
) | ||
|
||
scope.groups_allowlist.create({"target_group_id": group_to_add.id}) | ||
|
||
scope.refresh() | ||
|
||
scope.groups_allowlist.delete(group_to_add.id) | ||
|
||
scope.refresh() | ||
assert not any( | ||
allowed.name == group_to_add.name for allowed in scope.groups_allowlist.list() | ||
) | ||
|
||
group_to_add.delete() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.