mirror of
https://github.com/philippdieter/puppet-ldapquery.git
synced 2026-05-05 15:32:47 +00:00
modulesync 2017-02-07
This commit is contained in:
4
spec/classes/coverage_spec.rb
Normal file
4
spec/classes/coverage_spec.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
require 'rspec-puppet'
|
||||
|
||||
at_exit { RSpec::Puppet::Coverage.report! }
|
||||
# vim: syntax=ruby
|
||||
14
spec/default_facts.yml
Normal file
14
spec/default_facts.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
# This file is managed via modulesync
|
||||
# https://github.com/voxpupuli/modulesync
|
||||
# https://github.com/voxpupuli/modulesync_config
|
||||
#
|
||||
# use default_module_facts.yaml for module specific
|
||||
# facts.
|
||||
#
|
||||
# Hint if using with rspec-puppet-facts ("on_supported_os.each"):
|
||||
# if a same named fact exists in facterdb it will be overridden.
|
||||
---
|
||||
concat_basedir: "/tmp"
|
||||
ipaddress: "172.16.254.254"
|
||||
is_pe: false
|
||||
macaddress: "AA:AA:AA:AA:AA:AA"
|
||||
@@ -1,10 +1,33 @@
|
||||
require 'puppetlabs_spec_helper/module_spec_helper'
|
||||
require 'rspec-puppet'
|
||||
require 'rspec-puppet-facts'
|
||||
include RspecPuppetFacts
|
||||
|
||||
fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
|
||||
if Dir.exist?(File.expand_path('../../lib', __FILE__))
|
||||
require 'coveralls'
|
||||
require 'simplecov'
|
||||
require 'simplecov-console'
|
||||
SimpleCov.formatters = [
|
||||
SimpleCov::Formatter::HTMLFormatter,
|
||||
SimpleCov::Formatter::Console,
|
||||
Coveralls::SimpleCov::Formatter
|
||||
]
|
||||
SimpleCov.start do
|
||||
track_files 'lib/**/*.rb'
|
||||
add_filter '/spec'
|
||||
add_filter '/vendor'
|
||||
add_filter '/.vendor'
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.configure do |c|
|
||||
c.module_path = File.join(fixture_path, 'modules')
|
||||
c.manifest_dir = File.join(fixture_path, 'manifests')
|
||||
c.mock_framework = :rspec
|
||||
default_facts = {
|
||||
puppetversion: Puppet.version,
|
||||
facterversion: Facter.version
|
||||
}
|
||||
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_facts.yml', __FILE__))
|
||||
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_module_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_module_facts.yml', __FILE__))
|
||||
c.default_facts = default_facts
|
||||
c.mock_with :rspec
|
||||
end
|
||||
|
||||
# vim: syntax=ruby
|
||||
|
||||
@@ -4,62 +4,64 @@ require 'net/ldap'
|
||||
|
||||
describe 'PuppetX::LDAPquery' do
|
||||
describe 'results' do
|
||||
let (:conf) { {
|
||||
:host => 'ldap.example.com',
|
||||
:port => 9009,
|
||||
} }
|
||||
let(:conf) do
|
||||
{
|
||||
host: 'ldap.example.com',
|
||||
port: 9009
|
||||
}
|
||||
end
|
||||
|
||||
let (:base) { 'dc=example,dc=com' }
|
||||
let(:base) { 'dc=example,dc=com' }
|
||||
|
||||
it "should fail with no filter" do
|
||||
it 'fails with no filter' do
|
||||
filter = ''
|
||||
attributes = ['uid']
|
||||
expect { PuppetX::LDAPquery.new(filter, attributes).results }.to raise_error
|
||||
end
|
||||
|
||||
it "should not fail when using defaults in puppet.conf" do
|
||||
it 'does not fail when using defaults in puppet.conf' do
|
||||
filter = '(uid=zach)'
|
||||
attributes = ['uid']
|
||||
l = PuppetX::LDAPquery.new(filter, attributes, base)
|
||||
expect { l.get_config }.to_not raise_error
|
||||
expect { l.ldap_config }.not_to raise_error
|
||||
end
|
||||
|
||||
it 'should return the desired results' do
|
||||
it 'returns the desired results' do
|
||||
filter = '(uid=zach)'
|
||||
attributes = ['uid']
|
||||
|
||||
wanted = [{"dn"=>["uid=zach,ou=users,dc=puppetlabs,dc=com"], "uid"=>["zach"]}]
|
||||
entries = Marshal.load(File.read("spec/fixtures/entries_single.obj"))
|
||||
wanted = [{ 'dn' => ['uid=zach,ou=users,dc=puppetlabs,dc=com'], 'uid' => ['zach'] }]
|
||||
entries = Marshal.load(File.read('spec/fixtures/entries_single.obj'))
|
||||
|
||||
l = PuppetX::LDAPquery.new(filter, attributes, base)
|
||||
|
||||
expect(l).to receive(:get_entries).and_return(entries)
|
||||
allow(l).to receive(:entries).and_return(entries)
|
||||
expect(l.results).to eq(wanted)
|
||||
end
|
||||
|
||||
context "a multivalued attribute is requested" do
|
||||
it 'should return the attribute values as an array to the attribute' do
|
||||
context 'a multivalued attribute is requested' do
|
||||
it 'returns the attribute values as an array to the attribute' do
|
||||
filter = '(uid=zach)'
|
||||
attributes = ['objectClass']
|
||||
|
||||
wanted =[{"dn"=>["uid=zach,ou=users,dc=puppetlabs,dc=com"], "objectclass"=>["posixAccount", "shadowAccount", "inetOrgPerson", "puppetPerson", "ldapPublicKey", "top"]}]
|
||||
wanted = [{ 'dn' => ['uid=zach,ou=users,dc=puppetlabs,dc=com'], 'objectclass' => %w(posixAccount shadowAccount inetOrgPerson puppetPerson ldapPublicKey top) }]
|
||||
|
||||
entries = Marshal.load(File.read("spec/fixtures/entries_objectClass.obj"))
|
||||
entries = Marshal.load(File.read('spec/fixtures/entries_objectClass.obj'))
|
||||
|
||||
l = PuppetX::LDAPquery.new(filter, attributes, base)
|
||||
expect(l).to receive(:get_entries).and_return(entries)
|
||||
allow(l).to receive(:entries).and_return(entries)
|
||||
expect(l.results).to eq(wanted)
|
||||
end
|
||||
it 'should return the attributes without new lines' do
|
||||
it 'returns the attributes without new lines' do
|
||||
filter = '(uid=zach)'
|
||||
attributes = ['sshPublicKey']
|
||||
|
||||
wanted = [{"dn"=>["uid=zach,ou=users,dc=puppetlabs,dc=com"], "sshpublickey"=>["ssh-rsa AAAAB...1== user@somewhere", "ssh-rsa AAAAB...2== user@somewhereelse"]}]
|
||||
wanted = [{ 'dn' => ['uid=zach,ou=users,dc=puppetlabs,dc=com'], 'sshpublickey' => ['ssh-rsa AAAAB...1== user@somewhere', 'ssh-rsa AAAAB...2== user@somewhereelse'] }]
|
||||
|
||||
entries = Marshal.load(File.read("spec/fixtures/entries_multivalue.obj"))
|
||||
entries = Marshal.load(File.read('spec/fixtures/entries_multivalue.obj'))
|
||||
|
||||
l = PuppetX::LDAPquery.new(filter, attributes, base)
|
||||
expect(l).to receive(:get_entries).and_return(entries)
|
||||
allow(l).to receive(:entries).and_return(entries)
|
||||
expect(l.results).to eq(wanted)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user