-
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 #19228 from jvlcek/miq_config_sssd_bz1745775
Add support to automate external auth config for ldap
- Loading branch information
Showing
30 changed files
with
536 additions
and
188 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
$LOAD_PATH << Rails.root.join("tools").to_s | ||
|
||
require "miq_config_sssd_ldap/cli_config" | ||
|
||
describe MiqConfigSssdLdap::CliConfig do | ||
before do | ||
@all_opts = :tls_cacert, :tls_cacertdir, :domain, :ldaphost, :ldapport, :user_type, :user_suffix, :mode, | ||
:bind_dn, :bind_pwd, :only_change_userids, :skip_post_conversion_userid_change | ||
@all_required_opts = %w[-H ldaphost -T dn-cn -S user_suffix -M ldap -d example.com -b cn=Manager,dc=example,dc=com -p password] | ||
allow(TCPSocket).to receive(:new).and_return(double(:close => nil)) | ||
|
||
stub_const("LOGGER", double) | ||
allow(LOGGER).to receive(:debug) | ||
end | ||
|
||
describe "#parse" do | ||
it "should assign defaults" do | ||
opts = described_class.new.parse(@all_required_opts).opts.slice(*@all_opts) | ||
expect(opts).to include(:ldapport => 389, :skip_post_conversion_userid_change => false) | ||
end | ||
|
||
it "should assign all required options when mode is ldap" do | ||
opts = described_class.new.parse(@all_required_opts).opts.slice(*@all_opts) | ||
expect(opts).to eq(:bind_dn => "cn=Manager,dc=example,dc=com", | ||
:bind_pwd => "password", | ||
:domain => "example.com", | ||
:ldaphost => ["ldaphost"], | ||
:ldapport => 389, | ||
:mode => "ldap", | ||
:only_change_userids => false, | ||
:skip_post_conversion_userid_change => false, | ||
:user_suffix => "user_suffix", | ||
:user_type => "dn-cn") | ||
end | ||
|
||
it "should assign default non-secure ldapport" do | ||
opts = described_class.new.parse(@all_required_opts).opts.slice(:ldapport) | ||
expect(opts).to eq(:ldapport => 389) | ||
end | ||
|
||
it "should assign default secure ldapport" do | ||
opts = described_class.new.parse(@all_required_opts - %w[-M ldap] + %w[-M ldaps]).opts.slice(:ldapport) | ||
expect(opts).to eq(:ldapport => 636) | ||
end | ||
|
||
it "should parse ldaphost" do | ||
opts = described_class.new.parse(@all_required_opts).opts.slice(:ldaphost) | ||
expect(opts).to eq(:ldaphost => ["ldaphost"]) | ||
end | ||
|
||
it "should parse ldapport" do | ||
opts = described_class.new.parse(@all_required_opts + %w[-P 8675309]).opts.slice(:ldapport) | ||
expect(opts).to eq(:ldapport => "8675309") | ||
end | ||
|
||
it "should parse user_type" do | ||
opts = described_class.new.parse(@all_required_opts).opts.slice(:user_type) | ||
expect(opts).to eq(:user_type => "dn-cn") | ||
end | ||
|
||
it "should parse user_suffix" do | ||
opts = described_class.new.parse(@all_required_opts).opts.slice(:user_suffix) | ||
expect(opts).to eq(:user_suffix => "user_suffix") | ||
end | ||
|
||
it "should parse mode" do | ||
opts = described_class.new.parse(@all_required_opts).opts.slice(:mode) | ||
expect(opts).to eq(:mode => "ldap") | ||
end | ||
|
||
it "should parse base DN domain names" do | ||
opts = described_class.new.parse(@all_required_opts).opts.slice(:domain) | ||
expect(opts).to eq(:domain => "example.com") | ||
end | ||
|
||
it "should parse bind DN" do | ||
opts = described_class.new.parse(@all_required_opts).opts.slice(:bind_dn) | ||
expect(opts).to eq(:bind_dn => "cn=Manager,dc=example,dc=com") | ||
end | ||
|
||
it "should parse bind pwd" do | ||
opts = described_class.new.parse(@all_required_opts).opts.slice(:bind_pwd) | ||
expect(opts).to eq(:bind_pwd => "password") | ||
end | ||
|
||
it "should parse TLS cacert path and directory" do | ||
opts = described_class.new.parse(@all_required_opts + %w[-c /a/path/to/a/cacert]).opts.slice(:tls_cacert, :tls_cacertdir) | ||
expect(opts).to eq(:tls_cacert => "/a/path/to/a/cacert", :tls_cacertdir => "/a/path/to/a") | ||
end | ||
|
||
it "can skip updating the userids after the conversion" do | ||
opts = described_class.new.parse(@all_required_opts + %w[-s]).opts.slice(*@all_opts) | ||
expect(opts).to include(:skip_post_conversion_userid_change => true) | ||
end | ||
|
||
context "When mode is ldap" do | ||
it "requires bind_dn" do | ||
expect(Optimist).to receive(:die) | ||
described_class.new.parse(@all_required_opts - %w[-b cn=Manager,dc=example,dc=com]) | ||
end | ||
|
||
it "requires bind_pwd" do | ||
expect(Optimist).to receive(:die) | ||
described_class.new.parse(@all_required_opts - %w[-p password]) | ||
end | ||
end | ||
|
||
context "When ldap_role is true" do | ||
before do | ||
@ldap_role_ldaps_opts = @all_required_opts - %w[-M ldap] + %w[-M ldaps -g] | ||
end | ||
|
||
it "requires bind_dn" do | ||
expect(Optimist).to receive(:die) | ||
described_class.new.parse(@ldap_role_ldaps_opts - %w[-b cn=Manager,dc=example,dc=com]) | ||
end | ||
|
||
it "requires bind_pwd" do | ||
expect(Optimist).to receive(:die) | ||
described_class.new.parse(@ldap_role_ldaps_opts - %w[-p password]) | ||
end | ||
end | ||
end | ||
end |
20 changes: 10 additions & 10 deletions
20
spec/tools/miqldap_to_sssd/cli_spec.rb → .../miq_config_sssd_ldap/cli_convert_spec.rb
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
$LOAD_PATH << Rails.root.join("tools").to_s | ||
|
||
require "miq_config_sssd_ldap" | ||
|
||
describe MiqConfigSssdLdap::ConfigureSELinux do | ||
describe '#configure' do | ||
before do | ||
@initial_settings = {:ldapport => '22'} | ||
@success = double(:command_line => "semanage", :failure? => false) | ||
@semanage_params = {nil => "port", :a => nil, :t => "ldap_port_t", :p => %w[tcp 22]} | ||
@failure1 = double(:command_line => "semanage", :failure? => true, :error => "malfunction already defined") | ||
@failure2 = double(:command_line => "semanage", :failure? => true, :error => "malfunction") | ||
end | ||
|
||
it 'invokes semanage and setsebool with valid parameters' do | ||
expect(AwesomeSpawn).to receive(:run).once.with("semanage", :params => @semanage_params).and_return(@success) | ||
expect(AwesomeSpawn).to receive(:run).once.with("setsebool", :params => {:P=>%w[allow_httpd_mod_auth_pam on]}).and_return(@success) | ||
expect(AwesomeSpawn).to receive(:run).once.with("setsebool", :params => {:P=>%w[httpd_dbus_sssd on]}).and_return(@success) | ||
expect { described_class.new(@initial_settings).configure }.to_not raise_error | ||
end | ||
|
||
it 'handles semanage already defined result' do | ||
expect(MiqConfigSssdLdap::LOGGER).to_not receive(:fatal) | ||
expect(AwesomeSpawn).to receive(:run).once.and_return(@failure1) | ||
expect(AwesomeSpawn).to receive(:run).once.with("setsebool", :params => {:P=>%w[allow_httpd_mod_auth_pam on]}).and_return(@success) | ||
expect(AwesomeSpawn).to receive(:run).once.with("setsebool", :params => {:P=>%w[httpd_dbus_sssd on]}).and_return(@success) | ||
expect { described_class.new(@initial_settings).configure }.to_not raise_error | ||
end | ||
|
||
it 'handles semanage failures' do | ||
expect(MiqConfigSssdLdap::LOGGER).to receive(:fatal).with("semanage failed with: malfunction") | ||
expect(AwesomeSpawn).to receive(:run).and_return(@failure2) | ||
expect { described_class.new(@initial_settings).configure }.to raise_error(MiqConfigSssdLdap::ConfigureSELinuxError) | ||
end | ||
|
||
it 'handles setsebool failures' do | ||
expect(MiqConfigSssdLdap::LOGGER).to receive(:fatal).with("setsebool failed with: malfunction") | ||
expect(AwesomeSpawn).to receive(:run).once.with("semanage", :params => @semanage_params).and_return(@success) | ||
|
||
expect(AwesomeSpawn).to receive(:run) | ||
.and_return(double(:command_line => "setsebool", :failure? => true, :error => "malfunction")) | ||
expect { described_class.new(@initial_settings).configure }.to raise_error(MiqConfigSssdLdap::ConfigureSELinuxError) | ||
end | ||
end | ||
end |
34 changes: 34 additions & 0 deletions
34
spec/tools/miq_config_sssd_ldap/configure_sssd_rules_spec.rb
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
$LOAD_PATH << Rails.root.join("tools").to_s | ||
|
||
require "miq_config_sssd_ldap" | ||
require "tempfile" | ||
require "fileutils" | ||
require 'auth_template_files' | ||
|
||
describe MiqConfigSssdLdap::ConfigureSssdRules do | ||
before do | ||
@spec_name = File.basename(__FILE__).split(".rb").first.freeze | ||
end | ||
|
||
describe '#disable_tls' do | ||
let(:disable_tls_conf) do | ||
<<-CFG_RULES_CONF.strip_heredoc | ||
option = ldap_auth_disable_tls_never_use_in_production | ||
CFG_RULES_CONF | ||
end | ||
|
||
before do | ||
@test_dir = "#{Dir.tmpdir}/#{@spec_name}" | ||
stub_const("MiqConfigSssdLdap::ConfigureSssdRules::CFG_RULES_FILE", @test_dir) | ||
end | ||
|
||
after do | ||
FileUtils.rm_rf(@test_dir) | ||
end | ||
|
||
it 'appends the disable tls option to the sssd config file' do | ||
described_class.disable_tls | ||
expect(File.read(@test_dir)).to eq(disable_tls_conf) | ||
end | ||
end | ||
end |
Oops, something went wrong.