Commit 2bec0e82 authored by Imre Farkas's avatar Imre Farkas

Fix smartcard param check in User::BuildService

parent c567376b
---
title: Fix user registration when smartcard authentication is enabled
merge_request: 26800
author:
type: fixed
...@@ -70,7 +70,7 @@ module EE ...@@ -70,7 +70,7 @@ module EE
def build_smartcard_identity(user, params) def build_smartcard_identity(user, params)
smartcard_identity_attrs = params.slice(:certificate_subject, :certificate_issuer) smartcard_identity_attrs = params.slice(:certificate_subject, :certificate_issuer)
if smartcard_identity_attrs.any? unless smartcard_identity_attrs.empty?
user.smartcard_identities.build(subject: params[:certificate_subject], user.smartcard_identities.build(subject: params[:certificate_subject],
issuer: params[:certificate_issuer]) issuer: params[:certificate_issuer])
end end
......
...@@ -28,6 +28,39 @@ describe Users::BuildService do ...@@ -28,6 +28,39 @@ describe Users::BuildService do
end end
end end
end end
context 'smartcard authentication enabled' do
before do
allow(Gitlab::Auth::Smartcard).to receive(:enabled?).and_return(true)
end
context 'smartcard params' do
let(:subject) { '/O=Random Corp Ltd/CN=gitlab-user/emailAddress=gitlab-user@random-corp.org' }
let(:issuer) { '/O=Random Corp Ltd/CN=Random Corp' }
let(:smartcard_identity_params) do
{ certificate_subject: subject, certificate_issuer: issuer }
end
before do
params.merge!(smartcard_identity_params)
end
it 'sets smartcard identity attributes' do
expect(SmartcardIdentity).to(
receive(:new)
.with(hash_including(issuer: issuer, subject: subject))
.and_call_original)
service.execute
end
end
context 'missing smartcard params' do
it 'works as expected' do
expect { service.execute }.not_to raise_error
end
end
end
end end
end end
end end
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