forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
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 ManageIQ#15535 from jvlcek/bz1424618_dup_users
Converting userids to UPN format to avoid duplicate user records
- Loading branch information
Showing
4 changed files
with
130 additions
and
19 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 |
---|---|---|
|
@@ -65,6 +65,7 @@ def authenticate | |
'X-Remote-User-FirstName' => 'Alice', | ||
'X-Remote-User-LastName' => 'Aardvark', | ||
'X-Remote-User-Email' => '[email protected]', | ||
'X-Remote-User-Domain' => 'example.com', | ||
'X-Remote-User-Groups' => user_groups, | ||
} | ||
end | ||
|
@@ -190,6 +191,78 @@ def authenticate | |
end | ||
end | ||
|
||
context "with potential for multiple user records" do | ||
let(:dn) { 'cn=sally,ou=people,ou=prod,dc=example,dc=com' } | ||
let(:config) { {:httpd_role => true} } | ||
|
||
let(:username) { 'saLLy' } | ||
let(:user_groups) { 'wibble@fqdn:bubble@fqdn' } | ||
|
||
let(:headers) do | ||
super().merge('X-Remote-User-FullName' => 'Sally Porsche', | ||
'X-Remote-User-FirstName' => 'Sally', | ||
'X-Remote-User-LastName' => 'Porsche', | ||
'X-Remote-User-Email' => '[email protected]') | ||
end | ||
|
||
context "when user record with userid in upn format already exists" do | ||
let!(:sally_username) { FactoryGirl.create(:user, :userid => 'sAlly') } | ||
let!(:sally_dn) { FactoryGirl.create(:user, :userid => dn) } | ||
let!(:sally_upn) { FactoryGirl.create(:user, :userid => '[email protected]') } | ||
|
||
it "leaves user record with userid in username format unchanged" do | ||
expect(-> { authenticate }).to_not change { sally_username.reload.userid } | ||
end | ||
|
||
it "leaves user record with userid in distinguished name format unchanged" do | ||
expect(-> { authenticate }).to_not change { sally_dn.reload.userid } | ||
end | ||
|
||
it "downcases user record with userid in upn format" do | ||
expect(-> { authenticate }) | ||
.to change { sally_upn.reload.userid }.from("[email protected]").to("[email protected]") | ||
end | ||
end | ||
|
||
context "when user record with userid in upn format does not already exists" do | ||
it "updates userid from username format to upn format" do | ||
sally_username = FactoryGirl.create(:user, :userid => 'sally') | ||
expect(-> { authenticate }).to change { sally_username.reload.userid }.from("sally").to("[email protected]") | ||
end | ||
|
||
it "updates userid from distinguished name format to upn format" do | ||
sally_dn = FactoryGirl.create(:user, :userid => dn) | ||
expect(-> { authenticate }).to change { sally_dn.reload.userid }.from(dn).to("[email protected]") | ||
end | ||
|
||
it "does not modify userid if already in upn format" do | ||
sally_upn = FactoryGirl.create(:user, :userid => '[email protected]') | ||
expect(-> { authenticate }).to_not change { sally_upn.reload.userid } | ||
end | ||
end | ||
|
||
context "when user record is for a different region" do | ||
let(:my_region_number) { ApplicationRecord.my_region_number } | ||
let(:other_region) { ApplicationRecord.my_region_number + 1 } | ||
let(:other_region_id) { other_region * ApplicationRecord.rails_sequence_factor + 1 } | ||
|
||
it "does not modify the user record when userid is in username format" do | ||
sally_username = FactoryGirl.create(:user, :userid => 'sally', :id => other_region_id) | ||
expect(-> { authenticate }).to_not change { sally_username.reload.userid } | ||
end | ||
|
||
it "does not modify the user record when userid is in distinguished name format" do | ||
sally_dn = FactoryGirl.create(:user, :userid => dn, :id => other_region_id) | ||
expect(-> { authenticate }).to_not change { sally_dn.reload.userid } | ||
end | ||
|
||
it "does not modify the user record when userid is in already upn format" do | ||
sally_upn = FactoryGirl.create(:user, :userid => '[email protected]', :id => other_region_id) | ||
expect(-> { authenticate }).to_not change { sally_upn.reload.userid } | ||
end | ||
end | ||
end | ||
|
||
context "with unknown username in mixed case" do | ||
let(:username) { 'bOb' } | ||
let(:headers) do | ||
|
@@ -254,7 +327,7 @@ def authenticate | |
end | ||
|
||
it "creates a new User" do | ||
expect(-> { authenticate }).to change { User.where(:userid => 'bob').count }.from(0).to(1) | ||
expect(-> { authenticate }).to change { User.where(:userid => 'bob@example.com').count }.from(0).to(1) | ||
end | ||
|
||
context "with no matching groups" do | ||
|
@@ -279,7 +352,7 @@ def authenticate | |
expect(AuditEvent).to receive(:failure).with( | ||
:event => 'authorize', | ||
:userid => 'bob', | ||
:message => "Authentication failed for userid bob, unable to match user's group membership to an EVM role", | ||
:message => "Authentication failed for userid bob@example.com, unable to match user's group membership to an EVM role", | ||
) | ||
authenticate | ||
end | ||
|
@@ -319,8 +392,8 @@ def authenticate | |
'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) | ||
it "creates a new User with the userid set to the UPN" do | ||
expect(-> { authenticate }).to change { User.where(:name => 'sam@example.com').count }.from(0).to(1) | ||
end | ||
end | ||
end | ||
|
@@ -345,17 +418,19 @@ def authenticate | |
end | ||
|
||
it "should return user attributes hash for valid user" do | ||
requested_attrs = %w(mail givenname sn displayname) | ||
requested_attrs = %w(mail givenname sn displayname domainname) | ||
|
||
jdoe_attrs = [{"mail" => ["[email protected]"], | ||
"givenname" => ["John"], | ||
"sn" => ["Doe"], | ||
"displayname" => ["John Doe"]}] | ||
"displayname" => ["John Doe"], | ||
"domainname" => ["example.com"]}] | ||
|
||
expected_jdoe_attrs = {"mail" => "[email protected]", | ||
"givenname" => "John", | ||
"sn" => "Doe", | ||
"displayname" => "John Doe"} | ||
"displayname" => "John Doe", | ||
"domainname" => "example.com"} | ||
|
||
allow(@ifp_interface).to receive(:GetUserAttr).with('jdoe', requested_attrs).and_return(jdoe_attrs) | ||
|
||
|
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