Commit 89ac4baf authored by Dan Jensen's avatar Dan Jensen Committed by Dylan Griffith

Fix force_random_password option in Users API

Previously the API did not correctly handle the force_random_password
option. It was not being treated as one of the 3 viable password-
setting options. This adds it as the 3rd, and fixes the test coverage,
which was not properly testing this use case.
parent 8b107ee8
---
title: Fix force_random_password option when creating Users via API
merge_request: 57751
author:
type: fixed
......@@ -231,7 +231,7 @@ module API
optional :password, type: String, desc: 'The password of the new user'
optional :reset_password, type: Boolean, desc: 'Flag indicating the user will be sent a password reset token'
optional :skip_confirmation, type: Boolean, desc: 'Flag indicating the account is confirmed'
at_least_one_of :password, :reset_password
at_least_one_of :password, :reset_password, :force_random_password
requires :name, type: String, desc: 'The name of the user'
requires :username, type: String, desc: 'The username of the user'
optional :force_random_password, type: Boolean, desc: 'Flag indicating a random password will be set'
......
......@@ -928,7 +928,8 @@ RSpec.describe API::Users do
end
it "creates user with random password" do
params = attributes_for(:user, force_random_password: true, reset_password: true)
params = attributes_for(:user, force_random_password: true)
params.delete(:password)
post api('/users', admin), params: params
expect(response).to have_gitlab_http_status(:created)
......@@ -936,8 +937,7 @@ RSpec.describe API::Users do
user_id = json_response['id']
new_user = User.find(user_id)
expect(new_user.valid_password?(params[:password])).to eq(false)
expect(new_user.recently_sent_password_reset?).to eq(true)
expect(new_user.encrypted_password).to be_present
end
it "creates user with private profile" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment