Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppet/provider/openldap_access/olc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def self.instances
suffix = line.split[1]
when %r{^olcAccess: }
begin
position, what, bys = line.match(%r{^olcAccess:\s+\{(\d+)\}to\s+(\S+(?:\s+filter=\S+)?(?:\s+attrs=\S+)?(?:\s+val=\S+)?)(\s+by\s+.*)+$}).captures
position, what, bys = line.match(%r{^olcAccess:\s+\{(\d+)\}to\s+((?:\S*"[^"]+"|\S+)?(?:\s+filter=\S+)?(?:\s+attrs=\S+)?(?:\s+val=\S+)?)(\s+by\s+.*)+$}).captures
rescue StandardError
raise Puppet::Error, "Failed to parse olcAccess for suffix '#{suffix}': #{line}"
end
Expand Down
44 changes: 44 additions & 0 deletions spec/unit/puppet/provider/openldap_access/olc_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

require 'spec_helper'

describe Puppet::Type.type(:openldap_access).provider(:olc) do
describe '::instances' do
context 'with Debian defaults' do
it do
allow(described_class).to receive(:slapcat).with('(olcAccess=*)').and_return(<<~SLAPCAT)
# Debian defaults
dn: olcDatabase={-1}frontend,cn=config
olcAccess: {0}to * by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage by * break
olcAccess: {1}to dn.exact="" by * read
olcAccess: {2}to dn.base="cn=Subschema" by * read

dn: olcDatabase={0}config,cn=config
olcAccess: {0}to * by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage by * break

dn: olcDatabase={1}mdb,cn=config
olcAccess: {0}to attrs=userPassword by self write by anonymous auth by * none
olcAccess: {1}to attrs=shadowLastChange by self write by * read
olcAccess: {2}to * by * read
SLAPCAT
end

it 'parses olcAccess' do
allow(described_class.instances.size).to eq(7)
end
end

context 'with spaces' do
it do
allow(described_class).to receive(:slapcat).with('(olcAccess=*)').and_return(<<~SLAPCAT)
dn: olcDatabase={-1}frontend,cn=config
olcAccess: {0}to dn.base="cn=Sub Schema" by * read
SLAPCAT
end

it 'parses olcAccess' do
allow(described_class.instances.size).to eq(1)
end
end
end
end
10 changes: 10 additions & 0 deletions spec/unit/puppet/type/openldap_acess_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,15 @@
access = described_class.new(name: '0 on dc=example,dc=com', access: 'by dn="cn=admin,dc=example,dc=com" write by anonymous auth')
expect(access[:access]).to eq([['by dn="cn=admin,dc=example,dc=com" write', 'by anonymous auth']])
end

it 'handles target with spaces with prefix' do
access = described_class.new(name: '0 on dn.subtree="cn=Some String,dc=example,dc=com"', access: 'by dn="cn=admin,dc=example,dc=com" write by anonymous auth')
expect(access[:access]).to eq([['by dn="cn=admin,dc=example,dc=com" write', 'by anonymous auth']])
end

it 'handles target with spaces without prefix' do
access = described_class.new(name: '0 on "cn=Some String,dc=example,dc=com"', access: 'by dn="cn=admin,dc=example,dc=com" write by anonymous auth')
expect(access[:access]).to eq([['by dn="cn=admin,dc=example,dc=com" write', 'by anonymous auth']])
end
Comment on lines +16 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are not related to the above change 🤨

For some reason i can't push to your branch:

spec/unit/puppet/provider/openldap_acess/olc_spec.rb

# frozen_string_literal: true

require 'spec_helper'

describe Puppet::Type.type(:openldap_access).provider(:olc) do
  describe '::instances' do
    context 'with Debian defaults' do
      before do
        expect(described_class).to receive(:slapcat).with('(olcAccess=*)').and_return(<<~SLAPCAT)
          # Debian defaults
          dn: olcDatabase={-1}frontend,cn=config
          olcAccess: {0}to * by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage by * break
          olcAccess: {1}to dn.exact="" by * read
          olcAccess: {2}to dn.base="cn=Subschema" by * read

          dn: olcDatabase={0}config,cn=config
          olcAccess: {0}to * by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage by * break

          dn: olcDatabase={1}mdb,cn=config
          olcAccess: {0}to attrs=userPassword by self write by anonymous auth by * none
          olcAccess: {1}to attrs=shadowLastChange by self write by * read
          olcAccess: {2}to * by * read
        SLAPCAT
      end

      it 'parses olcAccess' do
        expect(described_class.instances.size).to eq(7)
      end
    end

    context 'with spaces' do
      before do
        expect(described_class).to receive(:slapcat).with('(olcAccess=*)').and_return(<<~SLAPCAT)
          dn: olcDatabase={-1}frontend,cn=config
          olcAccess: {0}to dn.base="cn=Sub Schema" by * read
        SLAPCAT
      end

      it 'parses olcAccess' do
        expect(described_class.instances.size).to eq(1)
      end
    end
  end
end

Can you check and add this?

end
end