|
12 | 12 | let(:username) { request.headers["X-Remote-User"] } |
13 | 13 |
|
14 | 14 | before do |
15 | | - # If anything goes looking for the currently configured |
16 | | - # Authenticator during any of these tests, we'd really rather they |
17 | | - # found the one we're working on. |
18 | | - # |
19 | | - # This specifically comes up when we auto-create a new user from an |
20 | | - # external auth system: they get saved without a password, so User's |
21 | | - # dummy_password_for_external_auth hook runs, and it needs to ask |
22 | | - # Authenticator#uses_stored_password? whether it's allowed to do anything. |
23 | | - |
| 15 | + # Stub authenticator to prevent User.dummy_password_for_external_auth from calling wrong authenticator |
24 | 16 | stub_settings_merge(:authentication => config) |
25 | 17 | allow(User).to receive(:authenticator).and_return(subject) |
26 | | - |
27 | 18 | EvmSpecHelper.local_miq_server |
28 | | - end |
29 | 19 |
|
30 | | - before do |
31 | 20 | FactoryBot.create(:miq_group, :description => 'wibble') |
32 | 21 | FactoryBot.create(:miq_group, :description => 'wobble') |
33 | | - |
34 | 22 | allow(MiqLdap).to receive(:using_ldap?) { false } |
35 | 23 | end |
36 | 24 |
|
|
106 | 94 | expect(subject.lookup_by_identity('baduser', request)).to eq(cheshire) |
107 | 95 | end |
108 | 96 |
|
| 97 | + it "falls back to X-Remote-User when X-Remote-User-Principal is empty string" do |
| 98 | + headers['X-Remote-User-Principal'] = '' |
| 99 | + expect(subject.lookup_by_identity('cheshire', request)).to eq(cheshire) |
| 100 | + end |
| 101 | + |
| 102 | + it "falls back to X-Remote-User when X-Remote-User-Principal is whitespace" do |
| 103 | + headers['X-Remote-User-Principal'] = ' ' |
| 104 | + expect(subject.lookup_by_identity('cheshire', request)).to eq(cheshire) |
| 105 | + end |
| 106 | + |
109 | 107 | it "Handles missing request parameter" do |
110 | 108 | expect(subject.lookup_by_identity('alice')).to eq(alice) |
111 | 109 | end |
@@ -731,6 +729,53 @@ def authenticate |
731 | 729 | user_attrs, _groups = subject.send(:user_details_from_external_directory, 'jdoe') |
732 | 730 | expect(user_attrs[:username]).to eq("jdoe@ipa.test") |
733 | 731 | end |
| 732 | + |
| 733 | + it "should fall back to provided username when krbPrincipalName is empty string" do |
| 734 | + requested_attrs = %w[mail givenname sn displayname domainname krbPrincipalName] |
| 735 | + |
| 736 | + jdoe_attrs = [{"mail" => ["jdoe@example.com"], |
| 737 | + "givenname" => ["John"], |
| 738 | + "sn" => ["Doe"], |
| 739 | + "displayname" => ["John Doe"], |
| 740 | + "domainname" => ["ipa.test"], |
| 741 | + "krbPrincipalName" => [""]}] |
| 742 | + |
| 743 | + allow(ifp_interface).to receive(:GetUserAttr).with('jdoe', requested_attrs).and_return(jdoe_attrs) |
| 744 | + allow(MiqGroup).to receive(:get_httpd_groups_by_user).with('jdoe').and_return([]) |
| 745 | + |
| 746 | + user_attrs, _groups = subject.send(:user_details_from_external_directory, 'jdoe') |
| 747 | + expect(user_attrs[:username]).to eq("jdoe") |
| 748 | + end |
| 749 | + |
| 750 | + context "integration test: multiple login formats produce same normalized username" do |
| 751 | + let(:expected_normalized_username) { "flast@ipa.test" } |
| 752 | + let(:requested_attrs) { %w[mail givenname sn displayname domainname krbPrincipalName] } |
| 753 | + let(:user_attrs_response) do |
| 754 | + [{"mail" => ["first.last@example.com"], |
| 755 | + "givenname" => ["First"], |
| 756 | + "sn" => ["Last"], |
| 757 | + "displayname" => ["First Last"], |
| 758 | + "domainname" => ["ipa.test"], |
| 759 | + "krbPrincipalName" => ["flast@IPA.TEST"]}] |
| 760 | + end |
| 761 | + |
| 762 | + before do |
| 763 | + allow(MiqGroup).to receive(:get_httpd_groups_by_user).and_return([]) |
| 764 | + end |
| 765 | + |
| 766 | + shared_examples "normalizes to principal name" do |login_format| |
| 767 | + it "normalizes #{login_format}" do |
| 768 | + allow(ifp_interface).to receive(:GetUserAttr).with(login_format, requested_attrs).and_return(user_attrs_response) |
| 769 | + user_attrs, _groups = subject.send(:user_details_from_external_directory, login_format) |
| 770 | + expect(user_attrs[:username]).to eq(expected_normalized_username) |
| 771 | + end |
| 772 | + end |
| 773 | + |
| 774 | + include_examples "normalizes to principal name", "first.last@example.com" |
| 775 | + include_examples "normalizes to principal name", "flast@IPA.TEST" |
| 776 | + include_examples "normalizes to principal name", "flast@ipa.test" |
| 777 | + include_examples "normalizes to principal name", "flast" |
| 778 | + end |
734 | 779 | end |
735 | 780 | end |
736 | 781 | end |
|
0 commit comments