-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14142 from jvlcek/bz1400567_RFE_LDAP_no_displayname
Ensure user name is set even when common LDAP attributes are missing.
- Loading branch information
Showing
4 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -295,6 +295,34 @@ def authenticate | |
expect(MiqTask.status_error?(task.status)).to be_truthy | ||
end | ||
end | ||
|
||
context "when fullname is blank" do | ||
let(:username) { 'betty' } | ||
let(:headers) do | ||
super().merge('X-Remote-User-FullName' => '', | ||
'X-Remote-User-FirstName' => 'Betty', | ||
'X-Remote-User-LastName' => 'Boop', | ||
'X-Remote-User-Email' => '[email protected]') | ||
end | ||
|
||
it "creates a new User with name set to FirstName + LastName" do | ||
expect(-> { authenticate }).to change { User.where(:name => 'Betty Boop').count }.from(0).to(1) | ||
end | ||
end | ||
|
||
context "when fullname, firstname and lastname are blank" do | ||
let(:username) { 'sam' } | ||
let(:headers) do | ||
super().merge('X-Remote-User-FullName' => '', | ||
'X-Remote-User-FirstName' => '', | ||
'X-Remote-User-LastName' => '', | ||
'X-Remote-User-Email' => '[email protected]') | ||
end | ||
|
||
it "creates a new User with name set to the userid" do | ||
expect(-> { authenticate }).to change { User.where(:name => 'sam').count }.from(0).to(1) | ||
end | ||
end | ||
end | ||
|
||
describe ".user_attrs_from_external_directory" do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,8 @@ def normalize(dn) | |
'rootdn' => {:password => 'verysecret'}, | ||
'alice' => alice_data, | ||
'bob' => bob_data, | ||
'betty' => betty_data, | ||
'sam' => sam_data, | ||
} | ||
end | ||
let(:alice_data) do | ||
|
@@ -86,6 +88,28 @@ def normalize(dn) | |
:groups => %w(wibble bubble), | ||
} | ||
end | ||
let(:betty_data) do | ||
{ | ||
:userprincipalname => 'betty', | ||
:password => 'secret', | ||
:displayname => nil, | ||
:givenname => 'Betty', | ||
:sn => 'Builderson', | ||
:mail => '[email protected]', | ||
:groups => %w(wibble bubble), | ||
} | ||
end | ||
let(:sam_data) do | ||
{ | ||
:userprincipalname => 'sam', | ||
:password => 'secret', | ||
:displayname => nil, | ||
:givenname => nil, | ||
:sn => nil, | ||
:mail => '[email protected]', | ||
:groups => %w(wibble bubble), | ||
} | ||
end | ||
|
||
before(:each) do | ||
allow(MiqLdap).to receive(:new) { FakeLdap.new(user_data) } | ||
|
@@ -462,6 +486,22 @@ def authenticate | |
expect(MiqTask.status_error?(task.status)).to be_truthy | ||
end | ||
end | ||
|
||
context "when display name is blank" do | ||
let(:username) { 'betty' } | ||
|
||
it "creates a new User with name set to givenname + sn" do | ||
expect(-> { authenticate }).to change { User.where(:name => 'Betty Builderson').count }.from(0).to(1) | ||
end | ||
end | ||
|
||
context "when display name, givenname and sn are blank" do | ||
let(:username) { 'sam' } | ||
|
||
it "creates a new User with name set to the userid" do | ||
expect(-> { authenticate }).to change { User.where(:name => 'sam').count }.from(0).to(1) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|