|
| 1 | +### Verify that the added scopes exist in GitLab |
| 2 | +### |
| 3 | +### Prerequisites: |
| 4 | +### Copy http-client.private.env.json.example to http-client.private.env.json |
| 5 | +### and fill in your gitlab.com token, project_id, and group_id. |
| 6 | +### Then select the "dev" environment in IntelliJ before running. |
| 7 | +### |
| 8 | +### How the proof works: |
| 9 | +### GitLab validates scopes AFTER authentication. If a scope is valid, |
| 10 | +### the request succeeds (or fails for permission reasons: 403/404). |
| 11 | +### If a scope is INVALID, GitLab returns 400 with |
| 12 | +### "scopes does not have a valid value". |
| 13 | +### |
| 14 | +### Each section includes a negative test with a deliberately invalid |
| 15 | +### scope to demonstrate that GitLab does reject unknown scopes. |
| 16 | + |
| 17 | + |
| 18 | +### --- ApplicationScope: self_rotate --- |
| 19 | +### |
| 20 | +### The self-service PAT endpoint (POST /api/v4/user/personal_access_tokens) |
| 21 | +### only accepts k8s_proxy and self_rotate scopes (by design, GitLab 16.5+). |
| 22 | +### The other ApplicationScope scopes (read_registry, write_registry, etc.) |
| 23 | +### are valid PAT scopes but can only be set via the admin endpoint or the UI. |
| 24 | +### |
| 25 | +### Reference: https://docs.gitlab.com/user/profile/personal_access_tokens/#personal-access-token-scopes |
| 26 | + |
| 27 | +### Positive: self_rotate scope (should return 201) |
| 28 | +POST https://gitlab.com/api/v4/user/personal_access_tokens |
| 29 | +PRIVATE-TOKEN: {{token}} |
| 30 | +Content-Type: application/json |
| 31 | + |
| 32 | +{ |
| 33 | + "name": "verify-self-rotate", |
| 34 | + "scopes": ["self_rotate"], |
| 35 | + "expires_at": "2026-12-31" |
| 36 | +} |
| 37 | + |
| 38 | +### Negative: invalid scope (should return 400) |
| 39 | +POST https://gitlab.com/api/v4/user/personal_access_tokens |
| 40 | +PRIVATE-TOKEN: {{token}} |
| 41 | +Content-Type: application/json |
| 42 | + |
| 43 | +{ |
| 44 | + "name": "verify-invalid-scope", |
| 45 | + "scopes": ["THIS_SCOPE_DOES_NOT_EXIST"], |
| 46 | + "expires_at": "2026-12-31" |
| 47 | +} |
| 48 | + |
| 49 | +### --- ProjectAccessTokenScope scopes --- |
| 50 | +### |
| 51 | +### Requires Maintainer access on the project. |
| 52 | +### Reference: https://docs.gitlab.com/user/project/settings/project_access_tokens/#scopes-for-a-project-access-token |
| 53 | + |
| 54 | +### Positive: newly added scopes (should return 201, NOT 400) |
| 55 | +POST https://gitlab.com/api/v4/projects/{{project_id}}/access_tokens |
| 56 | +PRIVATE-TOKEN: {{token}} |
| 57 | +Content-Type: application/json |
| 58 | + |
| 59 | +{ |
| 60 | + "name": "verify-project-scopes-valid", |
| 61 | + "scopes": ["manage_runner", "ai_features", "k8s_proxy", "self_rotate"], |
| 62 | + "expires_at": "2026-12-31", |
| 63 | + "access_level": 30 |
| 64 | +} |
| 65 | + |
| 66 | +### Negative: invalid scope (should return 400) |
| 67 | +POST https://gitlab.com/api/v4/projects/{{project_id}}/access_tokens |
| 68 | +PRIVATE-TOKEN: {{token}} |
| 69 | +Content-Type: application/json |
| 70 | + |
| 71 | +{ |
| 72 | + "name": "verify-project-scopes-invalid", |
| 73 | + "scopes": ["manage_runner", "THIS_SCOPE_DOES_NOT_EXIST"], |
| 74 | + "expires_at": "2026-12-31", |
| 75 | + "access_level": 30 |
| 76 | +} |
| 77 | + |
| 78 | +### --- ImpersonationToken.Scope (Group Access Token) scopes --- |
| 79 | +### |
| 80 | +### Requires Owner access on the group. |
| 81 | +### Reference: https://docs.gitlab.com/user/group/settings/group_access_tokens/#scopes-for-a-group-access-token |
| 82 | + |
| 83 | +### Positive: newly added scopes (should return 400 Bad request - User does not have permission to create group access token) |
| 84 | +POST https://gitlab.com/api/v4/groups/{{group_id}}/access_tokens |
| 85 | +PRIVATE-TOKEN: {{token}} |
| 86 | +Content-Type: application/json |
| 87 | + |
| 88 | +{ |
| 89 | + "name": "verify-group-scopes-valid", |
| 90 | + "scopes": ["create_runner", "manage_runner", "ai_features", "self_rotate", "read_virtual_registry", "write_virtual_registry"], |
| 91 | + "expires_at": "2026-12-31", |
| 92 | + "access_level": 30 |
| 93 | +} |
| 94 | + |
| 95 | +### Negative: invalid scope (should return 400 scopes does not have a valid value) |
| 96 | +POST https://gitlab.com/api/v4/groups/{{group_id}}/access_tokens |
| 97 | +PRIVATE-TOKEN: {{token}} |
| 98 | +Content-Type: application/json |
| 99 | + |
| 100 | +{ |
| 101 | + "name": "verify-group-scopes-invalid", |
| 102 | + "scopes": ["create_runner", "THIS_SCOPE_DOES_NOT_EXIST"], |
| 103 | + "expires_at": "2026-12-31", |
| 104 | + "access_level": 30 |
| 105 | +} |
| 106 | + |
| 107 | +### --- DeployTokenScope scopes --- |
| 108 | +### |
| 109 | +### Requires Maintainer access on the project. |
| 110 | +### Reference: https://docs.gitlab.com/user/project/deploy_tokens/#scope |
| 111 | + |
| 112 | +### Positive: newly added scopes (should return 201, NOT 400) |
| 113 | +POST https://gitlab.com/api/v4/projects/{{project_id}}/deploy_tokens |
| 114 | +PRIVATE-TOKEN: {{token}} |
| 115 | +Content-Type: application/json |
| 116 | + |
| 117 | +{ |
| 118 | + "name": "verify-deploy-scopes-valid", |
| 119 | + "scopes": ["write_registry", "read_virtual_registry", "write_virtual_registry", "read_package_registry", "write_package_registry"], |
| 120 | + "expires_at": "2026-12-31" |
| 121 | +} |
| 122 | + |
| 123 | +### Negative: invalid scope (should return 400 scopes does not have a valid value) |
| 124 | +POST https://gitlab.com/api/v4/projects/{{project_id}}/deploy_tokens |
| 125 | +PRIVATE-TOKEN: {{token}} |
| 126 | +Content-Type: application/json |
| 127 | + |
| 128 | +{ |
| 129 | + "name": "verify-deploy-scopes-invalid", |
| 130 | + "scopes": ["read_repository", "THIS_SCOPE_DOES_NOT_EXIST"], |
| 131 | + "expires_at": "2026-12-31" |
| 132 | +} |
| 133 | + |
| 134 | +### --- Cleanup --- |
| 135 | +### If any tokens were created above, revoke them: |
| 136 | +### GET https://gitlab.com/api/v4/personal_access_tokens |
| 137 | +### then DELETE https://gitlab.com/api/v4/personal_access_tokens/:id |
0 commit comments