Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax validation of openldap_database's suffix parameter #402

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 1 addition & 7 deletions lib/puppet/type/openldap_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@
newparam(:suffix, namevar: true) do
desc 'The default namevar.'
validate do |value|
raise ArgumentError, 'Invalid value' unless [
/\Acn=config\z/,
/\Acn=monitor\z/,
%r{\A(dc|o)=[[:alnum:].-]+(,(dc|o)=[[:alnum:].-]+)*\z},
].any? do |pattern|
pattern.match?(value)
end
raise ArgumentError, 'Invalid value' unless value.match?(%r{\A[[:alnum:]]+=[^,;]+([,;][[:alnum:]]+=[^,;]+)*\z})
end
end

Expand Down
11 changes: 9 additions & 2 deletions spec/unit/puppet/type/openldap_database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@

it 'does not invalid suffixes' do
expect { described_class.new(name: 'foo bar') }.to raise_error(Puppet::Error, %r{Invalid value})
expect { described_class.new(name: 'cn=admin,dc=example,dc=com') }.to raise_error(Puppet::Error, %r{Invalid value})
expect { described_class.new(name: 'dc=example, dc=com') }.to raise_error(Puppet::Error, %r{Invalid value})
expect { described_class.new(name: 'cn=foo,bar') }.to raise_error(Puppet::Error, %r{Invalid value})
expect { described_class.new(name: 'foo,cn=bar') }.to raise_error(Puppet::Error, %r{Invalid value})
expect { described_class.new(name: 'cn=foo,,cn=bar') }.to raise_error(Puppet::Error, %r{Invalid value})
end

it 'allows valid suffix' do
expect { described_class.new(name: 'dc=example,dc=com') }.not_to raise_error
expect { described_class.new(name: 'dc=foo;dc=bar') }.not_to raise_error
expect { described_class.new(name: 'cn=config') }.not_to raise_error
end

it 'allows more valid suffix', skip: 'These are valid DNs, but we need a proper parser to match them, not a regexp' do

Check warning on line 31 in spec/unit/puppet/type/openldap_database_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

Puppet::Type::Openldap_database namevar validation allows more valid suffix Skipped: These are valid DNs, but we need a proper parser to match them, not a regexp

Check warning on line 31 in spec/unit/puppet/type/openldap_database_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

Puppet::Type::Openldap_database namevar validation allows more valid suffix Skipped: These are valid DNs, but we need a proper parser to match them, not a regexp
expect { described_class.new(name: 'OU=Sales+CN=J. Smith,O=Widget Inc.,C=US') }.not_to raise_error
expect { described_class.new(name: 'CN=R. Smith,O=Big Company\\, Inc.,C=US') }.not_to raise_error
end
end

describe 'when validating attributes' do
Expand Down