-
Notifications
You must be signed in to change notification settings - Fork 4
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 #5 from EncoreTechnologies/feature/unit-testing
Added lots of unit testing for ipa_kinit
- Loading branch information
Showing
9 changed files
with
339 additions
and
14 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
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,55 @@ | ||
require 'spec_helper' | ||
require 'facter' | ||
require 'facter/ipa_login_defs' | ||
|
||
describe 'ipa_login_defs', type: :fact do | ||
subject(:fact) { Facter.fact(subject) } | ||
|
||
let(:mock_etc_login_defs) do | ||
str = <<-EOS | ||
# | ||
# Please note that the parameters in this configuration file control the | ||
# behavior of the tools from the shadow-utils component. None of these | ||
# tools uses the PAM mechanism, and the utilities that use PAM (such as the | ||
# passwd command) should therefore be configured elsewhere. Refer to | ||
# /etc/pam.d/system-auth for more information. | ||
# | ||
MAIL_DIR /var/spool/mail | ||
# | ||
# Min/max values for automatic uid selection in useradd | ||
# | ||
UID_MIN 1000 | ||
UID_MAX 60000 | ||
# | ||
# Min/max values for automatic gid selection in groupadd | ||
# | ||
GID_MIN 1000 | ||
GID_MAX 60000 | ||
# Use SHA512 to encrypt password. | ||
ENCRYPT_METHOD SHA512 | ||
EOS | ||
str.lines | ||
end | ||
|
||
before :each do | ||
Facter.clear | ||
end | ||
|
||
it 'returns a value' do | ||
# mock the File.readlines and give it some fake output of our file | ||
expect(File).to receive(:readlines).with('/etc/login.defs').and_return(mock_etc_login_defs) | ||
expected_fact = { | ||
'MAIL_DIR' => '/var/spool/mail', | ||
'UID_MIN' => 1_000, | ||
'UID_MAX' => 60_000, | ||
'GID_MIN' => 1_000, | ||
'GID_MAX' => 60_000, | ||
'ENCRYPT_METHOD' => 'SHA512', | ||
} | ||
expect(Facter.fact(:ipa_login_defs).value).to eq(expected_fact) | ||
end | ||
end |
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,162 @@ | ||
require 'spec_helper' | ||
|
||
describe Puppet::Type.type(:ipa_kinit).provider(:default) do | ||
let(:name) { 'admin' } | ||
let(:properties) do | ||
{ | ||
# this provider: is necessary, otherwise this provider isn't chosen | ||
provider: described_class.name, | ||
name: name, | ||
ensure: :present, | ||
password: 'AdminPassword123', | ||
} | ||
end | ||
let(:resource) { Puppet::Type.type(:ipa_kinit).new(properties) } | ||
let(:provider) { resource.provider } | ||
|
||
describe '#read_instance' do | ||
it 'return a resource when name matches' do | ||
klist_return = <<-EOS | ||
Principal name Cache name | ||
-------------- ---------- | ||
[email protected] KCM:0 | ||
EOS | ||
prov = resource.provider | ||
expect(prov).to receive(:klist).with('-l').and_return(klist_return) | ||
expect(prov.read_instance).to eq(ensure: :present, | ||
name: name, | ||
principal_name: '[email protected]') | ||
end | ||
|
||
it 'return {ensure: absent} instance when no names match' do | ||
klist_return = <<-EOS | ||
Principal name Cache name | ||
-------------- ---------- | ||
[email protected] KCM:0 | ||
EOS | ||
expect(provider).to receive(:klist).with('-l').and_return(klist_return) | ||
expect(provider.read_instance).to eq(ensure: :absent, name: name) | ||
end | ||
|
||
it 'return good instance when realm isnt passed in, as long as user matches' do | ||
klist_return = <<-EOS | ||
Principal name Cache name | ||
-------------- ---------- | ||
[email protected] KCM:0 | ||
EOS | ||
expect(provider).to receive(:klist).with('-l').and_return(klist_return) | ||
expect(provider.read_instance).to eq(ensure: :present, | ||
name: name, | ||
principal_name: '[email protected]') | ||
end | ||
|
||
it 'return {ensure: absent} instance when klist fails' do | ||
expect(provider).to receive(:klist).with('-l').and_raise(Puppet::ExecutionFailure.new('x')) | ||
expect(provider.read_instance).to eq(ensure: :absent, name: name) | ||
end | ||
|
||
context 'with realm set' do | ||
let(:properties) do | ||
{ | ||
# this provider: is necessary, otherwise this provider isn't chosen | ||
provider: described_class.name, | ||
name: name, | ||
realm: 'EXPECTED.DOMAIN.TLD', | ||
} | ||
end | ||
|
||
it 'return a resource when name and realm matches' do | ||
klist_return = <<-EOS | ||
Principal name Cache name | ||
-------------- ---------- | ||
[email protected] KCM:0 | ||
EOS | ||
expect(provider).to receive(:klist).with('-l').and_return(klist_return) | ||
expect(provider.read_instance).to eq(ensure: :present, | ||
name: name, | ||
principal_name: '[email protected]', | ||
realm: 'EXPECTED.DOMAIN.TLD') | ||
end | ||
|
||
it 'return a {ensure: absent} instance when name matches but realm doesnt match' do | ||
klist_return = <<-EOS | ||
Principal name Cache name | ||
-------------- ---------- | ||
[email protected] KCM:0 | ||
EOS | ||
expect(provider).to receive(:klist).with('-l').and_return(klist_return) | ||
expect(provider.read_instance).to eq(ensure: :absent, name: name) | ||
end | ||
end | ||
end | ||
|
||
describe '#flush_instance' do | ||
context 'when destroying' do | ||
let(:properties) do | ||
{ | ||
# this provider: is necessary, otherwise this provider isn't chosen | ||
provider: described_class.name, | ||
name: name, | ||
ensure: :absent, | ||
} | ||
end | ||
|
||
let(:provider) do | ||
prov = resource.provider | ||
props = { principal_name: '[email protected]' } | ||
prov.instance_variable_set(:@cached_instance, properties.merge(props)) | ||
prov | ||
end | ||
|
||
it 'run kdestroy with the principal name' do | ||
expect(provider).to receive(:kdestroy).with(['-p', '[email protected]']) | ||
provider.flush_instance | ||
end | ||
end | ||
|
||
context 'when creating' do | ||
it 'run kinit with username and password' do | ||
command_str = 'echo $KINIT_PASSWORD | /bin/kinit admin' | ||
expect(provider).to receive(:command).with(:kinit).and_return('/bin/kinit') | ||
expect(Puppet::Util::Execution).to receive(:execute).with( | ||
command_str, | ||
override_locale: false, | ||
failonfail: true, | ||
combine: true, | ||
custom_environment: { | ||
'KINIT_PASSWORD' => 'AdminPassword123', | ||
}, | ||
) | ||
provider.flush_instance | ||
end | ||
|
||
context 'with realm' do | ||
let(:properties) do | ||
{ | ||
# this provider: is necessary, otherwise this provider isn't chosen | ||
provider: described_class.name, | ||
name: name, | ||
ensure: :present, | ||
password: 'AdminPassword123', | ||
realm: 'EXPECTED.DOMAIN.TLD', | ||
} | ||
end | ||
|
||
it 'run kinit with username@realm specified' do | ||
command_str = 'echo $KINIT_PASSWORD | /bin/kinit [email protected]' | ||
expect(provider).to receive(:command).with(:kinit).and_return('/bin/kinit') | ||
expect(Puppet::Util::Execution).to receive(:execute).with( | ||
command_str, | ||
override_locale: false, | ||
failonfail: true, | ||
combine: true, | ||
custom_environment: { | ||
'KINIT_PASSWORD' => 'AdminPassword123', | ||
}, | ||
) | ||
provider.flush_instance | ||
end | ||
end | ||
end | ||
end | ||
end |
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,19 @@ | ||
# require 'spec_helper' | ||
|
||
# describe Puppet::Type.type("provider").provider("ipa") do | ||
# let (:provider) { subject } | ||
# let(:properties) do | ||
# {} | ||
# end | ||
# let(:resource) { subject.new(properties) } | ||
|
||
# it 'should return an array of instances' do | ||
# expect(subject.instances).to be_instance_of(Array) | ||
# end | ||
|
||
# describe 'getter property methods' do | ||
# end | ||
|
||
# describe 'setter property methods' do | ||
# end | ||
# end |
Oops, something went wrong.