Users API is not consistent with docs for force_random_password
Summary
The Users API docs state that you can use any one of password
, reset_password
, and force_random_password
when creating a user.
Either password, reset_password, or force_random_password must be specified. If reset_password and force_random_password are both false, then password is required.
Note that force_random_password and reset_password take priority over password. In addition, reset_password and force_random_password can be used together.
However, the API code, requires one of password or reset_password. https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/api/users.rb#L163
This feature was introduced in gitlab-foss!30138 (merged)
Steps to reproduce
Attempt to create a user with force_random_password
set and not reset_password
or password
.
curl -X POST \
'http://example.com/api/v4/users?private_token=xxxxxxxx' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{ "email": "test@example.com",
"username": "testusername",
"name": "testname",
"force_random_password": True
}'
What is the current bug behavior?
HTTP Error 400: password, reset_password are missing, at least one parameter must be provided
What is the expected correct behavior?
User is created with a random password.
Possible fixes
It might just be a one line fix to: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/api/users.rb#L163 adding force_random_password, but I don't know if other code relies on this restriction.