Add a helper method to load fixtures

This also disables the security rubocop since we can trust files on
disk enough.
This commit is contained in:
Ewoud Kohl van Wijngaarden 2020-04-30 23:54:44 +02:00
parent 07507bd9fb
commit 39610804e1
No known key found for this signature in database
GPG Key ID: C6EC8F04A934BAB1

View File

@ -2,6 +2,10 @@ require 'spec_helper'
require 'puppet_x/ldapquery' require 'puppet_x/ldapquery'
require 'net/ldap' require 'net/ldap'
def load_fixture(filename)
Marshal.load(File.read(File.join('spec', 'fixtures', filename))) # rubocop:disable Security/MarshalLoad
end
describe 'PuppetX::LDAPquery' do describe 'PuppetX::LDAPquery' do
describe 'results' do describe 'results' do
let(:conf) do let(:conf) do
@ -31,7 +35,7 @@ describe 'PuppetX::LDAPquery' do
attributes = ['uid'] attributes = ['uid']
wanted = [{ 'dn' => ['uid=zach,ou=users,dc=puppetlabs,dc=com'], 'uid' => ['zach'] }] wanted = [{ 'dn' => ['uid=zach,ou=users,dc=puppetlabs,dc=com'], 'uid' => ['zach'] }]
entries = Marshal.load(File.read('spec/fixtures/entries_single.obj')) entries = load_fixture('entries_single.obj')
l = PuppetX::LDAPquery.new(filter, attributes, base) l = PuppetX::LDAPquery.new(filter, attributes, base)
@ -46,7 +50,7 @@ describe 'PuppetX::LDAPquery' do
wanted = [{ 'dn' => ['uid=zach,ou=users,dc=puppetlabs,dc=com'], 'objectclass' => %w[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 = load_fixture('entries_objectClass.obj')
l = PuppetX::LDAPquery.new(filter, attributes, base) l = PuppetX::LDAPquery.new(filter, attributes, base)
allow(l).to receive(:entries).and_return(entries) allow(l).to receive(:entries).and_return(entries)
@ -58,7 +62,7 @@ describe 'PuppetX::LDAPquery' do
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 = load_fixture('entries_multivalue.obj')
l = PuppetX::LDAPquery.new(filter, attributes, base) l = PuppetX::LDAPquery.new(filter, attributes, base)
allow(l).to receive(:entries).and_return(entries) allow(l).to receive(:entries).and_return(entries)