|
| 1 | +# https://docs.gitlab.com/ee/ci/jobs/ci_job_token.html#allow-any-project-to-access-your-project |
| 2 | +def test_enable_limit_access_to_this_project(gl, project): |
| 3 | + scope = project.job_token_scope.get() |
| 4 | + |
| 5 | + scope.enabled = True |
| 6 | + scope.save() |
| 7 | + |
| 8 | + scope.refresh() |
| 9 | + |
| 10 | + assert scope.inbound_enabled |
| 11 | + |
| 12 | + |
| 13 | +def test_disable_limit_access_to_this_project(gl, project): |
| 14 | + scope = project.job_token_scope.get() |
| 15 | + |
| 16 | + scope.enabled = False |
| 17 | + scope.save() |
| 18 | + |
| 19 | + scope.refresh() |
| 20 | + |
| 21 | + assert not scope.inbound_enabled |
| 22 | + |
| 23 | + |
| 24 | +def test_add_project_to_job_token_scope_allowlist(gl, project): |
| 25 | + project_to_add = gl.projects.create({"name": "Ci_Cd_token_add_proj"}) |
| 26 | + |
| 27 | + scope = project.job_token_scope.get() |
| 28 | + resp = scope.allowlist.create({"target_project_id": project_to_add.id}) |
| 29 | + |
| 30 | + assert resp.source_project_id == project.id |
| 31 | + assert resp.target_project_id == project_to_add.id |
| 32 | + |
| 33 | + project_to_add.delete() |
| 34 | + |
| 35 | + |
| 36 | +def test_projects_job_token_scope_allowlist_contains_added_project_name(gl, project): |
| 37 | + scope = project.job_token_scope.get() |
| 38 | + project_name = "Ci_Cd_token_named_proj" |
| 39 | + project_to_add = gl.projects.create({"name": project_name}) |
| 40 | + scope.allowlist.create({"target_project_id": project_to_add.id}) |
| 41 | + |
| 42 | + scope.refresh() |
| 43 | + assert any(allowed.name == project_name for allowed in scope.allowlist.list()) |
| 44 | + |
| 45 | + project_to_add.delete() |
| 46 | + |
| 47 | + |
| 48 | +def test_remove_project_by_id_from_projects_job_token_scope_allowlist(gl, project): |
| 49 | + scope = project.job_token_scope.get() |
| 50 | + |
| 51 | + project_to_add = gl.projects.create({"name": "Ci_Cd_token_remove_proj"}) |
| 52 | + |
| 53 | + scope.allowlist.create({"target_project_id": project_to_add.id}) |
| 54 | + |
| 55 | + scope.refresh() |
| 56 | + |
| 57 | + scope.allowlist.delete(project_to_add.id) |
| 58 | + |
| 59 | + scope.refresh() |
| 60 | + assert not any( |
| 61 | + allowed.id == project_to_add.id for allowed in scope.allowlist.list() |
| 62 | + ) |
| 63 | + |
| 64 | + project_to_add.delete() |
| 65 | + |
| 66 | + |
| 67 | +def test_add_group_to_job_token_scope_allowlist(gl, project): |
| 68 | + group_to_add = gl.groups.create( |
| 69 | + {"name": "add_group", "path": "allowlisted-add-test"} |
| 70 | + ) |
| 71 | + |
| 72 | + scope = project.job_token_scope.get() |
| 73 | + resp = scope.groups_allowlist.create({"target_group_id": group_to_add.id}) |
| 74 | + |
| 75 | + assert resp.source_project_id == project.id |
| 76 | + assert resp.target_group_id == group_to_add.id |
| 77 | + |
| 78 | + group_to_add.delete() |
| 79 | + |
| 80 | + |
| 81 | +def test_projects_job_token_scope_groups_allowlist_contains_added_group_name( |
| 82 | + gl, project |
| 83 | +): |
| 84 | + scope = project.job_token_scope.get() |
| 85 | + group_name = "list_group" |
| 86 | + group_to_add = gl.groups.create( |
| 87 | + {"name": group_name, "path": "allowlisted-add-and-list-test"} |
| 88 | + ) |
| 89 | + |
| 90 | + scope.groups_allowlist.create({"target_group_id": group_to_add.id}) |
| 91 | + |
| 92 | + scope.refresh() |
| 93 | + assert any(allowed.name == group_name for allowed in scope.groups_allowlist.list()) |
| 94 | + |
| 95 | + group_to_add.delete() |
| 96 | + |
| 97 | + |
| 98 | +def test_remove_group_by_id_from_projects_job_token_scope_groups_allowlist(gl, project): |
| 99 | + scope = project.job_token_scope.get() |
| 100 | + |
| 101 | + group_to_add = gl.groups.create( |
| 102 | + {"name": "delete_group", "path": "allowlisted-delete-test"} |
| 103 | + ) |
| 104 | + |
| 105 | + scope.groups_allowlist.create({"target_group_id": group_to_add.id}) |
| 106 | + |
| 107 | + scope.refresh() |
| 108 | + |
| 109 | + scope.groups_allowlist.delete(group_to_add.id) |
| 110 | + |
| 111 | + scope.refresh() |
| 112 | + assert not any( |
| 113 | + allowed.name == group_to_add.name for allowed in scope.groups_allowlist.list() |
| 114 | + ) |
| 115 | + |
| 116 | + group_to_add.delete() |
0 commit comments