-
Notifications
You must be signed in to change notification settings - Fork 898
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 #23139 from kbrock/CP4AIOPS-3113
CP4AIOPS-3113 Introduce configurable delimiter for LDAP group names
- Loading branch information
Showing
4 changed files
with
92 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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
RSpec.describe Authenticator::Httpd do | ||
subject { Authenticator::Httpd.new(config) } | ||
subject { Authenticator::Httpd.new(Settings.authentication.to_hash) } | ||
|
||
let(:config) { {:httpd_role => false} } | ||
let(:request) do | ||
|
@@ -21,6 +21,7 @@ | |
# dummy_password_for_external_auth hook runs, and it needs to ask | ||
# Authenticator#uses_stored_password? whether it's allowed to do anything. | ||
|
||
stub_settings_merge(:authentication => config) | ||
allow(User).to receive(:authenticator).and_return(subject) | ||
|
||
EvmSpecHelper.local_miq_server | ||
|
@@ -172,6 +173,17 @@ def authenticate | |
} | ||
end | ||
|
||
let(:user_attrs) do | ||
{ | ||
:username => "testuser", | ||
:fullname => "Test User", | ||
:firstname => "Alice", | ||
:lastname => "Aardvark", | ||
:email => "[email protected]", | ||
:domain => "example.com" | ||
} | ||
end | ||
|
||
context "with user details" do | ||
let!(:alice) { FactoryBot.create(:user, :userid => 'alice') } | ||
|
||
|
@@ -702,38 +714,78 @@ def authenticate | |
end | ||
end | ||
|
||
context "using a comma separated group list" do | ||
context "using default delimiters" do | ||
let(:config) { {:httpd_role => true} } | ||
let(:headers) do | ||
super().merge('X-Remote-User-Groups' => 'wibble@fqdn,bubble@fqdn') | ||
end | ||
|
||
it "parses group names" do | ||
expect(subject).to receive(:find_external_identity).with(username, user_attrs, ["wibble@fqdn", "bubble@fqdn"]) | ||
authenticate | ||
end | ||
end | ||
|
||
context "using custom delimiter in settings" do | ||
let(:config) { {:httpd_role => true, :group_delimiter => ","} } | ||
let(:headers) do | ||
super().merge('X-Remote-User-Groups' => 'wibble:wobble@fqdn,hobble;bubble@fqdn') | ||
end | ||
|
||
it "parses group names that contain characters from the default delimiters (:)" do | ||
expect(subject).to receive(:find_external_identity).with(username, user_attrs, ["wibble:wobble@fqdn", "hobble;bubble@fqdn"]) | ||
authenticate | ||
end | ||
end | ||
|
||
context "using custom delimiter in settings (despite a header)" do | ||
let(:config) { {:httpd_role => true, :group_delimiter => "|"} } | ||
let(:headers) do | ||
super().merge('X-Remote-User-Groups' => 'wibble,wobble@fqdn|bubble@fqdn', 'X-Remote-User-Group-Delimiter' => ",") | ||
end | ||
let(:user_attrs) do | ||
{:username => "testuser", | ||
{ | ||
:username => "testuser", | ||
:fullname => "Test User", | ||
:firstname => "Alice", | ||
:lastname => "Aardvark", | ||
:email => "[email protected]", | ||
:domain => "example.com"} | ||
:domain => "example.com" | ||
} | ||
end | ||
|
||
it "handles a comma separated grouplist" do | ||
expect(subject).to receive(:find_external_identity).with(username, user_attrs, ["wibble@fqdn", "bubble@fqdn"]) | ||
it "parses group names that contain characters from header" do | ||
expect(subject).to receive(:find_external_identity).with(username, user_attrs, ["wibble,wobble@fqdn", "bubble@fqdn"]) | ||
authenticate | ||
end | ||
end | ||
|
||
context "when group names have escaped special characters" do | ||
context "using header delimiter" do | ||
let(:config) { {:httpd_role => true} } | ||
let(:headers) do | ||
super().merge('X-Remote-User-Groups' => CGI.escape('spécial_char@fqdn:moré@fqdn')) | ||
super().merge('X-Remote-User-Groups' => 'wibble:wobble@fqdn,bubble@fqdn', 'X-Remote-User-Group-Delimiter' => ",") | ||
end | ||
let(:user_attrs) do | ||
{:username => "testuser", | ||
{ | ||
:username => "testuser", | ||
:fullname => "Test User", | ||
:firstname => "Alice", | ||
:lastname => "Aardvark", | ||
:email => "[email protected]", | ||
:domain => "example.com"} | ||
:domain => "example.com" | ||
} | ||
end | ||
|
||
it "parses group names that contain characters from default delimiter" do | ||
expect(subject).to receive(:find_external_identity).with(username, user_attrs, ["wibble:wobble@fqdn", "bubble@fqdn"]) | ||
authenticate | ||
end | ||
end | ||
|
||
context "when group names have escaped special characters" do | ||
let(:config) { {:httpd_role => true} } | ||
let(:headers) do | ||
super().merge('X-Remote-User-Groups' => CGI.escape('spécial_char@fqdn:moré@fqdn')) | ||
end | ||
|
||
it "handles group names with escaped special characters" do | ||
|
@@ -755,13 +807,26 @@ def authenticate | |
'X-Remote-User-Groups' => nil, | ||
} | ||
end | ||
let(:user_attrs) do | ||
{:username => "testuser", | ||
:fullname => "Test User", | ||
:firstname => "Alice", | ||
:lastname => "Aardvark", | ||
:email => "[email protected]", | ||
:domain => "example.com"} | ||
|
||
it "handles nil group names" do | ||
expect(subject).to receive(:find_external_identity).with(username, user_attrs, []) | ||
authenticate | ||
end | ||
end | ||
|
||
context "when there are no group names (but a group header)" do | ||
let(:config) { {:httpd_role => true} } | ||
let(:headers) do | ||
{ | ||
'X-Remote-User' => 'testuser', | ||
'X-Remote-User-FullName' => 'Test User', | ||
'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' => nil, | ||
'X-Remote-User-Group-Delimiter' => nil | ||
} | ||
end | ||
|
||
it "handles nil group names" do | ||
|