diff options
-rw-r--r-- | changelogs/unreleased/api-fix-user-creation.yml | 4 | ||||
-rw-r--r-- | lib/api/users.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/users_spec.rb | 10 |
3 files changed, 16 insertions, 0 deletions
diff --git a/changelogs/unreleased/api-fix-user-creation.yml b/changelogs/unreleased/api-fix-user-creation.yml new file mode 100644 index 00000000000..a10b5a432ad --- /dev/null +++ b/changelogs/unreleased/api-fix-user-creation.yml @@ -0,0 +1,4 @@ +--- +title: 'API: Fix user creation with external identity' +merge_request: 8435 +author: Robert Schilling diff --git a/lib/api/users.rb b/lib/api/users.rb index de07fbf59fc..26b44eb7b81 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -92,6 +92,8 @@ module API # Filter out params which are used later identity_attrs = params.slice(:provider, :extern_uid) + params.delete(:provider) + params.delete(:extern_uid) confirm = params.delete(:confirm) user = User.new(declared_params(include_missing: false)) diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 45b7988a054..eccc8766777 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -181,6 +181,16 @@ describe API::Users, api: true do expect(new_user.external).to be_truthy end + it 'creates an user with an external provider' do + post api('/users', admin), attributes_for(:user, provider: 'github', extern_uid: 'john') + + expect(response).to have_http_status(201) + new_user = User.find(json_response['id']) + expect(new_user).not_to eq(nil) + expect(new_user.identities.first.provider).to eq('github') + expect(new_user.identities.first.extern_uid).to eq('john') + end + it "does not create user with invalid email" do post api('/users', admin), email: 'invalid email', |